markdown-text-editor 0.0.17-beta.1 → 0.0.18-beta.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/package.json CHANGED
@@ -1,61 +1,62 @@
1
- {
2
- "name": "markdown-text-editor",
3
- "version": "0.0.17-beta.1",
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
- "files": [
7
- "dist/**/*",
8
- "src/**/*"
9
- ],
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/nezanuha/markdown-text-editor"
13
- },
14
- "scripts": {
15
- "clean": "rm -rf dist",
16
- "build": "npm run clean && webpack --mode=production",
17
- "prepublishOnly": "npm run build",
18
- "dev": "webpack --watch --mode=development"
19
- },
20
- "publishConfig": {
21
- "registry": "https://registry.npmjs.org/"
22
- },
23
- "keywords": [
24
- "markdown-text-editor",
25
- "markdown",
26
- "text-editor",
27
- "editor",
28
- "live preview",
29
- "syntax highlighting",
30
- "developer tools",
31
- "content creation",
32
- "plugin",
33
- "open source"
34
- ],
35
- "author": "Nezanuha",
36
- "license": "MIT",
37
- "homepage": "https://github.com/nezanuha/markdown-text-editor",
38
- "bugs": {
39
- "url": "https://github.com/nezanuha/markdown-text-editor/issues"
40
- },
41
- "dependencies": {
42
- "marked": "^15.0.4",
43
- "tailwindcss": "^3.4.13"
44
- },
45
- "devDependencies": {
46
- "@babel/core": "^7.25.2",
47
- "@babel/preset-env": "^7.25.4",
48
- "@tailwindcss/typography": "^0.5.15",
49
- "autoprefixer": "^10.4.20",
50
- "babel-loader": "^9.2.1",
51
- "css-loader": "^7.1.2",
52
- "mini-css-extract-plugin": "^2.9.1",
53
- "postcss": "^8.4.47",
54
- "postcss-loader": "^8.1.1",
55
- "style-loader": "^4.0.0",
56
- "terser-webpack-plugin": "^5.3.11",
57
- "webpack": "^5.95.0",
58
- "webpack-cli": "^6.0.1",
59
- "webpack-dev-server": "^5.1.0"
60
- }
61
- }
1
+ {
2
+ "name": "markdown-text-editor",
3
+ "version": "0.0.18-beta.1",
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
+ "style": "./dist/markdown-text-editor.css",
7
+ "files": [
8
+ "dist/**/*",
9
+ "src/**/*"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/nezanuha/markdown-text-editor"
14
+ },
15
+ "scripts": {
16
+ "clean": "rm -rf dist",
17
+ "build": "npm run clean && webpack --mode=production",
18
+ "prepublishOnly": "npm run build",
19
+ "dev": "webpack --watch --mode=development"
20
+ },
21
+ "publishConfig": {
22
+ "registry": "https://registry.npmjs.org/"
23
+ },
24
+ "keywords": [
25
+ "markdown-text-editor",
26
+ "markdown",
27
+ "text-editor",
28
+ "editor",
29
+ "live preview",
30
+ "syntax highlighting",
31
+ "developer tools",
32
+ "content creation",
33
+ "plugin",
34
+ "open source"
35
+ ],
36
+ "author": "Nezanuha",
37
+ "license": "MIT",
38
+ "homepage": "https://github.com/nezanuha/markdown-text-editor",
39
+ "bugs": {
40
+ "url": "https://github.com/nezanuha/markdown-text-editor/issues"
41
+ },
42
+ "dependencies": {
43
+ "marked": "^15.0.4",
44
+ "tailwindcss": "^3.4.13"
45
+ },
46
+ "devDependencies": {
47
+ "@babel/core": "^7.25.2",
48
+ "@babel/preset-env": "^7.25.4",
49
+ "@tailwindcss/typography": "^0.5.15",
50
+ "autoprefixer": "^10.4.20",
51
+ "babel-loader": "^9.2.1",
52
+ "css-loader": "^7.1.2",
53
+ "mini-css-extract-plugin": "^2.9.1",
54
+ "postcss": "^8.4.47",
55
+ "postcss-loader": "^8.1.1",
56
+ "style-loader": "^4.0.0",
57
+ "terser-webpack-plugin": "^5.3.11",
58
+ "webpack": "^5.95.0",
59
+ "webpack-cli": "^6.0.1",
60
+ "webpack-dev-server": "^5.1.0"
61
+ }
62
+ }
@@ -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,36 +1,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 PreviewTool from './tools/PreviewTool.js'
6
-
7
- class Toolbar {
8
- constructor(editor, options) {
9
- this.editor = editor;
10
- this.options = options;
11
- this.toolbar = document.createElement('div');
12
- 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';
13
- this.init();
14
- }
15
-
16
- init() {
17
- const toolMapping = {
18
- bold: BoldTool,
19
- italic: ItalicTool,
20
- strikethrough: StrikethroughTool,
21
- preview: PreviewTool
22
- };
23
-
24
- this.options.forEach(tool => {
25
- const ToolClass = toolMapping[tool];
26
- if (ToolClass) {
27
- const toolInstance = new ToolClass(this.editor);
28
- this.toolbar.appendChild(toolInstance.button);
29
- }
30
- });
31
-
32
- this.editor.editorContainer.insertBefore(this.toolbar, this.editor.markdownEditorDiv);
33
- }
34
- }
35
-
36
- export default Toolbar;
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 PreviewTool from './tools/PreviewTool.js'
6
+
7
+ class Toolbar {
8
+ constructor(editor, options) {
9
+ this.editor = editor;
10
+ this.options = options;
11
+ this.toolbar = document.createElement('div');
12
+ 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';
13
+ this.init();
14
+ }
15
+
16
+ init() {
17
+ const toolMapping = {
18
+ bold: BoldTool,
19
+ italic: ItalicTool,
20
+ strikethrough: StrikethroughTool,
21
+ preview: PreviewTool
22
+ };
23
+
24
+ this.options.forEach(tool => {
25
+ const ToolClass = toolMapping[tool];
26
+ if (ToolClass) {
27
+ const toolInstance = new ToolClass(this.editor);
28
+ this.toolbar.appendChild(toolInstance.button);
29
+ }
30
+ });
31
+
32
+ this.editor.editorContainer.insertBefore(this.toolbar, this.editor.markdownEditorDiv);
33
+ }
34
+ }
35
+
36
+ export default Toolbar;
@@ -1,15 +1,15 @@
1
- import MarkdownTool from './MarkdownTool.js';
2
-
3
- class BoldTool extends MarkdownTool {
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 MarkdownTool from './MarkdownTool.js';
2
+
3
+ class BoldTool extends MarkdownTool {
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;
@@ -1,17 +1,17 @@
1
- import MarkdownTool from './MarkdownTool.js';
2
-
3
- class ItalicTool extends MarkdownTool {
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 MarkdownTool from './MarkdownTool.js';
2
+
3
+ class ItalicTool extends MarkdownTool {
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;
@@ -1,39 +1,39 @@
1
- // #components\Toolbar\tools\MarkdownTool.js
2
- class MarkdownTool {
3
- constructor(editor, syntax, defaultText) {
4
- this.editor = editor;
5
- this.syntax = syntax; // Markdown syntax (e.g., ** for bold, * for italic)
6
- this.defaultText = defaultText; // Default text if nothing is selected
7
- this.button = this.createButton();
8
- }
9
-
10
- // Create a button element (can be overridden in child classes)
11
- createButton(iconHtml) {
12
- const button = document.createElement('button');
13
- button.innerHTML = iconHtml; // Pass icon HTML from child classes
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());
16
- return button;
17
- }
18
-
19
- // Toggle markdown syntax at the current cursor position
20
- applySyntax() {
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
- if (selectedText.startsWith(this.syntax) && selectedText.endsWith(this.syntax)) {
28
- // If text is already wrapped with the markdown syntax, remove it
29
- const unformattedText = selectedText.slice(syntaxLength, -syntaxLength);
30
- this.editor.insertText(unformattedText);
31
- } else {
32
- // If no text is selected or it's not wrapped, add the markdown syntax
33
- const newText = `${this.syntax}${selectedText || this.defaultText}${this.syntax}`;
34
- this.editor.insertText(newText);
35
- }
36
- }
37
- }
38
-
1
+ // #components\Toolbar\tools\MarkdownTool.js
2
+ class MarkdownTool {
3
+ constructor(editor, syntax, defaultText) {
4
+ this.editor = editor;
5
+ this.syntax = syntax; // Markdown syntax (e.g., ** for bold, * for italic)
6
+ this.defaultText = defaultText; // Default text if nothing is selected
7
+ this.button = this.createButton();
8
+ }
9
+
10
+ // Create a button element (can be overridden in child classes)
11
+ createButton(iconHtml) {
12
+ const button = document.createElement('button');
13
+ button.innerHTML = iconHtml; // Pass icon HTML from child classes
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());
16
+ return button;
17
+ }
18
+
19
+ // Toggle markdown syntax at the current cursor position
20
+ applySyntax() {
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
+ if (selectedText.startsWith(this.syntax) && selectedText.endsWith(this.syntax)) {
28
+ // If text is already wrapped with the markdown syntax, remove it
29
+ const unformattedText = selectedText.slice(syntaxLength, -syntaxLength);
30
+ this.editor.insertText(unformattedText);
31
+ } else {
32
+ // If no text is selected or it's not wrapped, add the markdown syntax
33
+ const newText = `${this.syntax}${selectedText || this.defaultText}${this.syntax}`;
34
+ this.editor.insertText(newText);
35
+ }
36
+ }
37
+ }
38
+
39
39
  export default MarkdownTool;
@@ -1,92 +1,92 @@
1
- // #components/Toolbar/tools/PreviewToggleTool.js
2
- import MarkdownTool from './MarkdownTool.js';
3
-
4
- class PreviewTool extends MarkdownTool {
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
-
40
- previewWrapper.classList.toggle('hidden');
41
-
42
- // Add grid layout and divide classes to the editor div
43
- editorDiv.classList.remove(
44
- 'md:grid',
45
- 'md:grid-cols-2',
46
- 'md:divide-x',
47
- 'md:divide-stone-300',
48
- 'dark:md:divide-stone-700'
49
- );
50
-
51
- editorDiv.querySelector(".textarea-wrapper").classList.remove(
52
- 'h-lvh',
53
- 'hidden',
54
- 'md:block'
55
- );
56
- this.editor.render(); // Re-render content in the preview
57
-
58
- document.querySelector("body").classList.remove('overflow-hidden');
59
- }
60
-
61
- // Method to show the preview (enable it)
62
- enablePreview(previewWrapper, editorDiv) {
63
-
64
- this.editor.preview = false;
65
-
66
- editorDiv.parentNode.classList.toggle('fixed');
67
- editorDiv.parentNode.classList.toggle('top-0');
68
- editorDiv.parentNode.classList.toggle('inset-x-0');
69
- editorDiv.parentNode.classList.toggle('rounded-md');
70
-
71
- previewWrapper.classList.toggle('hidden');
72
- // Remove grid layout and divide classes from the editor div
73
- editorDiv.classList.add(
74
- 'md:grid',
75
- 'md:grid-cols-2',
76
- 'md:divide-x',
77
- 'md:divide-stone-300',
78
- 'dark:md:divide-stone-700'
79
- );
80
-
81
- editorDiv.querySelector(".textarea-wrapper").classList.add(
82
- 'h-lvh',
83
- 'hidden',
84
- 'md:block'
85
- );
86
- // editorDiv.closest(".textarea-wrapper>textarea").classList.add("h-lvh");
87
-
88
- document.querySelector("body").classList.add('overflow-hidden');
89
- }
90
- }
91
-
92
- export default PreviewTool;
1
+ // #components/Toolbar/tools/PreviewToggleTool.js
2
+ import MarkdownTool from './MarkdownTool.js';
3
+
4
+ class PreviewTool extends MarkdownTool {
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
+
40
+ previewWrapper.classList.toggle('hidden');
41
+
42
+ // Add grid layout and divide classes to the editor div
43
+ editorDiv.classList.remove(
44
+ 'md:grid',
45
+ 'md:grid-cols-2',
46
+ 'md:divide-x',
47
+ 'md:divide-stone-300',
48
+ 'dark:md:divide-stone-700'
49
+ );
50
+
51
+ editorDiv.querySelector(".textarea-wrapper").classList.remove(
52
+ 'h-lvh',
53
+ 'hidden',
54
+ 'md:block'
55
+ );
56
+ this.editor.render(); // Re-render content in the preview
57
+
58
+ document.querySelector("body").classList.remove('overflow-hidden');
59
+ }
60
+
61
+ // Method to show the preview (enable it)
62
+ enablePreview(previewWrapper, editorDiv) {
63
+
64
+ this.editor.preview = false;
65
+
66
+ editorDiv.parentNode.classList.toggle('fixed');
67
+ editorDiv.parentNode.classList.toggle('top-0');
68
+ editorDiv.parentNode.classList.toggle('inset-x-0');
69
+ editorDiv.parentNode.classList.toggle('rounded-md');
70
+
71
+ previewWrapper.classList.toggle('hidden');
72
+ // Remove grid layout and divide classes from the editor div
73
+ editorDiv.classList.add(
74
+ 'md:grid',
75
+ 'md:grid-cols-2',
76
+ 'md:divide-x',
77
+ 'md:divide-stone-300',
78
+ 'dark:md:divide-stone-700'
79
+ );
80
+
81
+ editorDiv.querySelector(".textarea-wrapper").classList.add(
82
+ 'h-lvh',
83
+ 'hidden',
84
+ 'md:block'
85
+ );
86
+ // editorDiv.closest(".textarea-wrapper>textarea").classList.add("h-lvh");
87
+
88
+ document.querySelector("body").classList.add('overflow-hidden');
89
+ }
90
+ }
91
+
92
+ export default PreviewTool;
@@ -1,16 +1,16 @@
1
- import MarkdownTool from './MarkdownTool.js';
2
-
3
- class StrikethroughTool extends MarkdownTool {
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 MarkdownTool from './MarkdownTool.js';
2
+
3
+ class StrikethroughTool extends MarkdownTool {
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;