markdown-text-editor 0.1.0 → 0.1.2
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 +280 -277
- package/dist/index.css +58 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/markdown-text-editor.css +58 -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 +22 -63
- package/src/plugins/markdown/Toolbar/index.js +56 -42
- package/src/plugins/markdown/Toolbar/tools/BlockQuoteTool.js +31 -0
- package/src/plugins/markdown/Toolbar/tools/BoldTool.js +33 -15
- package/src/plugins/markdown/Toolbar/tools/CheckListTool.js +30 -17
- package/src/plugins/markdown/Toolbar/tools/HeadingTool.js +55 -0
- package/src/plugins/markdown/Toolbar/tools/ItalicTool.js +30 -16
- package/src/plugins/markdown/Toolbar/tools/LinkTool.js +47 -0
- package/src/plugins/markdown/Toolbar/tools/OLTool.js +30 -19
- package/src/plugins/markdown/Toolbar/tools/PreviewTool.js +108 -98
- package/src/plugins/markdown/Toolbar/tools/StrikethroughTool.js +30 -15
- package/src/plugins/markdown/Toolbar/tools/ULTool.js +30 -17
- package/src/plugins/markdown/editor.js +171 -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/package.json
CHANGED
|
@@ -1,67 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "markdown-text-editor",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A
|
|
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
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"markdown",
|
|
28
|
-
"mde",
|
|
29
|
-
"markdown
|
|
30
|
-
"
|
|
31
|
-
"editor",
|
|
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
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-text-editor",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "A simple JavaScript Markdown editor plugin with real-time preview, and easy integration.",
|
|
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": "git+https://github.com/nezanuha/markdown-text-editor.git"
|
|
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
|
+
"provenance": true,
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"markdown",
|
|
28
|
+
"mde",
|
|
29
|
+
"markdown js library",
|
|
30
|
+
"editor",
|
|
31
|
+
"markdown editor",
|
|
32
|
+
"text editor",
|
|
33
|
+
"markdown preview",
|
|
34
|
+
"markdown syntax",
|
|
35
|
+
"markdown plugin",
|
|
36
|
+
"rich text editor",
|
|
37
|
+
"wysiwyg",
|
|
38
|
+
"markdown formatting",
|
|
39
|
+
"code editor",
|
|
40
|
+
"editor plugin",
|
|
41
|
+
"text formatting",
|
|
42
|
+
"markdown-text-editor"
|
|
43
|
+
],
|
|
44
|
+
"author": "Nezanuha",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"homepage": "https://github.com/nezanuha/markdown-text-editor",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/nezanuha/markdown-text-editor/issues"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"marked": "~15.0.4",
|
|
52
|
+
"tailwindcss": "~3.4.13",
|
|
53
|
+
"@tailwindcss/typography": "~0.5.15"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@babel/core": "^7.25.2",
|
|
57
|
+
"@babel/preset-env": "^7.25.4",
|
|
58
|
+
"autoprefixer": "^10.4.20",
|
|
59
|
+
"babel-loader": "^9.2.1",
|
|
60
|
+
"css-loader": "^7.1.2",
|
|
61
|
+
"html-webpack-plugin": "^5.6.3",
|
|
62
|
+
"mini-css-extract-plugin": "^2.9.1",
|
|
63
|
+
"postcss": "^8.4.47",
|
|
64
|
+
"postcss-loader": "^8.1.1",
|
|
65
|
+
"rimraf": "^6.0.1",
|
|
66
|
+
"style-loader": "^4.0.0",
|
|
67
|
+
"terser-webpack-plugin": "^5.3.11",
|
|
68
|
+
"webpack": "^5.95.0",
|
|
69
|
+
"webpack-cli": "^6.0.1",
|
|
70
|
+
"webpack-dev-server": "^5.2.0"
|
|
71
|
+
}
|
|
72
|
+
}
|
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';
|
|
@@ -1,63 +1,22 @@
|
|
|
1
|
-
class MakeTool {
|
|
2
|
-
constructor(editor,
|
|
3
|
-
this.editor = editor;
|
|
4
|
-
this.
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Create a button element (can be overridden in child classes)
|
|
10
|
-
createButton(iconHtml) {
|
|
11
|
-
const button = document.createElement('button');
|
|
12
|
-
|
|
13
|
-
button.
|
|
14
|
-
button.
|
|
15
|
-
button.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
class MakeTool {
|
|
2
|
+
constructor(editor, title) {
|
|
3
|
+
this.editor = editor;
|
|
4
|
+
this.defaultText = `${title} text`; // Default text if nothing is selected
|
|
5
|
+
this.button = this.createButton();
|
|
6
|
+
this.title = title
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Create a button element (can be overridden in child classes)
|
|
10
|
+
createButton(iconHtml) {
|
|
11
|
+
const button = document.createElement('button');
|
|
12
|
+
const buttonClass = this.title ? `${this.title.replace(/ /g, '-')}-btn`.toLowerCase() : '';
|
|
13
|
+
button.innerHTML = iconHtml; // Pass icon HTML from child classes
|
|
14
|
+
button.type = 'button';
|
|
15
|
+
button.title = this.title;
|
|
16
|
+
button.className = `markdown-btn ${buttonClass}${buttonClass == 'preview-btn' ? ' sticky right-0 bg-stone-100 dark:bg-stone-900 ' : ' ' }p-2 hover:bg-stone-200 dark:hover:bg-stone-600 rounded duration-300 text-stone-900 dark:text-stone-100`;
|
|
17
|
+
button.addEventListener('click', () => this.applySyntax()); // Default to 'both', can change in child
|
|
18
|
+
return button;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default MakeTool;
|
|
@@ -1,42 +1,56 @@
|
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 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
|
+
import BlockQuoteTool from './tools/BlockQuoteTool.js';
|
|
10
|
+
import LinkTool from './tools/LinkTool.js'
|
|
11
|
+
import HeadingTool from './tools/HeadingTool.js';
|
|
12
|
+
|
|
13
|
+
class Toolbar {
|
|
14
|
+
constructor(editor, options) {
|
|
15
|
+
this.editor = editor;
|
|
16
|
+
this.options = options;
|
|
17
|
+
this.toolbar = document.createElement('div');
|
|
18
|
+
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 overflow-x-auto';
|
|
19
|
+
this.init();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
init() {
|
|
23
|
+
const toolMapping = {
|
|
24
|
+
heading: HeadingTool,
|
|
25
|
+
ul: ULTool,
|
|
26
|
+
ol: OLTool,
|
|
27
|
+
checklist: CheckListTool,
|
|
28
|
+
bold: BoldTool,
|
|
29
|
+
italic: ItalicTool,
|
|
30
|
+
strikethrough: StrikethroughTool,
|
|
31
|
+
blockquote: BlockQuoteTool,
|
|
32
|
+
link: LinkTool
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Append all tools except preview
|
|
36
|
+
this.options.forEach(tool => {
|
|
37
|
+
if (tool !== 'preview') {
|
|
38
|
+
const ToolClass = toolMapping[tool];
|
|
39
|
+
if (ToolClass) {
|
|
40
|
+
const toolInstance = new ToolClass(this.editor);
|
|
41
|
+
this.toolbar.appendChild(toolInstance.button); // Directly append to toolbar
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Append preview button at the end
|
|
47
|
+
if (this.options.includes('preview')) {
|
|
48
|
+
const previewToolInstance = new PreviewTool(this.editor);
|
|
49
|
+
this.toolbar.appendChild(previewToolInstance.button); // Directly append to toolbar at the end
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.editor.editorContainer.insertBefore(this.toolbar, this.editor.markdownEditorDiv);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default Toolbar;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class BlockQuoteTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
// Call the parent constructor with the markdown syntax for italic (*)
|
|
6
|
+
super(editor, 'Blockquote');
|
|
7
|
+
this.button = this.createButton(`
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M4.58341 17.3211C3.55316 16.2274 3 15 3 13.0103C3 9.51086 5.45651 6.37366 9.03059 4.82318L9.92328 6.20079C6.58804 8.00539 5.93618 10.346 5.67564 11.822C6.21263 11.5443 6.91558 11.4466 7.60471 11.5105C9.40908 11.6778 10.8312 13.159 10.8312 15C10.8312 16.933 9.26416 18.5 7.33116 18.5C6.2581 18.5 5.23196 18.0095 4.58341 17.3211ZM14.5834 17.3211C13.5532 16.2274 13 15 13 13.0103C13 9.51086 15.4565 6.37366 19.0306 4.82318L19.9233 6.20079C16.588 8.00539 15.9362 10.346 15.6756 11.822C16.2126 11.5443 16.9156 11.4466 17.6047 11.5105C19.4091 11.6778 20.8312 13.159 20.8312 15C20.8312 16.933 19.2642 18.5 17.3312 18.5C16.2581 18.5 15.232 18.0095 14.5834 17.3211Z"></path></svg>
|
|
9
|
+
`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
applySyntax() {
|
|
13
|
+
const textarea = this.editor.usertextarea;
|
|
14
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
15
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
16
|
+
|
|
17
|
+
const syntax = '>';
|
|
18
|
+
let newText = '';
|
|
19
|
+
if (selectedText.startsWith(syntax)) {
|
|
20
|
+
// Remove the blockquote syntax if it's already wrapped
|
|
21
|
+
newText = selectedText.slice(syntax.length);
|
|
22
|
+
} else {
|
|
23
|
+
// Apply blockquote syntax
|
|
24
|
+
newText = `${syntax}${selectedText || 'Blockquote text'}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.editor.insertText(newText);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default BlockQuoteTool;
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
-
import MakeTool from '../MakeTool.js';
|
|
2
|
-
|
|
3
|
-
class BoldTool extends MakeTool {
|
|
4
|
-
constructor(editor) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class BoldTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, 'Bold');
|
|
6
|
+
this.button = this.createButton(`
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20">
|
|
8
|
+
<path d="M8 11H12.5C13.8807 11 15 9.88071 15 8.5C15 7.11929 13.8807 6 12.5 6H8V11ZM18 15.5C18 17.9853 15.9853 20 13.5 20H6V4H12.5C14.9853 4 17 6.01472 17 8.5C17 9.70431 16.5269 10.7981 15.7564 11.6058C17.0979 12.3847 18 13.837 18 15.5ZM8 13V18H13.5C14.8807 18 16 16.8807 16 15.5C16 14.1193 14.8807 13 13.5 13H8Z"></path>
|
|
9
|
+
</svg>
|
|
10
|
+
`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Apply bold syntax (**bold**)
|
|
14
|
+
applySyntax() {
|
|
15
|
+
const textarea = this.editor.usertextarea;
|
|
16
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
17
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
18
|
+
|
|
19
|
+
const syntax = '**';
|
|
20
|
+
let newText = '';
|
|
21
|
+
if (selectedText.startsWith(syntax) && selectedText.endsWith(syntax)) {
|
|
22
|
+
// Remove the bold syntax if it's already wrapped
|
|
23
|
+
newText = selectedText.slice(syntax.length, -syntax.length);
|
|
24
|
+
} else {
|
|
25
|
+
// Apply bold syntax
|
|
26
|
+
newText = `${syntax}${selectedText || 'Bold text'}${syntax}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.editor.insertText(newText);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default BoldTool;
|
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
import MakeTool from '../MakeTool.js';
|
|
2
|
-
|
|
3
|
-
class CheckListTool extends MakeTool {
|
|
4
|
-
constructor(editor) {
|
|
5
|
-
super(editor, '
|
|
6
|
-
this.button = this.createButton(`
|
|
7
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
8
|
-
`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class CheckListTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, 'Check list');
|
|
6
|
+
this.button = this.createButton(`
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M8.00008 6V9H5.00008V6H8.00008ZM3.00008 4V11H10.0001V4H3.00008ZM13.0001 4H21.0001V6H13.0001V4ZM13.0001 11H21.0001V13H13.0001V11ZM13.0001 18H21.0001V20H13.0001V18ZM10.7072 16.2071L9.29297 14.7929L6.00008 18.0858L4.20718 16.2929L2.79297 17.7071L6.00008 20.9142L10.7072 16.2071Z"></path></svg>
|
|
8
|
+
`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
applySyntax() {
|
|
12
|
+
const textarea = this.editor.usertextarea;
|
|
13
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
14
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
15
|
+
|
|
16
|
+
const syntax = '- [x] ';
|
|
17
|
+
let newText = '';
|
|
18
|
+
if (selectedText.startsWith(syntax)) {
|
|
19
|
+
// Remove the checklist syntax if it's already wrapped
|
|
20
|
+
newText = selectedText.slice(syntax.length);
|
|
21
|
+
} else {
|
|
22
|
+
// Apply check list syntax
|
|
23
|
+
newText = `${syntax}${selectedText || 'Check list'}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.editor.insertText(newText);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
18
31
|
export default CheckListTool;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class HeadingTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, 'Heading');
|
|
6
|
+
this.currentHeading = 1; // Start with Heading 1
|
|
7
|
+
this.button = this.createButton(`
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M17 11V4H19V21H17V13H7V21H5V4H7V11H17Z"></path></svg>
|
|
9
|
+
`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Apply heading syntax (e.g., # sample text for h1, ## sample text for h2, etc.)
|
|
13
|
+
applySyntax() {
|
|
14
|
+
const textarea = this.editor.usertextarea;
|
|
15
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
16
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
17
|
+
|
|
18
|
+
// Strip any existing heading symbols (i.e., # or ##) from the selected text
|
|
19
|
+
const headingRegex = /^#+\s*/; // Regex to match any # followed by space
|
|
20
|
+
let cleanText = selectedText.replace(headingRegex, ''); // Remove existing heading
|
|
21
|
+
|
|
22
|
+
let newText = '';
|
|
23
|
+
|
|
24
|
+
// If there is a heading, continue from the current level
|
|
25
|
+
if (selectedText) {
|
|
26
|
+
const currentLevel = selectedText.match(/^#+/); // Match the number of # symbols at the start
|
|
27
|
+
if (currentLevel) {
|
|
28
|
+
let headingCount = currentLevel[0].length;
|
|
29
|
+
if (headingCount === 6) {
|
|
30
|
+
newText = cleanText; // Just plain text
|
|
31
|
+
} else {
|
|
32
|
+
newText = `${'#'.repeat(headingCount + 1)} ${cleanText}`;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
// If no # symbol, start from # (Heading 1)
|
|
36
|
+
newText = `# ${cleanText}`;
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
// If no text is selected, use default "Heading"
|
|
40
|
+
newText = `${'#'.repeat(this.currentHeading)} Heading`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Insert the new heading text and replace any selected text
|
|
44
|
+
this.editor.insertText(newText, true);
|
|
45
|
+
|
|
46
|
+
// Cycle heading levels after applying the heading
|
|
47
|
+
if (this.currentHeading === 6) {
|
|
48
|
+
this.currentHeading = 1; // Reset to # for Heading 1 after reaching Heading 6
|
|
49
|
+
} else {
|
|
50
|
+
this.currentHeading++; // Increment the heading level
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default HeadingTool;
|
|
@@ -1,17 +1,31 @@
|
|
|
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, '
|
|
7
|
-
this.button = this.createButton(`
|
|
8
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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');
|
|
7
|
+
this.button = this.createButton(`
|
|
8
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20"><path d="M15 20H7V18H9.92661L12.0425 6H9V4H17V6H14.0734L11.9575 18H15V20Z"></path></svg>
|
|
9
|
+
`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
applySyntax() {
|
|
13
|
+
const textarea = this.editor.usertextarea;
|
|
14
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
15
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
16
|
+
|
|
17
|
+
const syntax = '*';
|
|
18
|
+
let newText = '';
|
|
19
|
+
if (selectedText.startsWith(syntax) && selectedText.endsWith(syntax)) {
|
|
20
|
+
// Remove the italic syntax if it's already wrapped
|
|
21
|
+
newText = selectedText.slice(syntax.length, -syntax.length);
|
|
22
|
+
} else {
|
|
23
|
+
// Apply italic syntax
|
|
24
|
+
newText = `${syntax}${selectedText || 'Italic text'}${syntax}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.editor.insertText(newText);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
export default ItalicTool;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import MakeTool from '../MakeTool.js';
|
|
2
|
+
|
|
3
|
+
class LinkTool extends MakeTool {
|
|
4
|
+
constructor(editor) {
|
|
5
|
+
super(editor, 'Link');
|
|
6
|
+
this.button = this.createButton(`
|
|
7
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" width="20" height="20">
|
|
8
|
+
<path d="M18.3638 15.5355L16.9496 14.1213L18.3638 12.7071C20.3164 10.7545 20.3164 7.58866 18.3638 5.63604C16.4112 3.68341 13.2453 3.68341 11.2927 5.63604L9.87849 7.05025L8.46428 5.63604L9.87849 4.22182C12.6122 1.48815 17.0443 1.48815 19.778 4.22182C22.5117 6.95549 22.5117 11.3876 19.778 14.1213L18.3638 15.5355ZM15.5353 18.364L14.1211 19.7782C11.3875 22.5118 6.95531 22.5118 4.22164 19.7782C1.48797 17.0445 1.48797 12.6123 4.22164 9.87868L5.63585 8.46446L7.05007 9.87868L5.63585 11.2929C3.68323 13.2455 3.68323 16.4113 5.63585 18.364C7.58847 20.3166 10.7543 20.3166 12.7069 18.364L14.1211 16.9497L15.5353 18.364ZM14.8282 7.75736L16.2425 9.17157L9.17139 16.2426L7.75717 14.8284L14.8282 7.75736Z"></path>
|
|
9
|
+
</svg>
|
|
10
|
+
`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Apply link syntax [text](url)
|
|
14
|
+
applySyntax() {
|
|
15
|
+
const textarea = this.editor.usertextarea;
|
|
16
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
17
|
+
const selectedText = textarea.value.substring(selectionStart, selectionEnd);
|
|
18
|
+
|
|
19
|
+
// Check if the selected text contains a link syntax [text](url)
|
|
20
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/;
|
|
21
|
+
|
|
22
|
+
if (selectedText && linkRegex.test(selectedText)) {
|
|
23
|
+
// If the selected text is already a link, extract the text inside the brackets
|
|
24
|
+
const match = selectedText.match(linkRegex);
|
|
25
|
+
const linkText = match[1]; // Text inside the square brackets
|
|
26
|
+
|
|
27
|
+
// Replace the selected text with just the text
|
|
28
|
+
textarea.setRangeText(linkText, selectionStart, selectionEnd, 'select');
|
|
29
|
+
} else {
|
|
30
|
+
// If no link syntax, prompt for the URL and apply the syntax
|
|
31
|
+
const url = prompt("Enter the URL:", "https://");
|
|
32
|
+
if (url) {
|
|
33
|
+
let newText = '';
|
|
34
|
+
if (selectedText) {
|
|
35
|
+
newText = `[${selectedText}](${url})`; // Insert the link with selected text
|
|
36
|
+
} else {
|
|
37
|
+
newText = `[Link text](${url})`; // Insert a placeholder text if nothing is selected
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.editor.insertText(newText); // Insert the constructed link markdown
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default LinkTool;
|