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/package.json CHANGED
@@ -1,67 +1,72 @@
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
- }
1
+ {
2
+ "name": "markdown-text-editor",
3
+ "version": "0.1.1",
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
+ },
54
+ "devDependencies": {
55
+ "@babel/core": "^7.25.2",
56
+ "@babel/preset-env": "^7.25.4",
57
+ "@tailwindcss/typography": "^0.5.15",
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
+ }
@@ -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,66 @@
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
+ class MakeTool {
2
+ constructor(editor, syntax, title) {
3
+ this.editor = editor;
4
+ this.syntax = syntax; // Markdown syntax (e.g., ** for bold, * for italic)
5
+ this.defaultText = `${title} text`; // Default text if nothing is selected
6
+ this.button = this.createButton();
7
+ this.title = title
8
+ }
9
+
10
+ // Create a button element (can be overridden in child classes)
11
+ createButton(iconHtml) {
12
+ const button = document.createElement('button');
13
+ const buttonClass = this.title ? `${this.title.replace(/ /g, '-')}-btn`.toLowerCase() : '';
14
+ button.innerHTML = iconHtml; // Pass icon HTML from child classes
15
+ button.type = 'button';
16
+ button.title = this.title;
17
+ 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`;
18
+ button.addEventListener('click', () => this.applySyntax('both')); // Default to 'both', can change in child
19
+ return button;
20
+ }
21
+
22
+ // Toggle markdown syntax at the current cursor position
23
+ applySyntax(position = 'both') {
24
+ const textarea = this.editor.usertextarea;
25
+ const { selectionStart, selectionEnd } = textarea;
26
+ const selectedText = textarea.value.substring(selectionStart, selectionEnd);
27
+
28
+ const syntaxLength = this.syntax.length;
29
+
30
+ // Check which type of syntax to apply based on the position
31
+ let newText = '';
32
+ if(position === 'start'){
33
+ if (selectedText.startsWith(this.syntax)) {
34
+ // If text is already wrapped with the markdown syntax, remove it
35
+ const unformattedText = selectedText.slice(syntaxLength);
36
+ this.editor.insertText(unformattedText);
37
+ }else{
38
+ newText = `${this.syntax} ${selectedText || this.defaultText}`;
39
+ // Insert the new formatted text
40
+ this.editor.insertText(newText);
41
+ }
42
+ } else if (position === 'end') {
43
+ if (selectedText.startsWith(this.syntax)) {
44
+ // If text is already wrapped with the markdown syntax, remove it
45
+ const unformattedText = selectedText.slice(syntaxLength);
46
+ this.editor.insertText(unformattedText);
47
+ }else{
48
+ newText = `${selectedText || this.defaultText}${this.syntax}`;
49
+ // Insert the new formatted text
50
+ this.editor.insertText(newText);
51
+ }
52
+ } else {
53
+ if (selectedText.startsWith(this.syntax) && selectedText.endsWith(this.syntax)) {
54
+ // If text is already wrapped with the markdown syntax, remove it
55
+ const unformattedText = selectedText.slice(syntaxLength, -syntaxLength);
56
+ this.editor.insertText(unformattedText);
57
+ }else{
58
+ newText = `${this.syntax}${selectedText || this.defaultText}${this.syntax}`;
59
+ // Insert the new formatted text
60
+ this.editor.insertText(newText);
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ export default MakeTool;
@@ -1,42 +1,50 @@
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
+ // #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 overflow-x-auto';
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
+ };
28
+
29
+ // Append all tools except preview
30
+ this.options.forEach(tool => {
31
+ if (tool !== 'preview') {
32
+ const ToolClass = toolMapping[tool];
33
+ if (ToolClass) {
34
+ const toolInstance = new ToolClass(this.editor);
35
+ this.toolbar.appendChild(toolInstance.button); // Directly append to toolbar
36
+ }
37
+ }
38
+ });
39
+
40
+ // Append preview button at the end
41
+ if (this.options.includes('preview')) {
42
+ const previewToolInstance = new PreviewTool(this.editor);
43
+ this.toolbar.appendChild(previewToolInstance.button); // Directly append to toolbar at the end
44
+ }
45
+
46
+ this.editor.editorContainer.insertBefore(this.toolbar, this.editor.markdownEditorDiv);
47
+ }
48
+ }
49
+
50
+ export default Toolbar;
@@ -1,15 +1,15 @@
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
-
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');
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,18 +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
-
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
18
  export default CheckListTool;
@@ -1,17 +1,17 @@
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
-
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" 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,20 +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
-
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
20
  export default OLTool;