markdown-text-editor 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +277 -277
- package/dist/index.css +35 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown-text-editor.css +35 -0
- package/dist/markdown-text-editor.css.map +1 -1
- package/dist/markdown-text-editor.js +1 -1
- package/dist/markdown-text-editor.js.map +1 -1
- package/package.json +72 -67
- package/src/plugins/index.js +2 -2
- package/src/plugins/markdown/Toolbar/MakeTool.js +66 -63
- package/src/plugins/markdown/Toolbar/index.js +50 -42
- package/src/plugins/markdown/Toolbar/tools/BoldTool.js +14 -14
- package/src/plugins/markdown/Toolbar/tools/CheckListTool.js +17 -17
- package/src/plugins/markdown/Toolbar/tools/ItalicTool.js +16 -16
- package/src/plugins/markdown/Toolbar/tools/OLTool.js +19 -19
- package/src/plugins/markdown/Toolbar/tools/PreviewTool.js +110 -98
- package/src/plugins/markdown/Toolbar/tools/StrikethroughTool.js +15 -15
- package/src/plugins/markdown/Toolbar/tools/ULTool.js +17 -17
- package/src/plugins/markdown/editor.js +168 -141
- package/src/plugins/markdown/preview.js +16 -16
- package/src/plugins/markdown/styles/main.css +2 -2
- package/src/plugins/markdown/utils/markdownUtils.js +7 -7
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 nezanuha
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 nezanuha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,278 +1,278 @@
|
|
|
1
|
-
## MarkdownEditor Plugin Documentation
|
|
2
|
-
|
|
3
|
-
Welcome to the documentation for the **MarkdownEditor Plugin** – an **open source project** offering the **best, simple, embeddable JavaScript Markdown editor plugin or library**. This powerful tool provides **real-time preview**, **syntax highlighting**, and **easy integration** into your projects. Whether you’re building a blog, note-taking app, or any content-rich website, this plugin delivers a robust and customizable markdown editing experience.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Table of Contents
|
|
8
|
-
|
|
9
|
-
- [Overview](#overview)
|
|
10
|
-
- [Installation](#installation)
|
|
11
|
-
- [Usage](#usage)
|
|
12
|
-
- [Markdown Content Retrieval](#markdown-content-retrieval)
|
|
13
|
-
- [JavaScript Value Retrieval](#javascript-value-retrieval)
|
|
14
|
-
- [HTML Template Form Submission](#html-template-form-submission)
|
|
15
|
-
- [Set Markdown Content to Editor](#set-markdown-content-to-editor)
|
|
16
|
-
- [Configuration Options](#configuration-options)
|
|
17
|
-
- [Toolbar Customization](#toolbar-customization)
|
|
18
|
-
- [Example Implementations](#example-implementations)
|
|
19
|
-
- [Contribution Guidelines](#contribute)
|
|
20
|
-
- [License](#license)
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Overview
|
|
25
|
-
|
|
26
|
-
The MarkdownEditor Plugin is designed to be the **best, simple, and embeddable JavaScript markdown editor plugin** available. It is an open source project that boasts:
|
|
27
|
-
|
|
28
|
-
- **Real-time Preview:** See your markdown rendered instantly as you type.
|
|
29
|
-
- **Syntax Highlighting:** Enhanced readability with clear code and markdown formatting.
|
|
30
|
-
- **Easy Integration:** Seamlessly integrate into any web project with minimal setup.
|
|
31
|
-
- **Customizable Toolbar:** Dynamically configure and reorder toolbar options like **bold**, **italic**, and more.
|
|
32
|
-
|
|
33
|
-
Built with **Tailwind CSS** for modern styling, this plugin is perfect for developers seeking a lightweight yet feature-rich markdown editor.
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## Installation
|
|
38
|
-
|
|
39
|
-
Integrating the MarkdownEditor Plugin into your project is straightforward. You can install it using NPM, import the JavaScript file directly, or use a CDN for rapid deployment.
|
|
40
|
-
|
|
41
|
-
### Install via NPM
|
|
42
|
-
|
|
43
|
-
For projects utilizing bundling tools like Webpack, run:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
npm install markdown-text-editor
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## Usage
|
|
52
|
-
|
|
53
|
-
After installation, import the `MarkdownEditor` class from the package:
|
|
54
|
-
|
|
55
|
-
```javascript
|
|
56
|
-
import MarkdownEditor from "markdown-text-editor";
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Basic Initialization
|
|
60
|
-
|
|
61
|
-
To get started, include a `<textarea>` element in your HTML and initialize the editor by targeting its container:
|
|
62
|
-
|
|
63
|
-
#### HTML
|
|
64
|
-
|
|
65
|
-
```html
|
|
66
|
-
<textarea class="editor-container"></textarea>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
#### JavaScript
|
|
70
|
-
|
|
71
|
-
```javascript
|
|
72
|
-
const editor = new MarkdownEditor('.editor-container', {
|
|
73
|
-
placeholder: 'Write your markdown...',
|
|
74
|
-
toolbar: ['preview', 'bold', 'italic'], // Customize toolbar options as needed
|
|
75
|
-
});
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## CSS Setup
|
|
81
|
-
|
|
82
|
-
### Using TailwindCSS
|
|
83
|
-
|
|
84
|
-
If you’re leveraging **TailwindCSS**, add the following configuration to your `tailwind.config.js`:
|
|
85
|
-
|
|
86
|
-
```javascript
|
|
87
|
-
// tailwind.config.js
|
|
88
|
-
module.exports = {
|
|
89
|
-
content: [
|
|
90
|
-
'node_modules/markdown-text-editor/**/*.js',
|
|
91
|
-
// Add your project paths here
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Without TailwindCSS
|
|
97
|
-
|
|
98
|
-
For projects not using TailwindCSS, simply import the CSS file directly:
|
|
99
|
-
|
|
100
|
-
```javascript
|
|
101
|
-
import 'markdown-text-editor/dist/markdown-text-editor.css';
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Using a CDN
|
|
105
|
-
|
|
106
|
-
Alternatively, include the following CDN links in your HTML:
|
|
107
|
-
|
|
108
|
-
#### JavaScript:
|
|
109
|
-
|
|
110
|
-
```html
|
|
111
|
-
<script src="https://cdn.jsdelivr.net/npm/markdown-text-editor/dist/markdown-text-editor.js"></script>
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### CSS:
|
|
115
|
-
|
|
116
|
-
```html
|
|
117
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markdown-text-editor/dist/markdown-text-editor.min.css">
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## Markdown Content Retrieval
|
|
123
|
-
|
|
124
|
-
### JavaScript Value Retrieval
|
|
125
|
-
|
|
126
|
-
In this method, you can access the markdown content entered into the editor directly using JavaScript. This is helpful when you want to dynamically retrieve the value and process it in your application (e.g., displaying it elsewhere or sending it via AJAX).
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
#### HTML
|
|
130
|
-
|
|
131
|
-
```html
|
|
132
|
-
<form>
|
|
133
|
-
<textarea class="editor-container h-48" rows="5"></textarea>
|
|
134
|
-
<button type="button" id="submit-btn">Submit</button>
|
|
135
|
-
<div class="output"></div>
|
|
136
|
-
</form>
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### JavaScript
|
|
140
|
-
|
|
141
|
-
```javascript
|
|
142
|
-
const editor = new MarkdownEditor('.editor-container', {
|
|
143
|
-
placeholder: 'Start writing...',
|
|
144
|
-
toolbar: ['bold', 'italic', 'preview'],
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
document.getElementById('submit-btn').addEventListener('click', function() {
|
|
148
|
-
const markdownValue = document.querySelector('.editor-container').value;
|
|
149
|
-
console.log(markdownValue);
|
|
150
|
-
document.querySelector('.output').innerHTML = `<pre>${markdownValue}</pre>`;
|
|
151
|
-
});
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### HTML Template Form Submission
|
|
155
|
-
|
|
156
|
-
If you prefer a traditional form submission approach (for example, in server-side applications like Django), you can integrate the markdown editor into a form that submits the value to the server for processing.
|
|
157
|
-
|
|
158
|
-
#### HTML (Form Submission)
|
|
159
|
-
|
|
160
|
-
```html
|
|
161
|
-
<form method="POST" action="/your-server-endpoint">
|
|
162
|
-
<textarea class="editor-container h-48" rows="5" name="markdown"></textarea>
|
|
163
|
-
<button type="submit">Submit</button>
|
|
164
|
-
</form>
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
you can retrieve the value from a traditional `<textarea>` in a form submission without any custom element. When the form is submitted, the content inside the `<textarea>` is automatically included as part of the form data, using the name attribute of the `<textarea>`.
|
|
168
|
-
|
|
169
|
-
#### JavaScript (MarkdownEditor Initialization)
|
|
170
|
-
|
|
171
|
-
```javascript
|
|
172
|
-
const editor = new MarkdownEditor('.editor-container', {
|
|
173
|
-
placeholder: 'Write your markdown...',
|
|
174
|
-
toolbar: ['preview', 'bold', 'italic'],
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## Set Markdown Content to Editor
|
|
179
|
-
|
|
180
|
-
```HTML
|
|
181
|
-
<form method="POST" action="/your-server-endpoint">
|
|
182
|
-
<textarea class="editor-container h-48" rows="5" name="markdown">Add your markdown content here</textarea>
|
|
183
|
-
<button type="submit">Submit</button>
|
|
184
|
-
</form>
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## Configuration Options
|
|
188
|
-
|
|
189
|
-
Customize your Markdown editor by passing an `options` object during initialization. Below are some key configuration options:
|
|
190
|
-
|
|
191
|
-
| Option | Type | Default | Description |
|
|
192
|
-
|---------------|----------|------------------------------|-----------------------------------------------------------|
|
|
193
|
-
| `placeholder` | `string` | `'Write your markdown...'` | Sets the placeholder text for the textarea (optional, as you can also use the standard HTML textarea attribute) |
|
|
194
|
-
| `toolbar` | `array` | `['bold', 'italic', 'strikethrough', 'ol', 'ul', 'checklist', 'preview']` | Determines which tools appear in the toolbar and their order. |
|
|
195
|
-
|
|
196
|
-
---
|
|
197
|
-
|
|
198
|
-
## Toolbar Customization
|
|
199
|
-
|
|
200
|
-
Tailor the toolbar to suit your needs by choosing which formatting options to include. The MarkdownEditor Plugin supports several tools, including:
|
|
201
|
-
|
|
202
|
-
- **`bold`**: Enables bold text formatting.
|
|
203
|
-
- **`italic`**: Enables italic text formatting.
|
|
204
|
-
- **`strikethrough`**: Allows text to be struck through.
|
|
205
|
-
- **`preview`**: Toggles the real-time markdown preview.
|
|
206
|
-
|
|
207
|
-
**Example:**
|
|
208
|
-
|
|
209
|
-
```javascript
|
|
210
|
-
const editor = new MarkdownEditor('.editor-container', {
|
|
211
|
-
placeholder: 'Start writing...',
|
|
212
|
-
toolbar: ['bold', 'italic', 'strikethrough', 'preview'],
|
|
213
|
-
});
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
## Example Implementations
|
|
219
|
-
|
|
220
|
-
### Full HTML Example
|
|
221
|
-
|
|
222
|
-
Below is a complete HTML example demonstrating how to integrate the MarkdownEditor Plugin into your project:
|
|
223
|
-
|
|
224
|
-
```html
|
|
225
|
-
<!DOCTYPE html>
|
|
226
|
-
<html lang="en">
|
|
227
|
-
<head>
|
|
228
|
-
<meta charset="UTF-8">
|
|
229
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
230
|
-
<title>Markdown Editor Example</title>
|
|
231
|
-
<link rel="stylesheet" href="dist/markdown-editor-plugin.css">
|
|
232
|
-
</head>
|
|
233
|
-
<body>
|
|
234
|
-
<textarea class="editor-container h-56" rows="6"></textarea>
|
|
235
|
-
|
|
236
|
-
<script src="dist/markdown-editor-plugin.js"></script>
|
|
237
|
-
<script>
|
|
238
|
-
const editor = new MarkdownEditor('.editor-container', {
|
|
239
|
-
placeholder: 'Type your markdown...',
|
|
240
|
-
toolbar: ['preview', 'bold', 'italic']
|
|
241
|
-
});
|
|
242
|
-
</script>
|
|
243
|
-
</body>
|
|
244
|
-
</html>
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
### Webpack Integration Example
|
|
248
|
-
|
|
249
|
-
For projects using Webpack, import and initialize the editor as follows:
|
|
250
|
-
|
|
251
|
-
```javascript
|
|
252
|
-
import MarkdownEditor from 'markdown-text-editor';
|
|
253
|
-
|
|
254
|
-
const editor = new MarkdownEditor('.editor-container', {
|
|
255
|
-
placeholder: 'Write markdown...',
|
|
256
|
-
toolbar: ['preview', 'bold', 'italic'],
|
|
257
|
-
});
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Customizing Styles with TailwindCSS
|
|
261
|
-
|
|
262
|
-
Customize the appearance of the editor using Tailwind utility classes. The plugin’s default styling can be easily overridden in your custom Tailwind configuration.
|
|
263
|
-
|
|
264
|
-
---
|
|
265
|
-
|
|
266
|
-
## Contribute
|
|
267
|
-
|
|
268
|
-
Contributions to this **open source project** are highly encouraged! If you have bug fixes, feature enhancements, or new ideas, please consider opening an issue or submitting a pull request. Your help will ensure that this **best, simple, embeddable JavaScript markdown editor plugin** continues to evolve and serve the community with **real-time preview** and **syntax highlighting** capabilities.
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## License
|
|
273
|
-
|
|
274
|
-
This project is released under the [MIT License](LICENSE).
|
|
275
|
-
|
|
276
|
-
---
|
|
277
|
-
|
|
1
|
+
## MarkdownEditor Plugin Documentation
|
|
2
|
+
|
|
3
|
+
Welcome to the documentation for the **MarkdownEditor Plugin** – an **open source project** offering the **best, simple, embeddable JavaScript Markdown editor plugin or library**. This powerful tool provides **real-time preview**, **syntax highlighting**, and **easy integration** into your projects. Whether you’re building a blog, note-taking app, or any content-rich website, this plugin delivers a robust and customizable markdown editing experience.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Overview](#overview)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Markdown Content Retrieval](#markdown-content-retrieval)
|
|
13
|
+
- [JavaScript Value Retrieval](#javascript-value-retrieval)
|
|
14
|
+
- [HTML Template Form Submission](#html-template-form-submission)
|
|
15
|
+
- [Set Markdown Content to Editor](#set-markdown-content-to-editor)
|
|
16
|
+
- [Configuration Options](#configuration-options)
|
|
17
|
+
- [Toolbar Customization](#toolbar-customization)
|
|
18
|
+
- [Example Implementations](#example-implementations)
|
|
19
|
+
- [Contribution Guidelines](#contribute)
|
|
20
|
+
- [License](#license)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
The MarkdownEditor Plugin is designed to be the **best, simple, and embeddable JavaScript markdown editor plugin** available. It is an open source project that boasts:
|
|
27
|
+
|
|
28
|
+
- **Real-time Preview:** See your markdown rendered instantly as you type.
|
|
29
|
+
- **Syntax Highlighting:** Enhanced readability with clear code and markdown formatting.
|
|
30
|
+
- **Easy Integration:** Seamlessly integrate into any web project with minimal setup.
|
|
31
|
+
- **Customizable Toolbar:** Dynamically configure and reorder toolbar options like **bold**, **italic**, and more.
|
|
32
|
+
|
|
33
|
+
Built with **Tailwind CSS** for modern styling, this plugin is perfect for developers seeking a lightweight yet feature-rich markdown editor.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
Integrating the MarkdownEditor Plugin into your project is straightforward. You can install it using NPM, import the JavaScript file directly, or use a CDN for rapid deployment.
|
|
40
|
+
|
|
41
|
+
### Install via NPM
|
|
42
|
+
|
|
43
|
+
For projects utilizing bundling tools like Webpack, run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install markdown-text-editor
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
After installation, import the `MarkdownEditor` class from the package:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import MarkdownEditor from "markdown-text-editor";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Basic Initialization
|
|
60
|
+
|
|
61
|
+
To get started, include a `<textarea>` element in your HTML and initialize the editor by targeting its container:
|
|
62
|
+
|
|
63
|
+
#### HTML
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<textarea class="editor-container"></textarea>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### JavaScript
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const editor = new MarkdownEditor('.editor-container', {
|
|
73
|
+
placeholder: 'Write your markdown...',
|
|
74
|
+
toolbar: ['preview', 'bold', 'italic'], // Customize toolbar options as needed
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## CSS Setup
|
|
81
|
+
|
|
82
|
+
### Using TailwindCSS
|
|
83
|
+
|
|
84
|
+
If you’re leveraging **TailwindCSS**, add the following configuration to your `tailwind.config.js`:
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// tailwind.config.js
|
|
88
|
+
module.exports = {
|
|
89
|
+
content: [
|
|
90
|
+
'node_modules/markdown-text-editor/**/*.js',
|
|
91
|
+
// Add your project paths here
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Without TailwindCSS
|
|
97
|
+
|
|
98
|
+
For projects not using TailwindCSS, simply import the CSS file directly:
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
import 'markdown-text-editor/dist/markdown-text-editor.css';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Using a CDN
|
|
105
|
+
|
|
106
|
+
Alternatively, include the following CDN links in your HTML:
|
|
107
|
+
|
|
108
|
+
#### JavaScript:
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<script src="https://cdn.jsdelivr.net/npm/markdown-text-editor/dist/markdown-text-editor.js"></script>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### CSS:
|
|
115
|
+
|
|
116
|
+
```html
|
|
117
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markdown-text-editor/dist/markdown-text-editor.min.css">
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Markdown Content Retrieval
|
|
123
|
+
|
|
124
|
+
### JavaScript Value Retrieval
|
|
125
|
+
|
|
126
|
+
In this method, you can access the markdown content entered into the editor directly using JavaScript. This is helpful when you want to dynamically retrieve the value and process it in your application (e.g., displaying it elsewhere or sending it via AJAX).
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
#### HTML
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<form>
|
|
133
|
+
<textarea class="editor-container h-48" rows="5"></textarea>
|
|
134
|
+
<button type="button" id="submit-btn">Submit</button>
|
|
135
|
+
<div class="output"></div>
|
|
136
|
+
</form>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### JavaScript
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
const editor = new MarkdownEditor('.editor-container', {
|
|
143
|
+
placeholder: 'Start writing...',
|
|
144
|
+
toolbar: ['bold', 'italic', 'preview'],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
document.getElementById('submit-btn').addEventListener('click', function() {
|
|
148
|
+
const markdownValue = document.querySelector('.editor-container').value;
|
|
149
|
+
console.log(markdownValue);
|
|
150
|
+
document.querySelector('.output').innerHTML = `<pre>${markdownValue}</pre>`;
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### HTML Template Form Submission
|
|
155
|
+
|
|
156
|
+
If you prefer a traditional form submission approach (for example, in server-side applications like Django), you can integrate the markdown editor into a form that submits the value to the server for processing.
|
|
157
|
+
|
|
158
|
+
#### HTML (Form Submission)
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<form method="POST" action="/your-server-endpoint">
|
|
162
|
+
<textarea class="editor-container h-48" rows="5" name="markdown"></textarea>
|
|
163
|
+
<button type="submit">Submit</button>
|
|
164
|
+
</form>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
you can retrieve the value from a traditional `<textarea>` in a form submission without any custom element. When the form is submitted, the content inside the `<textarea>` is automatically included as part of the form data, using the name attribute of the `<textarea>`.
|
|
168
|
+
|
|
169
|
+
#### JavaScript (MarkdownEditor Initialization)
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
const editor = new MarkdownEditor('.editor-container', {
|
|
173
|
+
placeholder: 'Write your markdown...',
|
|
174
|
+
toolbar: ['preview', 'bold', 'italic'],
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Set Markdown Content to Editor
|
|
179
|
+
|
|
180
|
+
```HTML
|
|
181
|
+
<form method="POST" action="/your-server-endpoint">
|
|
182
|
+
<textarea class="editor-container h-48" rows="5" name="markdown">Add your markdown content here</textarea>
|
|
183
|
+
<button type="submit">Submit</button>
|
|
184
|
+
</form>
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Configuration Options
|
|
188
|
+
|
|
189
|
+
Customize your Markdown editor by passing an `options` object during initialization. Below are some key configuration options:
|
|
190
|
+
|
|
191
|
+
| Option | Type | Default | Description |
|
|
192
|
+
|---------------|----------|------------------------------|-----------------------------------------------------------|
|
|
193
|
+
| `placeholder` | `string` | `'Write your markdown...'` | Sets the placeholder text for the textarea (optional, as you can also use the standard HTML textarea attribute) |
|
|
194
|
+
| `toolbar` | `array` | `['bold', 'italic', 'strikethrough', 'ol', 'ul', 'checklist', 'preview']` | Determines which tools appear in the toolbar and their order. |
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Toolbar Customization
|
|
199
|
+
|
|
200
|
+
Tailor the toolbar to suit your needs by choosing which formatting options to include. The MarkdownEditor Plugin supports several tools, including:
|
|
201
|
+
|
|
202
|
+
- **`bold`**: Enables bold text formatting.
|
|
203
|
+
- **`italic`**: Enables italic text formatting.
|
|
204
|
+
- **`strikethrough`**: Allows text to be struck through.
|
|
205
|
+
- **`preview`**: Toggles the real-time markdown preview.
|
|
206
|
+
|
|
207
|
+
**Example:**
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
const editor = new MarkdownEditor('.editor-container', {
|
|
211
|
+
placeholder: 'Start writing...',
|
|
212
|
+
toolbar: ['bold', 'italic', 'strikethrough', 'preview'],
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Example Implementations
|
|
219
|
+
|
|
220
|
+
### Full HTML Example
|
|
221
|
+
|
|
222
|
+
Below is a complete HTML example demonstrating how to integrate the MarkdownEditor Plugin into your project:
|
|
223
|
+
|
|
224
|
+
```html
|
|
225
|
+
<!DOCTYPE html>
|
|
226
|
+
<html lang="en">
|
|
227
|
+
<head>
|
|
228
|
+
<meta charset="UTF-8">
|
|
229
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
230
|
+
<title>Markdown Editor Example</title>
|
|
231
|
+
<link rel="stylesheet" href="dist/markdown-editor-plugin.css">
|
|
232
|
+
</head>
|
|
233
|
+
<body>
|
|
234
|
+
<textarea class="editor-container h-56" rows="6"></textarea>
|
|
235
|
+
|
|
236
|
+
<script src="dist/markdown-editor-plugin.js"></script>
|
|
237
|
+
<script>
|
|
238
|
+
const editor = new MarkdownEditor('.editor-container', {
|
|
239
|
+
placeholder: 'Type your markdown...',
|
|
240
|
+
toolbar: ['preview', 'bold', 'italic']
|
|
241
|
+
});
|
|
242
|
+
</script>
|
|
243
|
+
</body>
|
|
244
|
+
</html>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Webpack Integration Example
|
|
248
|
+
|
|
249
|
+
For projects using Webpack, import and initialize the editor as follows:
|
|
250
|
+
|
|
251
|
+
```javascript
|
|
252
|
+
import MarkdownEditor from 'markdown-text-editor';
|
|
253
|
+
|
|
254
|
+
const editor = new MarkdownEditor('.editor-container', {
|
|
255
|
+
placeholder: 'Write markdown...',
|
|
256
|
+
toolbar: ['preview', 'bold', 'italic'],
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Customizing Styles with TailwindCSS
|
|
261
|
+
|
|
262
|
+
Customize the appearance of the editor using Tailwind utility classes. The plugin’s default styling can be easily overridden in your custom Tailwind configuration.
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Contribute
|
|
267
|
+
|
|
268
|
+
Contributions to this **open source project** are highly encouraged! If you have bug fixes, feature enhancements, or new ideas, please consider opening an issue or submitting a pull request. Your help will ensure that this **best, simple, embeddable JavaScript markdown editor plugin** continues to evolve and serve the community with **real-time preview** and **syntax highlighting** capabilities.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
This project is released under the [MIT License](LICENSE).
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
278
|
Thank you for choosing the MarkdownEditor Plugin – your reliable, feature-rich solution for seamless markdown editing and content creation with **easy integration**. Happy coding!
|