2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-07-05 09:04:28 -06:00

Merge branch 'master' into bugfix/simplemde-compatibility

This commit is contained in:
Jeroen Akkerman 2019-03-04 15:43:47 +01:00
commit b14d7dda1c
11 changed files with 463 additions and 521 deletions

View File

@ -9,7 +9,8 @@
"semi": [ "semi": [
"error", "error",
"always" "always"
] ],
"comma-dangle": ["error", "always-multiline"]
}, },
"env": { "env": {
"browser": true, "browser": true,

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# generated files
dist/
# NPM files # NPM files
node_modules/ node_modules/

View File

@ -14,7 +14,7 @@ You can [submit an issue](https://github.com/Ionaru/easy-markdown-editor/issu
### 📦 Prerequisites ### 📦 Prerequisites
You need node.js and npm. You need Node.js and npm.
To install them on Debian-based systems: To install them on Debian-based systems:
@ -37,7 +37,7 @@ git clone https://github.com/Ionaru/easy-markdown-editor.git
cd easy-markdown-editor cd easy-markdown-editor
``` ```
Then install the EasyMDE with npm: Then install the required dependencies:
```bash ```bash
npm install npm install
@ -50,12 +50,12 @@ Yay! You are ready! 🍾
1. First, [create a fork of this project](https://github.com/Ionaru/easy-markdown-editor/fork), and copy the https URL (*clone or download* button) of your project (something like https://github.com/YOUR_USERNAME/easy-markdown-editor.git ); 1. First, [create a fork of this project](https://github.com/Ionaru/easy-markdown-editor/fork), and copy the https URL (*clone or download* button) of your project (something like https://github.com/YOUR_USERNAME/easy-markdown-editor.git );
2. a) If you already cloned and worked on the project: `git remote add source https://github.com/Ionaru/easy-markdown-editor.git`; 2. a) If you already cloned and worked on the project: `git remote add source https://github.com/Ionaru/easy-markdown-editor.git`;
b) otherwise, clone your fork: `git clone https://github.com/YOUR_USERNAME/easy-markdown-editor.git`; b) Otherwise, clone your fork: `git clone https://github.com/YOUR_USERNAME/easy-markdown-editor.git`;
3. create a new dedicated branch `git checkout -b myMergeRequest`; 3. Create a new dedicated branch `git checkout -b myMergeRequest`;
4. write some nice code and commit your work; 4. Write some nice code and commit your work;
5. check files against the ESLint syntax and build minified versions: `gulp`; 5. Check files against the ESLint syntax and build minified versions: `gulp`;
6. push it to a dedicated branch `git push origin myMergeRequest`; 6. Push it to a dedicated branch `git push origin myMergeRequest`;
7. got to the [main project page](https://github.com/Ionaru/easy-markdown-editor) and click on the button *Compare and pull request*, then fill the description. 7. Go to the [main project page](https://github.com/Ionaru/easy-markdown-editor) and click on the button *Compare and pull request*, then fill the description.
If you want to make other pull requests, go back to the master branch (`git checkout master`), update it (`git pull --rebase source master`), then follow the instructions above from step 3. If you want to make other pull requests, go back to the master branch (`git checkout master`), update it (`git pull --rebase source master`), then follow the instructions above from step 3.

View File

@ -2,7 +2,7 @@
[![npm version](https://img.shields.io/npm/v/easymde.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde) [![npm version](https://img.shields.io/npm/v/easymde.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde)
[![npm version](https://img.shields.io/npm/v/easymde/next.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde/v/next) [![npm version](https://img.shields.io/npm/v/easymde/next.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde/v/next)
[![Build Status](https://img.shields.io/travis/Ionaru/easy-markdown-editor.svg?style=for-the-badge)](https://travis-ci.org/Ionaru/easy-markdown-editor) [![Build Status](https://img.shields.io/travis/Ionaru/easy-markdown-editor/master.svg?style=for-the-badge)](https://travis-ci.org/Ionaru/easy-markdown-editor)
> This repository is a fork of > This repository is a fork of
[SimpleMDE, made by Sparksuite](https://github.com/sparksuite/simplemde-markdown-editor/). [SimpleMDE, made by Sparksuite](https://github.com/sparksuite/simplemde-markdown-editor/).
@ -151,7 +151,7 @@ easyMDE.value('New input for **EasyMDE**');
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing). - **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
- **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page or pass in using the `hljs` option. For example, include the script and the CSS files like:<br>`<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>`<br>`<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">` - **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page or pass in using the `hljs` option. For example, include the script and the CSS files like:<br>`<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>`<br>`<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">`
- **hljs**: An injectible instance of [highlight.js](https://github.com/isagalaev/highlight.js). If you don't want to rely on the global namespace (`window.hljs`), you can provide an instance here. Defaults to `undefined`. - **hljs**: An injectible instance of [highlight.js](https://github.com/isagalaev/highlight.js). If you don't want to rely on the global namespace (`window.hljs`), you can provide an instance here. Defaults to `undefined`.
- **markedOptions**: Set the internal Markdown renderer's [options](https://github.com/chjj/marked#options-1). Other `renderingConfig` options will take precedence. - **markedOptions**: Set the internal Markdown renderer's [options](https://marked.js.org/#/USING_ADVANCED.md#options). Other `renderingConfig` options will take precedence.
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`. - **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
- **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts). - **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts).
- **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar. - **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar.

File diff suppressed because one or more lines are too long

7
dist/easymde.min.js vendored

File diff suppressed because one or more lines are too long

757
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,11 @@
"name": "easymde", "name": "easymde",
"version": "2.5.1", "version": "2.5.1",
"description": "A simple, beautiful, and embeddable JavaScript Markdown editor that easy to use. Features include autosaving and spell checking.", "description": "A simple, beautiful, and embeddable JavaScript Markdown editor that easy to use. Features include autosaving and spell checking.",
"files": [
"dist/**/*",
"src/**/*",
"types/easymde.d.ts"
],
"keywords": [ "keywords": [
"embeddable", "embeddable",
"markdown", "markdown",

View File

@ -42,7 +42,7 @@ var bindings = {
'undo': undo, 'undo': undo,
'redo': redo, 'redo': redo,
'toggleSideBySide': toggleSideBySide, 'toggleSideBySide': toggleSideBySide,
'toggleFullScreen': toggleFullScreen 'toggleFullScreen': toggleFullScreen,
}; };
var shortcuts = { var shortcuts = {
@ -59,7 +59,7 @@ var shortcuts = {
'toggleCodeBlock': 'Cmd-Alt-C', 'toggleCodeBlock': 'Cmd-Alt-C',
'togglePreview': 'Cmd-P', 'togglePreview': 'Cmd-P',
'toggleSideBySide': 'F9', 'toggleSideBySide': 'F9',
'toggleFullScreen': 'F11' 'toggleFullScreen': 'F11',
}; };
var getBindingName = function (f) { var getBindingName = function (f) {
@ -338,11 +338,11 @@ function toggleCodeBlock(editor) {
line = line || cm.getLineHandle(line_num); line = line || cm.getLineHandle(line_num);
firstTok = firstTok || cm.getTokenAt({ firstTok = firstTok || cm.getTokenAt({
line: line_num, line: line_num,
ch: 1 ch: 1,
}); });
lastTok = lastTok || (!!line.text && cm.getTokenAt({ lastTok = lastTok || (!!line.text && cm.getTokenAt({
line: line_num, line: line_num,
ch: line.text.length - 1 ch: line.text.length - 1,
})); }));
var types = firstTok.type ? firstTok.type.split(' ') : []; var types = firstTok.type ? firstTok.type.split(' ') : [];
if (lastTok && token_state(lastTok).indentedCode) { if (lastTok && token_state(lastTok).indentedCode) {
@ -375,10 +375,10 @@ function toggleCodeBlock(editor) {
_replaceSelection(cm, false, [repl_start, repl_end]); _replaceSelection(cm, false, [repl_start, repl_end]);
cm.setSelection({ cm.setSelection({
line: start_line_sel, line: start_line_sel,
ch: 0 ch: 0,
}, { }, {
line: end_line_sel, line: end_line_sel,
ch: 0 ch: 0,
}); });
} }
@ -387,7 +387,7 @@ function toggleCodeBlock(editor) {
cur_end = cm.getCursor('end'), cur_end = cm.getCursor('end'),
tok = cm.getTokenAt({ tok = cm.getTokenAt({
line: cur_start.line, line: cur_start.line,
ch: cur_start.ch || 1 ch: cur_start.ch || 1,
}), // avoid ch 0 which is a cursor pos but not token }), // avoid ch 0 which is a cursor pos but not token
line = cm.getLineHandle(cur_start.line), line = cm.getLineHandle(cur_start.line),
is_code = code_type(cm, cur_start.line, line, tok); is_code = code_type(cm, cur_start.line, line, tok);
@ -399,10 +399,10 @@ function toggleCodeBlock(editor) {
end = line.text.slice(cur_start.ch).replace('`', ''); end = line.text.slice(cur_start.ch).replace('`', '');
cm.replaceRange(start + end, { cm.replaceRange(start + end, {
line: cur_start.line, line: cur_start.line,
ch: 0 ch: 0,
}, { }, {
line: cur_start.line, line: cur_start.line,
ch: 99999999999999 ch: 99999999999999,
}); });
cur_start.ch--; cur_start.ch--;
if (cur_start !== cur_end) { if (cur_start !== cur_end) {
@ -423,7 +423,7 @@ function toggleCodeBlock(editor) {
} }
var fencedTok = cm.getTokenAt({ var fencedTok = cm.getTokenAt({
line: block_start, line: block_start,
ch: 1 ch: 1,
}); });
var fence_chars = token_state(fencedTok).fencedChars; var fence_chars = token_state(fencedTok).fencedChars;
var start_text, start_line; var start_text, start_line;
@ -460,25 +460,25 @@ function toggleCodeBlock(editor) {
// end line first, so that line numbers don't change // end line first, so that line numbers don't change
cm.replaceRange(end_text, { cm.replaceRange(end_text, {
line: end_line, line: end_line,
ch: 0 ch: 0,
}, { }, {
line: end_line + (end_text ? 0 : 1), line: end_line + (end_text ? 0 : 1),
ch: 0 ch: 0,
}); });
cm.replaceRange(start_text, { cm.replaceRange(start_text, {
line: start_line, line: start_line,
ch: 0 ch: 0,
}, { }, {
line: start_line + (start_text ? 0 : 1), line: start_line + (start_text ? 0 : 1),
ch: 0 ch: 0,
}); });
}); });
cm.setSelection({ cm.setSelection({
line: start_line + (start_text ? 1 : 0), line: start_line + (start_text ? 1 : 0),
ch: 0 ch: 0,
}, { }, {
line: end_line + (start_text ? 1 : -1), line: end_line + (start_text ? 1 : -1),
ch: 0 ch: 0,
}); });
cm.focus(); cm.focus();
} else { } else {
@ -513,17 +513,17 @@ function toggleCodeBlock(editor) {
cm.operation(function () { cm.operation(function () {
cm.replaceRange('', { cm.replaceRange('', {
line: block_start, line: block_start,
ch: 0 ch: 0,
}, { }, {
line: block_start + 1, line: block_start + 1,
ch: 0 ch: 0,
}); });
cm.replaceRange('', { cm.replaceRange('', {
line: block_end - 1, line: block_end - 1,
ch: 0 ch: 0,
}, { }, {
line: block_end, line: block_end,
ch: 0 ch: 0,
}); });
}); });
cm.focus(); cm.focus();
@ -569,13 +569,13 @@ function toggleCodeBlock(editor) {
var next_line = cm.getLineHandle(block_end + 1), var next_line = cm.getLineHandle(block_end + 1),
next_line_last_tok = next_line && cm.getTokenAt({ next_line_last_tok = next_line && cm.getTokenAt({
line: block_end + 1, line: block_end + 1,
ch: next_line.text.length - 1 ch: next_line.text.length - 1,
}), }),
next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode; next_line_indented = next_line_last_tok && token_state(next_line_last_tok).indentedCode;
if (next_line_indented) { if (next_line_indented) {
cm.replaceRange('\n', { cm.replaceRange('\n', {
line: block_end + 1, line: block_end + 1,
ch: 0 ch: 0,
}); });
} }
@ -678,7 +678,7 @@ function drawLink(editor) {
var options = editor.options; var options = editor.options;
var url = 'https://'; var url = 'https://';
if (options.promptURLs) { if (options.promptURLs) {
url = prompt(options.promptTexts.link); url = prompt(options.promptTexts.link, 'https://');
if (!url) { if (!url) {
return false; return false;
} }
@ -695,7 +695,7 @@ function drawImage(editor) {
var options = editor.options; var options = editor.options;
var url = 'https://'; var url = 'https://';
if (options.promptURLs) { if (options.promptURLs) {
url = prompt(options.promptTexts.image); url = prompt(options.promptTexts.image, 'https://');
if (!url) { if (!url) {
return false; return false;
} }
@ -867,7 +867,7 @@ function _replaceSelection(cm, active, startEnd, url) {
end = text.slice(startPoint.ch); end = text.slice(startPoint.ch);
cm.replaceRange(start + end, { cm.replaceRange(start + end, {
line: startPoint.line, line: startPoint.line,
ch: 0 ch: 0,
}); });
} else { } else {
text = cm.getSelection(); text = cm.getSelection();
@ -942,10 +942,10 @@ function _toggleHeading(cm, direction, size) {
cm.replaceRange(text, { cm.replaceRange(text, {
line: i, line: i,
ch: 0 ch: 0,
}, { }, {
line: i, line: i,
ch: 99999999999999 ch: 99999999999999,
}); });
})(i); })(i);
} }
@ -966,14 +966,14 @@ function _toggleLine(cm, name) {
var repl = { var repl = {
'quote': /^(\s*)>\s+/, 'quote': /^(\s*)>\s+/,
'unordered-list': listRegexp, 'unordered-list': listRegexp,
'ordered-list': listRegexp 'ordered-list': listRegexp,
}; };
var _getChar = function (name, i) { var _getChar = function (name, i) {
var map = { var map = {
'quote': '>', 'quote': '>',
'unordered-list': '*', 'unordered-list': '*',
'ordered-list': '%%i.' 'ordered-list': '%%i.',
}; };
return map[name].replace('%%i', i); return map[name].replace('%%i', i);
@ -983,7 +983,7 @@ function _toggleLine(cm, name) {
var map = { var map = {
'quote': '>', 'quote': '>',
'unordered-list': '*', 'unordered-list': '*',
'ordered-list': 'd+.' 'ordered-list': 'd+.',
}; };
var rt = new RegExp(map[name]); var rt = new RegExp(map[name]);
@ -1011,10 +1011,10 @@ function _toggleLine(cm, name) {
} }
cm.replaceRange(text, { cm.replaceRange(text, {
line: i, line: i,
ch: 0 ch: 0,
}, { }, {
line: i, line: i,
ch: 99999999999999 ch: 99999999999999,
}); });
})(i); })(i);
} }
@ -1052,10 +1052,10 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
} }
cm.replaceRange(start + end, { cm.replaceRange(start + end, {
line: startPoint.line, line: startPoint.line,
ch: 0 ch: 0,
}, { }, {
line: startPoint.line, line: startPoint.line,
ch: 99999999999999 ch: 99999999999999,
}); });
if (type == 'bold' || type == 'strikethrough') { if (type == 'bold' || type == 'strikethrough') {
@ -1104,10 +1104,10 @@ function _cleanBlock(cm) {
cm.replaceRange(text, { cm.replaceRange(text, {
line: line, line: line,
ch: 0 ch: 0,
}, { }, {
line: line, line: line,
ch: 99999999999999 ch: 99999999999999,
}); });
} }
} }
@ -1144,7 +1144,7 @@ function extend(target) {
/* The right word count in respect for CJK. */ /* The right word count in respect for CJK. */
function wordCount(data) { function wordCount(data) {
var pattern = /[a-zA-Z0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g; var pattern = /[a-zA-Z0-9_\u00A0-\u02AF\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
var m = data.match(pattern); var m = data.match(pattern);
var count = 0; var count = 0;
if (m === null) return count; if (m === null) return count;
@ -1164,125 +1164,125 @@ var toolbarBuiltInButtons = {
action: toggleBold, action: toggleBold,
className: 'fa fa-bold', className: 'fa fa-bold',
title: 'Bold', title: 'Bold',
default: true default: true,
}, },
'italic': { 'italic': {
name: 'italic', name: 'italic',
action: toggleItalic, action: toggleItalic,
className: 'fa fa-italic', className: 'fa fa-italic',
title: 'Italic', title: 'Italic',
default: true default: true,
}, },
'strikethrough': { 'strikethrough': {
name: 'strikethrough', name: 'strikethrough',
action: toggleStrikethrough, action: toggleStrikethrough,
className: 'fa fa-strikethrough', className: 'fa fa-strikethrough',
title: 'Strikethrough' title: 'Strikethrough',
}, },
'heading': { 'heading': {
name: 'heading', name: 'heading',
action: toggleHeadingSmaller, action: toggleHeadingSmaller,
className: 'fa fa-header fa-heading', className: 'fa fa-header fa-heading',
title: 'Heading', title: 'Heading',
default: true default: true,
}, },
'heading-smaller': { 'heading-smaller': {
name: 'heading-smaller', name: 'heading-smaller',
action: toggleHeadingSmaller, action: toggleHeadingSmaller,
className: 'fa fa-header fa-heading header-smaller', className: 'fa fa-header fa-heading header-smaller',
title: 'Smaller Heading' title: 'Smaller Heading',
}, },
'heading-bigger': { 'heading-bigger': {
name: 'heading-bigger', name: 'heading-bigger',
action: toggleHeadingBigger, action: toggleHeadingBigger,
className: 'fa fa-header fa-heading header-bigger', className: 'fa fa-header fa-heading header-bigger',
title: 'Bigger Heading' title: 'Bigger Heading',
}, },
'heading-1': { 'heading-1': {
name: 'heading-1', name: 'heading-1',
action: toggleHeading1, action: toggleHeading1,
className: 'fa fa-header fa-heading header-1', className: 'fa fa-header fa-heading header-1',
title: 'Big Heading' title: 'Big Heading',
}, },
'heading-2': { 'heading-2': {
name: 'heading-2', name: 'heading-2',
action: toggleHeading2, action: toggleHeading2,
className: 'fa fa-header fa-heading header-2', className: 'fa fa-header fa-heading header-2',
title: 'Medium Heading' title: 'Medium Heading',
}, },
'heading-3': { 'heading-3': {
name: 'heading-3', name: 'heading-3',
action: toggleHeading3, action: toggleHeading3,
className: 'fa fa-header fa-heading header-3', className: 'fa fa-header fa-heading header-3',
title: 'Small Heading' title: 'Small Heading',
}, },
'separator-1': { 'separator-1': {
name: 'separator-1' name: 'separator-1',
}, },
'code': { 'code': {
name: 'code', name: 'code',
action: toggleCodeBlock, action: toggleCodeBlock,
className: 'fa fa-code', className: 'fa fa-code',
title: 'Code' title: 'Code',
}, },
'quote': { 'quote': {
name: 'quote', name: 'quote',
action: toggleBlockquote, action: toggleBlockquote,
className: 'fa fa-quote-left', className: 'fa fa-quote-left',
title: 'Quote', title: 'Quote',
default: true default: true,
}, },
'unordered-list': { 'unordered-list': {
name: 'unordered-list', name: 'unordered-list',
action: toggleUnorderedList, action: toggleUnorderedList,
className: 'fa fa-list-ul', className: 'fa fa-list-ul',
title: 'Generic List', title: 'Generic List',
default: true default: true,
}, },
'ordered-list': { 'ordered-list': {
name: 'ordered-list', name: 'ordered-list',
action: toggleOrderedList, action: toggleOrderedList,
className: 'fa fa-list-ol', className: 'fa fa-list-ol',
title: 'Numbered List', title: 'Numbered List',
default: true default: true,
}, },
'clean-block': { 'clean-block': {
name: 'clean-block', name: 'clean-block',
action: cleanBlock, action: cleanBlock,
className: 'fa fa-eraser', className: 'fa fa-eraser',
title: 'Clean block' title: 'Clean block',
}, },
'separator-2': { 'separator-2': {
name: 'separator-2' name: 'separator-2',
}, },
'link': { 'link': {
name: 'link', name: 'link',
action: drawLink, action: drawLink,
className: 'fa fa-link', className: 'fa fa-link',
title: 'Create Link', title: 'Create Link',
default: true default: true,
}, },
'image': { 'image': {
name: 'image', name: 'image',
action: drawImage, action: drawImage,
className: 'fa fa-image', className: 'fa fa-image',
title: 'Insert Image', title: 'Insert Image',
default: true default: true,
}, },
'table': { 'table': {
name: 'table', name: 'table',
action: drawTable, action: drawTable,
className: 'fa fa-table', className: 'fa fa-table',
title: 'Insert Table' title: 'Insert Table',
}, },
'horizontal-rule': { 'horizontal-rule': {
name: 'horizontal-rule', name: 'horizontal-rule',
action: drawHorizontalRule, action: drawHorizontalRule,
className: 'fa fa-minus', className: 'fa fa-minus',
title: 'Insert Horizontal Line' title: 'Insert Horizontal Line',
}, },
'separator-3': { 'separator-3': {
name: 'separator-3' name: 'separator-3',
}, },
'preview': { 'preview': {
name: 'preview', name: 'preview',
@ -1290,7 +1290,7 @@ var toolbarBuiltInButtons = {
className: 'fa fa-eye', className: 'fa fa-eye',
noDisable: true, noDisable: true,
title: 'Toggle Preview', title: 'Toggle Preview',
default: true default: true,
}, },
'side-by-side': { 'side-by-side': {
name: 'side-by-side', name: 'side-by-side',
@ -1299,7 +1299,7 @@ var toolbarBuiltInButtons = {
noDisable: true, noDisable: true,
noMobile: true, noMobile: true,
title: 'Toggle Side by Side', title: 'Toggle Side by Side',
default: true default: true,
}, },
'fullscreen': { 'fullscreen': {
name: 'fullscreen', name: 'fullscreen',
@ -1308,54 +1308,54 @@ var toolbarBuiltInButtons = {
noDisable: true, noDisable: true,
noMobile: true, noMobile: true,
title: 'Toggle Fullscreen', title: 'Toggle Fullscreen',
default: true default: true,
}, },
'separator-4': { 'separator-4': {
name: 'separator-4' name: 'separator-4',
}, },
'guide': { 'guide': {
name: 'guide', name: 'guide',
action: 'https://simplemde.com/markdown-guide', action: 'https://www.markdownguide.org/basic-syntax/',
className: 'fa fa-question-circle', className: 'fa fa-question-circle',
noDisable: true, noDisable: true,
title: 'Markdown Guide', title: 'Markdown Guide',
default: true default: true,
}, },
'separator-5': { 'separator-5': {
name: 'separator-5' name: 'separator-5',
}, },
'undo': { 'undo': {
name: 'undo', name: 'undo',
action: undo, action: undo,
className: 'fa fa-undo', className: 'fa fa-undo',
noDisable: true, noDisable: true,
title: 'Undo' title: 'Undo',
}, },
'redo': { 'redo': {
name: 'redo', name: 'redo',
action: redo, action: redo,
className: 'fa fa-repeat fa-redo', className: 'fa fa-repeat fa-redo',
noDisable: true, noDisable: true,
title: 'Redo' title: 'Redo',
} },
}; };
var insertTexts = { var insertTexts = {
link: ['[', '](#url#)'], link: ['[', '](#url#)'],
image: ['![](', '#url#)'], image: ['![](', '#url#)'],
table: ['', '\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n'], table: ['', '\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n'],
horizontalRule: ['', '\n\n-----\n\n'] horizontalRule: ['', '\n\n-----\n\n'],
}; };
var promptTexts = { var promptTexts = {
link: 'URL for the link:', link: 'URL for the link:',
image: 'URL of the image:' image: 'URL of the image:',
}; };
var blockStyles = { var blockStyles = {
'bold': '**', 'bold': '**',
'code': '```', 'code': '```',
'italic': '*' 'italic': '*',
}; };
/** /**
@ -1443,7 +1443,7 @@ function EasyMDE(options) {
// Set default options for parsing config // Set default options for parsing config
options.parsingConfig = extend({ options.parsingConfig = extend({
highlightFormatting: true // needed for toggleCodeBlock to detect types of code highlightFormatting: true, // needed for toggleCodeBlock to detect types of code
}, options.parsingConfig || {}); }, options.parsingConfig || {});
@ -1585,7 +1585,7 @@ EasyMDE.prototype.render = function (el) {
backdrop.gitHubSpice = false; backdrop.gitHubSpice = false;
CodeMirrorSpellChecker({ CodeMirrorSpellChecker({
codeMirrorInstance: CodeMirror codeMirrorInstance: CodeMirror,
}); });
} else { } else {
mode = options.parsingConfig; mode = options.parsingConfig;
@ -1596,7 +1596,7 @@ EasyMDE.prototype.render = function (el) {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function configureMouse(cm, repeat, event) { function configureMouse(cm, repeat, event) {
return { return {
addNew: false addNew: false,
}; };
} }
@ -1614,7 +1614,7 @@ EasyMDE.prototype.render = function (el) {
allowDropFileTypes: ['text/plain'], allowDropFileTypes: ['text/plain'],
placeholder: options.placeholder || el.getAttribute('placeholder') || '', placeholder: options.placeholder || el.getAttribute('placeholder') || '',
styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : !isMobile(), styleSelectedText: (options.styleSelectedText != undefined) ? options.styleSelectedText : !isMobile(),
configureMouse: configureMouse configureMouse: configureMouse,
}); });
this.codemirror.getScrollerElement().style.minHeight = options.minHeight; this.codemirror.getScrollerElement().style.minHeight = options.minHeight;
@ -1914,7 +1914,7 @@ EasyMDE.prototype.createStatusbar = function (status) {
items.push({ items.push({
className: status[i].className, className: status[i].className,
defaultValue: status[i].defaultValue, defaultValue: status[i].defaultValue,
onUpdate: status[i].onUpdate onUpdate: status[i].onUpdate,
}); });
} else { } else {
var name = status[i]; var name = status[i];
@ -1952,7 +1952,7 @@ EasyMDE.prototype.createStatusbar = function (status) {
items.push({ items.push({
className: name, className: name,
defaultValue: defaultValue, defaultValue: defaultValue,
onUpdate: onUpdate onUpdate: onUpdate,
}); });
} }
} }

View File

@ -1,14 +1,16 @@
// Create new instance // Create new instance
const editor = new EasyMDE({ const editor = new EasyMDE({
autoDownloadFontAwesome: false, autoDownloadFontAwesome: false,
element: document.getElementById("mdEditor")!, element: document.getElementById('mdEditor')!,
hideIcons: ["side-by-side", "fullscreen"], hideIcons: ['side-by-side', 'fullscreen'],
shortcuts: { shortcuts: {
drawTable: "Cmd-Alt-T", drawTable: 'Cmd-Alt-T',
toggleFullScreen: null toggleFullScreen: null
}, },
spellChecker: false, spellChecker: false,
onToggleFullScreen: (full: boolean) => { console.log('FullscreenToggled', full); }, onToggleFullScreen: (full: boolean) => {
console.log('FullscreenToggled', full);
},
theme: 'someOtherTheme', theme: 'someOtherTheme',
}); });
@ -23,4 +25,6 @@ const fullscreen = editor.isFullscreenActive() as boolean;
editor.codemirror.setOption('readOnly', true); editor.codemirror.setOption('readOnly', true);
// Static properties // Static properties
EasyMDE.toggleItalic = (editor: EasyMDE) => { console.log('SomeButtonOverride'); }; EasyMDE.toggleItalic = (editor: EasyMDE) => {
console.log('SomeButtonOverride');
};

14
types/easymde.d.ts vendored
View File

@ -54,6 +54,7 @@ declare namespace EasyMDE {
interface Shortcuts { interface Shortcuts {
[action: string]: string | undefined | null; [action: string]: string | undefined | null;
toggleBlockquote?: string | null; toggleBlockquote?: string | null;
toggleBold?: string | null; toggleBold?: string | null;
cleanBlock?: string | null; cleanBlock?: string | null;
@ -78,7 +79,7 @@ declare namespace EasyMDE {
interface ToolbarIcon { interface ToolbarIcon {
name: string; name: string;
action: string|((editor: EasyMDE) => void); action: string | ((editor: EasyMDE) => void);
className: string; className: string;
title: string; title: string;
noDisable?: boolean; noDisable?: boolean;
@ -105,10 +106,10 @@ declare namespace EasyMDE {
shortcuts?: Shortcuts; shortcuts?: Shortcuts;
showIcons?: ReadonlyArray<string>; showIcons?: ReadonlyArray<string>;
spellChecker?: boolean; spellChecker?: boolean;
status?: boolean|ReadonlyArray<string|StatusBarItem>; status?: boolean | ReadonlyArray<string | StatusBarItem>;
styleSelectedText?: boolean; styleSelectedText?: boolean;
tabSize?: number; tabSize?: number;
toolbar?: boolean|ReadonlyArray<string|ToolbarIcon>; toolbar?: boolean | ReadonlyArray<string | ToolbarIcon>;
toolbarTips?: boolean; toolbarTips?: boolean;
onToggleFullScreen?: (goingIntoFullScreen: boolean) => void; onToggleFullScreen?: (goingIntoFullScreen: boolean) => void;
theme?: string; theme?: string;
@ -117,13 +118,20 @@ declare namespace EasyMDE {
declare class EasyMDE { declare class EasyMDE {
constructor(options?: EasyMDE.Options); constructor(options?: EasyMDE.Options);
value(): string; value(): string;
value(val: string): void; value(val: string): void;
codemirror: CodeMirror.Editor; codemirror: CodeMirror.Editor;
toTextArea(): void; toTextArea(): void;
isPreviewActive(): boolean; isPreviewActive(): boolean;
isSideBySideActive(): boolean; isSideBySideActive(): boolean;
isFullscreenActive(): boolean; isFullscreenActive(): boolean;
clearAutosavedValue(): void; clearAutosavedValue(): void;
static toggleBold: (editor: EasyMDE) => void; static toggleBold: (editor: EasyMDE) => void;