mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-06-27 05:01:02 -06:00
parent
c311b7b8da
commit
c84af4c3ed
@ -11,11 +11,17 @@
|
|||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
],
|
],
|
||||||
"comma-dangle": ["error", "always-multiline"]
|
"comma-dangle": [
|
||||||
|
"error",
|
||||||
|
"always-multiline"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"node": true
|
"node": true
|
||||||
},
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2018
|
||||||
|
},
|
||||||
"extends": "eslint:recommended"
|
"extends": "eslint:recommended"
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Fixed
|
### Fixed
|
||||||
- URLs with certain characters entered through prompts causing invalid markdown (Thanks to [@Zignature], [#393]).
|
- URLs with certain characters entered through prompts causing invalid markdown (Thanks to [@Zignature], [#393]).
|
||||||
- Autofocus option not working properly ([#399]).
|
- Autofocus option not working properly ([#399]).
|
||||||
|
- Hyperlink doubling (Thanks to [@danielok1993], [#95]).
|
||||||
|
|
||||||
## [2.16.1] - 2022-01-14
|
## [2.16.1] - 2022-01-14
|
||||||
### Fixed
|
### Fixed
|
||||||
@ -297,6 +298,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown
|
|||||||
[#106]: https://github.com/Ionaru/easy-markdown-editor/pull/106
|
[#106]: https://github.com/Ionaru/easy-markdown-editor/pull/106
|
||||||
[#101]: https://github.com/Ionaru/easy-markdown-editor/pull/101
|
[#101]: https://github.com/Ionaru/easy-markdown-editor/pull/101
|
||||||
[#97]: https://github.com/Ionaru/easy-markdown-editor/pull/97
|
[#97]: https://github.com/Ionaru/easy-markdown-editor/pull/97
|
||||||
|
[#97]: https://github.com/Ionaru/easy-markdown-editor/pull/95
|
||||||
[#93]: https://github.com/Ionaru/easy-markdown-editor/pull/93
|
[#93]: https://github.com/Ionaru/easy-markdown-editor/pull/93
|
||||||
[#75]: https://github.com/Ionaru/easy-markdown-editor/pull/75
|
[#75]: https://github.com/Ionaru/easy-markdown-editor/pull/75
|
||||||
[#71]: https://github.com/Ionaru/easy-markdown-editor/pull/71
|
[#71]: https://github.com/Ionaru/easy-markdown-editor/pull/71
|
||||||
@ -353,6 +355,7 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown
|
|||||||
[@Zignature]: https://github.com/Zignature
|
[@Zignature]: https://github.com/Zignature
|
||||||
[@kelvinj]: https://github.com/kelvinj
|
[@kelvinj]: https://github.com/kelvinj
|
||||||
[@diego-gw]: https://github.com/diego-gw
|
[@diego-gw]: https://github.com/diego-gw
|
||||||
|
[@danielok1993]: https://github.com/danielok1993
|
||||||
|
|
||||||
<!-- Linked versions -->
|
<!-- Linked versions -->
|
||||||
[Unreleased]: https://github.com/Ionaru/easy-markdown-editor/compare/2.16.1...HEAD
|
[Unreleased]: https://github.com/Ionaru/easy-markdown-editor/compare/2.16.1...HEAD
|
||||||
|
@ -335,9 +335,9 @@ function getState(cm, pos) {
|
|||||||
ret.strikethrough = true;
|
ret.strikethrough = true;
|
||||||
} else if (data === 'comment') {
|
} else if (data === 'comment') {
|
||||||
ret.code = true;
|
ret.code = true;
|
||||||
} else if (data === 'link') {
|
} else if (data === 'link' && !ret.image) {
|
||||||
ret.link = true;
|
ret.link = true;
|
||||||
} else if (data === 'tag') {
|
} else if (data === 'image') {
|
||||||
ret.image = true;
|
ret.image = true;
|
||||||
} else if (data.match(/^header(-[1-6])?$/)) {
|
} else if (data.match(/^header(-[1-6])?$/)) {
|
||||||
ret[data.replace('header', 'heading')] = true;
|
ret[data.replace('header', 'heading')] = true;
|
||||||
@ -352,6 +352,7 @@ var saved_overflow = '';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle full screen of the editor.
|
* Toggle full screen of the editor.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function toggleFullScreen(editor) {
|
function toggleFullScreen(editor) {
|
||||||
// Set fullscreen
|
// Set fullscreen
|
||||||
@ -412,6 +413,7 @@ function toggleFullScreen(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for toggling bold.
|
* Action for toggling bold.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function toggleBold(editor) {
|
function toggleBold(editor) {
|
||||||
_toggleBlock(editor, 'bold', editor.options.blockStyles.bold);
|
_toggleBlock(editor, 'bold', editor.options.blockStyles.bold);
|
||||||
@ -420,6 +422,7 @@ function toggleBold(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for toggling italic.
|
* Action for toggling italic.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function toggleItalic(editor) {
|
function toggleItalic(editor) {
|
||||||
_toggleBlock(editor, 'italic', editor.options.blockStyles.italic);
|
_toggleBlock(editor, 'italic', editor.options.blockStyles.italic);
|
||||||
@ -428,6 +431,7 @@ function toggleItalic(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for toggling strikethrough.
|
* Action for toggling strikethrough.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function toggleStrikethrough(editor) {
|
function toggleStrikethrough(editor) {
|
||||||
_toggleBlock(editor, 'strikethrough', '~~');
|
_toggleBlock(editor, 'strikethrough', '~~');
|
||||||
@ -435,6 +439,7 @@ function toggleStrikethrough(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for toggling code block.
|
* Action for toggling code block.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function toggleCodeBlock(editor) {
|
function toggleCodeBlock(editor) {
|
||||||
var fenceCharsToInsert = editor.options.blockStyles.code;
|
var fenceCharsToInsert = editor.options.blockStyles.code;
|
||||||
@ -814,43 +819,41 @@ function cleanBlock(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for drawing a link.
|
* Action for drawing a link.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function drawLink(editor) {
|
function drawLink(editor) {
|
||||||
var cm = editor.codemirror;
|
|
||||||
var stat = getState(cm);
|
|
||||||
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);
|
var result = prompt(options.promptTexts.link, url);
|
||||||
if (!url) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
url = escapePromptURL(url);
|
url = escapePromptURL(result);
|
||||||
}
|
}
|
||||||
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
_toggleLink(editor, 'link', options.insertTexts.link, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for drawing an img.
|
* Action for drawing an img.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function drawImage(editor) {
|
function drawImage(editor) {
|
||||||
var cm = editor.codemirror;
|
|
||||||
var stat = getState(cm);
|
|
||||||
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);
|
var result = prompt(options.promptTexts.image, url);
|
||||||
if (!url) {
|
if (!result) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
url = escapePromptURL(url);
|
url = escapePromptURL(result);
|
||||||
}
|
}
|
||||||
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
|
_toggleLink(editor, 'image', options.insertTexts.image, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode and escape URLs to prevent breaking up rendered Markdown links.
|
* Encode and escape URLs to prevent breaking up rendered Markdown links.
|
||||||
* @param url {string} The url of the link or image
|
* @param {string} url The url of the link or image
|
||||||
*/
|
*/
|
||||||
function escapePromptURL(url) {
|
function escapePromptURL(url) {
|
||||||
return encodeURI(url).replace(/([\\()])/g, '\\$1');
|
return encodeURI(url).replace(/([\\()])/g, '\\$1');
|
||||||
@ -858,7 +861,7 @@ function escapePromptURL(url) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for opening the browse-file window to upload an image to a server.
|
* Action for opening the browse-file window to upload an image to a server.
|
||||||
* @param editor {EasyMDE} The EasyMDE object
|
* @param {EasyMDE} editor The EasyMDE object
|
||||||
*/
|
*/
|
||||||
function drawUploadedImage(editor) {
|
function drawUploadedImage(editor) {
|
||||||
// TODO: Draw the image template with a fake url? ie: ''
|
// TODO: Draw the image template with a fake url? ie: ''
|
||||||
@ -867,8 +870,8 @@ function drawUploadedImage(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action executed after an image have been successfully imported on the server.
|
* Action executed after an image have been successfully imported on the server.
|
||||||
* @param editor {EasyMDE} The EasyMDE object
|
* @param {EasyMDE} editor The EasyMDE object
|
||||||
* @param url {string} The url of the uploaded image
|
* @param {string} url The url of the uploaded image
|
||||||
*/
|
*/
|
||||||
function afterImageUploaded(editor, url) {
|
function afterImageUploaded(editor, url) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -895,6 +898,7 @@ function afterImageUploaded(editor, url) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for drawing a table.
|
* Action for drawing a table.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function drawTable(editor) {
|
function drawTable(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -905,6 +909,7 @@ function drawTable(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for drawing a horizontal rule.
|
* Action for drawing a horizontal rule.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function drawHorizontalRule(editor) {
|
function drawHorizontalRule(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -916,6 +921,7 @@ function drawHorizontalRule(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Undo action.
|
* Undo action.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function undo(editor) {
|
function undo(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -926,6 +932,7 @@ function undo(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Redo action.
|
* Redo action.
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function redo(editor) {
|
function redo(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -936,6 +943,7 @@ function redo(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle side by side preview
|
* Toggle side by side preview
|
||||||
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function toggleSideBySide(editor) {
|
function toggleSideBySide(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -1012,7 +1020,7 @@ function toggleSideBySide(editor) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Preview action.
|
* Preview action.
|
||||||
* @param editor {EasyMDE}
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function togglePreview(editor) {
|
function togglePreview(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -1254,12 +1262,61 @@ function _toggleLine(cm, name, liststyle) {
|
|||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EasyMDE} editor
|
||||||
|
* @param {'link' | 'image'} type
|
||||||
|
* @param {string} startEnd
|
||||||
|
* @param {string} url
|
||||||
|
*/
|
||||||
|
function _toggleLink(editor, type, startEnd, url) {
|
||||||
|
if (!editor.codemirror || editor.isPreviewActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cm = editor.codemirror;
|
||||||
|
var stat = getState(cm);
|
||||||
|
var active = stat[type];
|
||||||
|
if (!active) {
|
||||||
|
_replaceSelection(cm, active, startEnd, url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var startPoint = cm.getCursor('start');
|
||||||
|
var endPoint = cm.getCursor('end');
|
||||||
|
var text = cm.getLine(startPoint.line);
|
||||||
|
var start = text.slice(0, startPoint.ch);
|
||||||
|
var end = text.slice(startPoint.ch);
|
||||||
|
|
||||||
|
if (type == 'link') {
|
||||||
|
start = start.replace(/(.*(?<!!))\[/, '$1');
|
||||||
|
} else if (type == 'image') {
|
||||||
|
start = start.replace(/(.*)!\[$/, '$1');
|
||||||
|
}
|
||||||
|
end = end.replace(/]\(.*?\)/, '');
|
||||||
|
|
||||||
|
cm.replaceRange(start + end, {
|
||||||
|
line: startPoint.line,
|
||||||
|
ch: 0,
|
||||||
|
}, {
|
||||||
|
line: startPoint.line,
|
||||||
|
ch: 99999999999999,
|
||||||
|
});
|
||||||
|
|
||||||
|
startPoint.ch -= startEnd[0].length;
|
||||||
|
if (startPoint !== endPoint) {
|
||||||
|
endPoint.ch -= startEnd[0].length;
|
||||||
|
}
|
||||||
|
cm.setSelection(startPoint, endPoint);
|
||||||
|
cm.focus();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {EasyMDE} editor
|
* @param {EasyMDE} editor
|
||||||
*/
|
*/
|
||||||
function _toggleBlock(editor, type, start_chars, end_chars) {
|
function _toggleBlock(editor, type, start_chars, end_chars) {
|
||||||
if (editor.codemirror.getWrapperElement().lastChild.classList.contains('editor-preview-active'))
|
if (!editor.codemirror || editor.isPreviewActive()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars;
|
end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars;
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
@ -1352,7 +1409,7 @@ function _cleanBlock(cm) {
|
|||||||
* Convert a number of bytes to a human-readable file size. If you desire
|
* Convert a number of bytes to a human-readable file size. If you desire
|
||||||
* to add a space between the value and the unit, you need to add this space
|
* to add a space between the value and the unit, you need to add this space
|
||||||
* to the given units.
|
* to the given units.
|
||||||
* @param bytes {integer} A number of bytes, as integer. Ex: 421137
|
* @param bytes {number} A number of bytes, as integer. Ex: 421137
|
||||||
* @param units {number[]} An array of human-readable units, ie. [' B', ' K', ' MB']
|
* @param units {number[]} An array of human-readable units, ie. [' B', ' K', ' MB']
|
||||||
* @returns string A human-readable file size. Ex: '412 KB'
|
* @returns string A human-readable file size. Ex: '412 KB'
|
||||||
*/
|
*/
|
||||||
@ -1604,7 +1661,7 @@ var toolbarBuiltInButtons = {
|
|||||||
|
|
||||||
var insertTexts = {
|
var insertTexts = {
|
||||||
link: ['[', '](#url#)'],
|
link: ['[', '](#url#)'],
|
||||||
image: [''],
|
image: [''],
|
||||||
uploadedImage: ['', ''],
|
uploadedImage: ['', ''],
|
||||||
// uploadedImage: ['\n', ''], // TODO: New line insertion doesn't work here.
|
// uploadedImage: ['\n', ''], // TODO: New line insertion doesn't work here.
|
||||||
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'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user