mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-09-24 16:40:55 -06:00
reverting commit in order to create a new branch for this fix.
This commit is contained in:
parent
06e7bc5a6d
commit
40d02812b1
@ -999,35 +999,25 @@ function _toggleBlock(editor, type, start_chars, end_chars) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _cleanBlock(cm) {
|
function _cleanBlock(cm) {
|
||||||
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) {
|
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
|
||||||
return;
|
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// split the selection in lines
|
|
||||||
var selections = cm.getSelection().split("\n");
|
|
||||||
var removeTags = function(selection) {
|
|
||||||
var html = marked(selection);
|
|
||||||
// create a div...
|
|
||||||
var tmp = document.createElement("DIV");
|
|
||||||
// .. with the new generated html code...
|
|
||||||
tmp.innerHTML = html;
|
|
||||||
// ... now read the text of the generated code.
|
|
||||||
// This way the browser does the job of removing the tags.
|
|
||||||
var result = selection;
|
|
||||||
if(tmp.textContent) {
|
|
||||||
result = tmp.textContent;
|
|
||||||
} else if(tmp.innerText) {
|
|
||||||
result = tmp.innerText;
|
|
||||||
}
|
|
||||||
// removing trailing "new line"
|
|
||||||
return result.split("\n").join("");
|
|
||||||
};
|
|
||||||
var result = [];
|
|
||||||
for(var i = 0; i < selections.length; i++) {
|
|
||||||
result.push(removeTags(selections[i]));
|
|
||||||
}
|
|
||||||
// Add removed "new lines" back to the resulting string.
|
|
||||||
// Replace the selection with the new clean selection.
|
|
||||||
cm.replaceSelection(result.join("\n"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge the properties of one object into another.
|
// Merge the properties of one object into another.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user