markdown-text-editor 0.0.24-beta.3 → 0.1.0
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 -268
- package/dist/index.css.map +1 -1
- package/dist/index.js.map +1 -1
- 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 +67 -65
- package/src/plugins/index.js +2 -2
- package/src/plugins/markdown/Toolbar/MakeTool.js +63 -0
- package/src/plugins/markdown/Toolbar/index.js +42 -36
- package/src/plugins/markdown/Toolbar/tools/BoldTool.js +14 -14
- package/src/plugins/markdown/Toolbar/tools/CheckListTool.js +18 -0
- package/src/plugins/markdown/Toolbar/tools/ItalicTool.js +16 -16
- package/src/plugins/markdown/Toolbar/tools/OLTool.js +20 -0
- package/src/plugins/markdown/Toolbar/tools/PreviewTool.js +98 -98
- package/src/plugins/markdown/Toolbar/tools/StrikethroughTool.js +15 -15
- package/src/plugins/markdown/Toolbar/tools/ULTool.js +18 -0
- package/src/plugins/markdown/editor.js +141 -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/src/plugins/markdown/Toolbar/tools/MarkdownTool.js +0 -40
package/package.json
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "markdown-text-editor",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "A powerful, easy-to-use Markdown editor with a real-time preview, syntax highlighting. Ideal for developers, writers, and content creators who need a seamless, interactive writing experience with full Markdown support.",
|
|
5
|
-
"main": "./dist/markdown-text-editor.js",
|
|
6
|
-
"browser": "dist/markdown-text-editor.js",
|
|
7
|
-
"style": "./dist/markdown-text-editor.css",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist/**/*",
|
|
10
|
-
"src/**/*"
|
|
11
|
-
],
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/nezanuha/markdown-text-editor"
|
|
15
|
-
},
|
|
16
|
-
"scripts": {
|
|
17
|
-
"clean": "rimraf dist",
|
|
18
|
-
"build": "npm run clean && webpack --mode=production",
|
|
19
|
-
"prepublishOnly": "npm run build",
|
|
20
|
-
"dev": "webpack serve --mode=development"
|
|
21
|
-
},
|
|
22
|
-
"publishConfig": {
|
|
23
|
-
"registry": "https://registry.npmjs.org/"
|
|
24
|
-
},
|
|
25
|
-
"keywords": [
|
|
26
|
-
"markdown-text-editor",
|
|
27
|
-
"markdown",
|
|
28
|
-
"
|
|
29
|
-
"editor",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"webpack-
|
|
63
|
-
"webpack
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-text-editor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A powerful, easy-to-use Markdown editor with a real-time preview, syntax highlighting. Ideal for developers, writers, and content creators who need a seamless, interactive writing experience with full Markdown support.",
|
|
5
|
+
"main": "./dist/markdown-text-editor.js",
|
|
6
|
+
"browser": "dist/markdown-text-editor.js",
|
|
7
|
+
"style": "./dist/markdown-text-editor.css",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/**/*",
|
|
10
|
+
"src/**/*"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/nezanuha/markdown-text-editor"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rimraf dist",
|
|
18
|
+
"build": "npm run clean && webpack --mode=production",
|
|
19
|
+
"prepublishOnly": "npm run build",
|
|
20
|
+
"dev": "webpack serve --mode=development"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"markdown-text-editor",
|
|
27
|
+
"markdown",
|
|
28
|
+
"mde",
|
|
29
|
+
"markdown editor",
|
|
30
|
+
"text-editor",
|
|
31
|
+
"editor",
|
|
32
|
+
"live preview",
|
|
33
|
+
"syntax highlighting",
|
|
34
|
+
"library",
|
|
35
|
+
"content creation",
|
|
36
|
+
"plugin",
|
|
37
|
+
"open source"
|
|
38
|
+
],
|
|
39
|
+
"author": "Nezanuha",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"homepage": "https://github.com/nezanuha/markdown-text-editor",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/nezanuha/markdown-text-editor/issues"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"marked": "^15.0.4",
|
|
47
|
+
"tailwindcss": "^3.4.13"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@babel/core": "^7.25.2",
|
|
51
|
+
"@babel/preset-env": "^7.25.4",
|
|
52
|
+
"@tailwindcss/typography": "^0.5.15",
|
|
53
|
+
"autoprefixer": "^10.4.20",
|
|
54
|
+
"babel-loader": "^9.2.1",
|
|
55
|
+
"css-loader": "^7.1.2",
|
|
56
|
+
"html-webpack-plugin": "^5.6.3",
|
|
57
|
+
"mini-css-extract-plugin": "^2.9.1",
|
|
58
|
+
"postcss": "^8.4.47",
|
|
59
|
+
"postcss-loader": "^8.1.1",
|
|
60
|
+
"rimraf": "^6.0.1",
|
|
61
|
+
"style-loader": "^4.0.0",
|
|
62
|
+
"terser-webpack-plugin": "^5.3.11",
|
|
63
|
+
"webpack": "^5.95.0",
|
|
64
|
+
"webpack-cli": "^6.0.1",
|
|
65
|
+
"webpack-dev-server": "^5.2.0"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/plugins/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// main.js
|
|
2
|
-
export { default as MarkdownEditor } from './markdown/editor';
|
|
1
|
+
// main.js
|
|
2
|
+
export { default as MarkdownEditor } from './markdown/editor';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class MakeTool {
|
|
2
|
+
constructor(editor, syntax, defaultText) {
|
|
3
|
+
this.editor = editor;
|
|
4
|
+
this.syntax = syntax; // Markdown syntax (e.g., ** for bold, * for italic)
|
|
5
|
+
this.defaultText = defaultText; // Default text if nothing is selected
|
|
6
|
+
this.button = this.createButton();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Create a button element (can be overridden in child classes)
|
|
10
|
+
createButton(iconHtml) {
|
|
11
|
+
const button = document.createElement('button');
|
|
12
|
+
button.innerHTML = iconHtml; // Pass icon HTML from child classes
|
|
13
|
+
button.type = 'button';
|
|
14
|
+
button.className = 'markdown-btn p-2 hover:bg-stone-200 dark:hover:bg-stone-600 rounded duration-300';
|
|
15
|
+
button.addEventListener('click', () => this.applySyntax('both')); // Default to 'both', can change in child
|
|
16
|
+
return button;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Toggle markdown syntax at the current cursor position
|
|
20
|
+
applySyntax(position = 'both') {
|
|
21
|
+
const textarea = this.editor.usertextarea;
|
|
22
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
23
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
24
|
+
|
|
25
|
+
const syntaxLength = this.syntax.length;
|
|
26
|
+
|
|
27
|
+
// Check which type of syntax to apply based on the position
|
|
28
|
+
let newText = '';
|
|
29
|
+
if(position === 'start'){
|
|
30
|
+
if (selectedText.startsWith(this.syntax)) {
|
|
31
|
+
// If text is already wrapped with the markdown syntax, remove it
|
|
32
|
+
const unformattedText = selectedText.slice(syntaxLength);
|
|
33
|
+
this.editor.insertText(unformattedText);
|
|
34
|
+
}else{
|
|
35
|
+
newText = `${this.syntax} ${selectedText || this.defaultText}`;
|
|
36
|
+
// Insert the new formatted text
|
|
37
|
+
this.editor.insertText(newText);
|
|
38
|
+
}
|
|
39
|
+
} else if (position === 'end') {
|
|
40
|
+
if (selectedText.startsWith(this.syntax)) {
|
|
41
|
+
// If text is already wrapped with the markdown syntax, remove it
|
|
42
|
+
const unformattedText = selectedText.slice(syntaxLength);
|
|
43
|
+
this.editor.insertText(unformattedText);
|
|
44
|
+
}else{
|
|
45
|
+
newText = `${selectedText || this.defaultText}${this.syntax}`;
|
|
46
|
+
// Insert the new formatted text
|
|
47
|
+
this.editor.insertText(newText);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (selectedText.startsWith(this.syntax) && selectedText.endsWith(this.syntax)) {
|
|
51
|
+
// If text is already wrapped with the markdown syntax, remove it
|
|
52
|
+
const unformattedText = selectedText.slice(syntaxLength, -syntaxLength);
|
|
53
|
+
this.editor.insertText(unformattedText);
|
|
54
|
+
}else{
|
|
55
|
+
newText = `${this.syntax}${selectedText || this.defaultText}${this.syntax}`;
|
|
56
|
+
// Insert the new formatted text
|
|
57
|
+
this.editor.insertText(newText);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default MakeTool;
|
|
@@ -1,36 +1,42 @@
|
|
|
1
|
-
// #markdown\Toolbar\index.js
|
|
2
|
-
import BoldTool from './tools/BoldTool.js';
|
|
3
|
-
import ItalicTool from './tools/ItalicTool.js';
|
|
4
|
-
import StrikethroughTool from './tools/StrikethroughTool.js';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
// #markdown\Toolbar\index.js
|
|
2
|
+
import BoldTool from './tools/BoldTool.js';
|
|
3
|
+
import ItalicTool from './tools/ItalicTool.js';
|
|
4
|
+
import StrikethroughTool from './tools/StrikethroughTool.js';
|
|
5
|
+
import ULTool from './tools/ULTool.js';
|
|
6
|
+
import OLTool from './tools/OLTool.js';
|
|
7
|
+
import PreviewTool from './tools/PreviewTool.js'
|
|
8
|
+
import CheckListTool from './tools/CheckListTool.js';
|
|
9
|
+
|
|
10
|
+
class Toolbar {
|
|
11
|
+
constructor(editor, options) {
|
|
12
|
+
this.editor = editor;
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.toolbar = document.createElement('div');
|
|
15
|
+
this.toolbar.className = 'toolbar flex space-x-1.5 p-1.5 bg-stone-100 dark:bg-stone-900 dark:text-stone-200 border-b border-stone-200 dark:border-stone-700';
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
init() {
|
|
20
|
+
const toolMapping = {
|
|
21
|
+
ul: ULTool,
|
|
22
|
+
ol: OLTool,
|
|
23
|
+
checklist: CheckListTool,
|
|
24
|
+
bold: BoldTool,
|
|
25
|
+
italic: ItalicTool,
|
|
26
|
+
strikethrough: StrikethroughTool,
|
|
27
|
+
preview: PreviewTool
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.options.forEach(tool => {
|
|
31
|
+
const ToolClass = toolMapping[tool];
|
|
32
|
+
if (ToolClass) {
|
|
33
|
+
const toolInstance = new ToolClass(this.editor);
|
|
34
|
+
this.toolbar.appendChild(toolInstance.button);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.editor.editorContainer.insertBefore(this.toolbar, this.editor.markdownEditorDiv);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default Toolbar;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
class BoldTool extends
|
|
4
|
-
constructor(editor) {
|
|
5
|
-
// Call the parent constructor with the markdown syntax for bold (**)
|
|
6
|
-
super(editor, '**', 'bold text');
|
|
7
|
-
this.button = this.createButton(`
|
|
8
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
-
<path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/>
|
|
10
|
-
</svg>
|
|
11
|
-
`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class BoldTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
// Call the parent constructor with the markdown syntax for bold (**)
|
|
6
|
+
super(editor, '**', 'bold text');
|
|
7
|
+
this.button = this.createButton(`
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
+
<path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/>
|
|
10
|
+
</svg>
|
|
11
|
+
`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
15
|
export default BoldTool;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class CheckListTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, '- [x]', 'Check list');
|
|
6
|
+
this.button = this.createButton(`
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m3 17 2 2 4-4"/><path d="m3 7 2 2 4-4"/><path d="M13 6h8"/><path d="M13 12h8"/><path d="M13 18h8"/></svg>
|
|
8
|
+
`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// You can change how the syntax is applied for this specific tool:
|
|
12
|
+
applySyntax() {
|
|
13
|
+
super.applySyntax('start'); // Only apply strikethrough at the start
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export default CheckListTool;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
class ItalicTool extends
|
|
4
|
-
constructor(editor) {
|
|
5
|
-
// Call the parent constructor with the markdown syntax for italic (*)
|
|
6
|
-
super(editor, '*', 'italic text');
|
|
7
|
-
this.button = this.createButton(`
|
|
8
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
-
<line x1="19" y1="4" x2="10" y2="4"/>
|
|
10
|
-
<line x1="14" y1="20" x2="5" y2="20"/>
|
|
11
|
-
<line x1="15" y1="4" x2="9" y2="20"/>
|
|
12
|
-
</svg>
|
|
13
|
-
`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class ItalicTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
// Call the parent constructor with the markdown syntax for italic (*)
|
|
6
|
+
super(editor, '*', 'italic text');
|
|
7
|
+
this.button = this.createButton(`
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
+
<line x1="19" y1="4" x2="10" y2="4"/>
|
|
10
|
+
<line x1="14" y1="20" x2="5" y2="20"/>
|
|
11
|
+
<line x1="15" y1="4" x2="9" y2="20"/>
|
|
12
|
+
</svg>
|
|
13
|
+
`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
17
|
export default ItalicTool;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class OLTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, '1.', 'Ordered list');
|
|
6
|
+
this.button = this.createButton(`
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
8
|
+
<path d="M10 12h11"/><path d="M10 18h11"/><path d="M10 6h11"/><path d="M4 10h2"/><path d="M4 6h1v4"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/>
|
|
9
|
+
</svg>
|
|
10
|
+
`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// You can change how the syntax is applied for this specific tool:
|
|
14
|
+
applySyntax() {
|
|
15
|
+
super.applySyntax('start'); // Only apply strikethrough at the start
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export default OLTool;
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
// #components/Toolbar/tools/PreviewToggleTool.js
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
class PreviewTool extends
|
|
5
|
-
constructor(editor) {
|
|
6
|
-
// No markdown syntax for preview toggle, so we call the parent constructor with empty values
|
|
7
|
-
super(editor, '', 'Preview');
|
|
8
|
-
this.button = this.createButton(`
|
|
9
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
10
|
-
<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M12 3v18"/>
|
|
11
|
-
</svg>
|
|
12
|
-
`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Override applySyntax to handle preview toggling
|
|
16
|
-
applySyntax() {
|
|
17
|
-
const previewWrapper = this.editor.previewContent?.parentNode;
|
|
18
|
-
const editorDiv = this.editor.markdownEditorDiv;
|
|
19
|
-
|
|
20
|
-
if (!previewWrapper || !editorDiv) return;
|
|
21
|
-
|
|
22
|
-
// Toggle the preview's visibility by switching between 'block' and 'hidden' classes
|
|
23
|
-
if (this.editor.preview) {
|
|
24
|
-
this.enablePreview(previewWrapper, editorDiv);
|
|
25
|
-
} else {
|
|
26
|
-
this.disablePreview(previewWrapper, editorDiv);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Method to hide the preview (disable it)
|
|
31
|
-
disablePreview(previewWrapper, editorDiv) {
|
|
32
|
-
|
|
33
|
-
this.editor.preview = true;
|
|
34
|
-
|
|
35
|
-
editorDiv.parentNode.classList.toggle('fixed');
|
|
36
|
-
editorDiv.parentNode.classList.toggle('top-0');
|
|
37
|
-
editorDiv.parentNode.classList.toggle('inset-x-0');
|
|
38
|
-
editorDiv.parentNode.classList.toggle('rounded-md');
|
|
39
|
-
editorDiv.parentNode.classList.toggle('z-[999]');
|
|
40
|
-
|
|
41
|
-
previewWrapper.classList.toggle('hidden');
|
|
42
|
-
|
|
43
|
-
// Add grid layout and divide classes to the editor div
|
|
44
|
-
editorDiv.classList.remove(
|
|
45
|
-
'md:grid',
|
|
46
|
-
'md:grid-cols-2',
|
|
47
|
-
'md:divide-x',
|
|
48
|
-
'rtl:md:divide-x-reverse',
|
|
49
|
-
'md:divide-stone-300',
|
|
50
|
-
'dark:md:divide-stone-700'
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
editorDiv.querySelector(".textarea-wrapper").classList.remove(
|
|
54
|
-
'h-[90lvh]',
|
|
55
|
-
'hidden',
|
|
56
|
-
'md:block'
|
|
57
|
-
);
|
|
58
|
-
this.editor.render(); // Re-render content in the preview
|
|
59
|
-
|
|
60
|
-
editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.remove("!h-[90lvh]");
|
|
61
|
-
|
|
62
|
-
document.querySelector("body").classList.remove('overflow-hidden');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Method to show the preview (enable it)
|
|
66
|
-
enablePreview(previewWrapper, editorDiv) {
|
|
67
|
-
|
|
68
|
-
this.editor.preview = false;
|
|
69
|
-
|
|
70
|
-
editorDiv.parentNode.classList.toggle('fixed');
|
|
71
|
-
editorDiv.parentNode.classList.toggle('top-0');
|
|
72
|
-
editorDiv.parentNode.classList.toggle('inset-x-0');
|
|
73
|
-
editorDiv.parentNode.classList.toggle('rounded-md');
|
|
74
|
-
editorDiv.parentNode.classList.toggle('z-[999]');
|
|
75
|
-
|
|
76
|
-
previewWrapper.classList.toggle('hidden');
|
|
77
|
-
// Remove grid layout and divide classes from the editor div
|
|
78
|
-
editorDiv.classList.add(
|
|
79
|
-
'md:grid',
|
|
80
|
-
'md:grid-cols-2',
|
|
81
|
-
'md:divide-x',
|
|
82
|
-
'rtl:md:divide-x-reverse',
|
|
83
|
-
'md:divide-stone-300',
|
|
84
|
-
'dark:md:divide-stone-700'
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
editorDiv.querySelector(".textarea-wrapper").classList.add(
|
|
88
|
-
'h-[90lvh]',
|
|
89
|
-
'hidden',
|
|
90
|
-
'md:block'
|
|
91
|
-
);
|
|
92
|
-
editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.add("!h-[90lvh]");
|
|
93
|
-
|
|
94
|
-
document.querySelector("body").classList.add('overflow-hidden');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export default PreviewTool;
|
|
1
|
+
// #components/Toolbar/tools/PreviewToggleTool.js
|
|
2
|
+
import MakeTool from '../MakeTool.js';
|
|
3
|
+
|
|
4
|
+
class PreviewTool extends MakeTool {
|
|
5
|
+
constructor(editor) {
|
|
6
|
+
// No markdown syntax for preview toggle, so we call the parent constructor with empty values
|
|
7
|
+
super(editor, '', 'Preview');
|
|
8
|
+
this.button = this.createButton(`
|
|
9
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
10
|
+
<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M12 3v18"/>
|
|
11
|
+
</svg>
|
|
12
|
+
`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Override applySyntax to handle preview toggling
|
|
16
|
+
applySyntax() {
|
|
17
|
+
const previewWrapper = this.editor.previewContent?.parentNode;
|
|
18
|
+
const editorDiv = this.editor.markdownEditorDiv;
|
|
19
|
+
|
|
20
|
+
if (!previewWrapper || !editorDiv) return;
|
|
21
|
+
|
|
22
|
+
// Toggle the preview's visibility by switching between 'block' and 'hidden' classes
|
|
23
|
+
if (this.editor.preview) {
|
|
24
|
+
this.enablePreview(previewWrapper, editorDiv);
|
|
25
|
+
} else {
|
|
26
|
+
this.disablePreview(previewWrapper, editorDiv);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Method to hide the preview (disable it)
|
|
31
|
+
disablePreview(previewWrapper, editorDiv) {
|
|
32
|
+
|
|
33
|
+
this.editor.preview = true;
|
|
34
|
+
|
|
35
|
+
editorDiv.parentNode.classList.toggle('fixed');
|
|
36
|
+
editorDiv.parentNode.classList.toggle('top-0');
|
|
37
|
+
editorDiv.parentNode.classList.toggle('inset-x-0');
|
|
38
|
+
editorDiv.parentNode.classList.toggle('rounded-md');
|
|
39
|
+
editorDiv.parentNode.classList.toggle('z-[999]');
|
|
40
|
+
|
|
41
|
+
previewWrapper.classList.toggle('hidden');
|
|
42
|
+
|
|
43
|
+
// Add grid layout and divide classes to the editor div
|
|
44
|
+
editorDiv.classList.remove(
|
|
45
|
+
'md:grid',
|
|
46
|
+
'md:grid-cols-2',
|
|
47
|
+
'md:divide-x',
|
|
48
|
+
'rtl:md:divide-x-reverse',
|
|
49
|
+
'md:divide-stone-300',
|
|
50
|
+
'dark:md:divide-stone-700'
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
editorDiv.querySelector(".textarea-wrapper").classList.remove(
|
|
54
|
+
'h-[90lvh]',
|
|
55
|
+
'hidden',
|
|
56
|
+
'md:block'
|
|
57
|
+
);
|
|
58
|
+
this.editor.render(); // Re-render content in the preview
|
|
59
|
+
|
|
60
|
+
editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.remove("!h-[90lvh]");
|
|
61
|
+
|
|
62
|
+
document.querySelector("body").classList.remove('overflow-hidden');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Method to show the preview (enable it)
|
|
66
|
+
enablePreview(previewWrapper, editorDiv) {
|
|
67
|
+
|
|
68
|
+
this.editor.preview = false;
|
|
69
|
+
|
|
70
|
+
editorDiv.parentNode.classList.toggle('fixed');
|
|
71
|
+
editorDiv.parentNode.classList.toggle('top-0');
|
|
72
|
+
editorDiv.parentNode.classList.toggle('inset-x-0');
|
|
73
|
+
editorDiv.parentNode.classList.toggle('rounded-md');
|
|
74
|
+
editorDiv.parentNode.classList.toggle('z-[999]');
|
|
75
|
+
|
|
76
|
+
previewWrapper.classList.toggle('hidden');
|
|
77
|
+
// Remove grid layout and divide classes from the editor div
|
|
78
|
+
editorDiv.classList.add(
|
|
79
|
+
'md:grid',
|
|
80
|
+
'md:grid-cols-2',
|
|
81
|
+
'md:divide-x',
|
|
82
|
+
'rtl:md:divide-x-reverse',
|
|
83
|
+
'md:divide-stone-300',
|
|
84
|
+
'dark:md:divide-stone-700'
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
editorDiv.querySelector(".textarea-wrapper").classList.add(
|
|
88
|
+
'h-[90lvh]',
|
|
89
|
+
'hidden',
|
|
90
|
+
'md:block'
|
|
91
|
+
);
|
|
92
|
+
editorDiv.querySelector(".textarea-wrapper").querySelector("textarea").classList.add("!h-[90lvh]");
|
|
93
|
+
|
|
94
|
+
document.querySelector("body").classList.add('overflow-hidden');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default PreviewTool;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
class StrikethroughTool extends
|
|
4
|
-
constructor(editor) {
|
|
5
|
-
// Call the parent constructor with the markdown syntax for strikethrough (~~)
|
|
6
|
-
super(editor, '~~', 'strikethrough text');
|
|
7
|
-
this.button = this.createButton(`
|
|
8
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
-
<path d="M16 4H9a3 3 0 0 0-2.83 4"/>
|
|
10
|
-
<path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/>
|
|
11
|
-
</svg>
|
|
12
|
-
`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class StrikethroughTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
// Call the parent constructor with the markdown syntax for strikethrough (~~)
|
|
6
|
+
super(editor, '~~', 'strikethrough text');
|
|
7
|
+
this.button = this.createButton(`
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
9
|
+
<path d="M16 4H9a3 3 0 0 0-2.83 4"/>
|
|
10
|
+
<path d="M14 12a4 4 0 0 1 0 8H6"/><line x1="4" x2="20" y1="12" y2="12"/>
|
|
11
|
+
</svg>
|
|
12
|
+
`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
16
|
export default StrikethroughTool;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class ULTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, '-', 'Unordered list');
|
|
6
|
+
this.button = this.createButton(`
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 12h.01"/><path d="M3 18h.01"/><path d="M3 6h.01"/><path d="M8 12h13"/><path d="M8 18h13"/><path d="M8 6h13"/></svg>
|
|
8
|
+
`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// You can change how the syntax is applied for this specific tool:
|
|
12
|
+
applySyntax() {
|
|
13
|
+
super.applySyntax('start'); // Only apply strikethrough at the start
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export default ULTool;
|