mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2024-06-01 21:42:28 +02:00
add clean block feature
This commit is contained in:
parent
0ce602f68d
commit
8469cbc839
|
@ -176,6 +176,7 @@ code | toggleCodeBlock | Code (Ctrl+Alt+C)<br>fa fa-code
|
||||||
quote | toggleBlockquote | Quote (Ctrl+')<br>fa fa-quote-left
|
quote | toggleBlockquote | Quote (Ctrl+')<br>fa fa-quote-left
|
||||||
unordered-list | toggleUnorderedList | Generic List (Ctrl+L)<br>fa fa-list-ul
|
unordered-list | toggleUnorderedList | Generic List (Ctrl+L)<br>fa fa-list-ul
|
||||||
ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
|
ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
|
||||||
|
clean-block | cleanBlock | Clean block (Ctrl+E)<br>fa fa-eraser fa-clean-block
|
||||||
link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
|
link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
|
||||||
image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
|
image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
|
||||||
table | drawTable | Insert Table<br>fa fa-table
|
table | drawTable | Insert Table<br>fa fa-table
|
||||||
|
|
|
@ -22,6 +22,7 @@ var shortcuts = {
|
||||||
"Cmd-K": drawLink,
|
"Cmd-K": drawLink,
|
||||||
"Cmd-H": toggleHeadingSmaller,
|
"Cmd-H": toggleHeadingSmaller,
|
||||||
"Shift-Cmd-H": toggleHeadingBigger,
|
"Shift-Cmd-H": toggleHeadingBigger,
|
||||||
|
"Cmd-E": cleanBlock,
|
||||||
"Cmd-Alt-I": drawImage,
|
"Cmd-Alt-I": drawImage,
|
||||||
"Cmd-'": toggleBlockquote,
|
"Cmd-'": toggleBlockquote,
|
||||||
"Cmd-Alt-L": toggleOrderedList,
|
"Cmd-Alt-L": toggleOrderedList,
|
||||||
|
@ -265,6 +266,14 @@ function toggleOrderedList(editor) {
|
||||||
_toggleLine(cm, "ordered-list");
|
_toggleLine(cm, "ordered-list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action for clean block (remove headline, list, blockquote code, markers)
|
||||||
|
*/
|
||||||
|
function cleanBlock(editor) {
|
||||||
|
var cm = editor.codemirror;
|
||||||
|
_cleanBlock(cm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for drawing a link.
|
* Action for drawing a link.
|
||||||
*/
|
*/
|
||||||
|
@ -629,6 +638,28 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
|
||||||
cm.focus();
|
cm.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _cleanBlock(cm) {
|
||||||
|
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var startPoint = cm.getCursor("start");
|
||||||
|
var endPoint = cm.getCursor("end");
|
||||||
|
var text;
|
||||||
|
|
||||||
|
for (var line = startPoint.line; line <= endPoint.line; line++) {
|
||||||
|
text = cm.getLine(line);
|
||||||
|
text = text.replace(/^ *([# ]+|\*|\-|[> ]+|[0-9]+[.]) */, '')
|
||||||
|
|
||||||
|
cm.replaceRange(text, {
|
||||||
|
line: line,
|
||||||
|
ch: 0
|
||||||
|
}, {
|
||||||
|
line: line,
|
||||||
|
ch: 99999999999999
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Merge the properties of one object into another.
|
// Merge the properties of one object into another.
|
||||||
function _mergeProperties(target, source) {
|
function _mergeProperties(target, source) {
|
||||||
for(var property in source) {
|
for(var property in source) {
|
||||||
|
@ -763,6 +794,12 @@ var toolbarBuiltInButtons = {
|
||||||
title: "Numbered List (Ctrl+Alt+L)",
|
title: "Numbered List (Ctrl+Alt+L)",
|
||||||
default: true
|
default: true
|
||||||
},
|
},
|
||||||
|
"clean-block": {
|
||||||
|
name: "clean-block",
|
||||||
|
action: cleanBlock,
|
||||||
|
className: "fa fa-eraser fa-clean-block",
|
||||||
|
title: "Clean block (Ctrl+E)"
|
||||||
|
},
|
||||||
"separator-2": {
|
"separator-2": {
|
||||||
name: "separator-2"
|
name: "separator-2"
|
||||||
},
|
},
|
||||||
|
@ -1339,6 +1376,7 @@ SimpleMDE.toggleHeading3 = toggleHeading3;
|
||||||
SimpleMDE.toggleCodeBlock = toggleCodeBlock;
|
SimpleMDE.toggleCodeBlock = toggleCodeBlock;
|
||||||
SimpleMDE.toggleUnorderedList = toggleUnorderedList;
|
SimpleMDE.toggleUnorderedList = toggleUnorderedList;
|
||||||
SimpleMDE.toggleOrderedList = toggleOrderedList;
|
SimpleMDE.toggleOrderedList = toggleOrderedList;
|
||||||
|
SimpleMDE.cleanBlock = cleanBlock;
|
||||||
SimpleMDE.drawLink = drawLink;
|
SimpleMDE.drawLink = drawLink;
|
||||||
SimpleMDE.drawImage = drawImage;
|
SimpleMDE.drawImage = drawImage;
|
||||||
SimpleMDE.drawTable = drawTable;
|
SimpleMDE.drawTable = drawTable;
|
||||||
|
@ -1388,6 +1426,9 @@ SimpleMDE.prototype.toggleUnorderedList = function() {
|
||||||
SimpleMDE.prototype.toggleOrderedList = function() {
|
SimpleMDE.prototype.toggleOrderedList = function() {
|
||||||
toggleOrderedList(this);
|
toggleOrderedList(this);
|
||||||
};
|
};
|
||||||
|
SimpleMDE.prototype.cleanBlock = function() {
|
||||||
|
cleanBlock(this);
|
||||||
|
};
|
||||||
SimpleMDE.prototype.drawLink = function() {
|
SimpleMDE.prototype.drawLink = function() {
|
||||||
drawLink(this);
|
drawLink(this);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue