mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
MdEditor: fix turndown to parse HTML
This commit is contained in:
parent
7c7b9e8a3d
commit
28d5954bc3
@ -1546,6 +1546,10 @@ var htmlToText = function(identifier, id, timeStamp, html) {
|
||||
ts.addRule('mark', {
|
||||
filter: 'mark',
|
||||
replacement: function(content, node, options) {
|
||||
if (!content) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return '<mark>' + content + '</mark>';
|
||||
}
|
||||
});
|
||||
@ -1576,6 +1580,44 @@ var htmlToText = function(identifier, id, timeStamp, html) {
|
||||
}
|
||||
});
|
||||
|
||||
ts.remove(['head', 'style']);
|
||||
|
||||
var subEnabled = false, supEnabled = false;
|
||||
if (typeof VMarkdownitOption != "undefined") {
|
||||
subEnabled = VMarkdownitOption.sub;
|
||||
supEnabled = VMarkdownitOption.sup;
|
||||
}
|
||||
|
||||
ts.addRule('sub_fix', {
|
||||
filter: 'sub',
|
||||
replacement: function (content, node, options) {
|
||||
if (!content) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (subEnabled) {
|
||||
return '~' + content + '~';
|
||||
} else {
|
||||
return '<sub>' + content + '</sub>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ts.addRule('sup_fix', {
|
||||
filter: 'sup',
|
||||
replacement: function (content, node, options) {
|
||||
if (!content) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (supEnabled) {
|
||||
return '^' + content + '^';
|
||||
} else {
|
||||
return '<sup>' + content + '</sup>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var markdown = ts.turndown(html);
|
||||
content.htmlToTextCB(identifier, id, timeStamp, markdown);
|
||||
};
|
||||
|
@ -72,7 +72,7 @@ var previewMathJax = function(identifier, id, timeStamp, text, isHtml) {
|
||||
p,
|
||||
[postProcessMathJax, identifier, id, timeStamp, p, isBlock]]);
|
||||
} catch (err) {
|
||||
console.log("err: " + err);
|
||||
content.setLog("err: " + err);
|
||||
content.mathjaxResultReady(identifier, id, timeStamp, 'png', '');
|
||||
contentDiv.removeChild(p);
|
||||
delete p;
|
||||
@ -94,7 +94,7 @@ var postProcessMathJax = function(identifier, id, timeStamp, container, isBlock)
|
||||
contentDiv.removeChild(container);
|
||||
delete container;
|
||||
}).catch(function (err) {
|
||||
console.log("err: " + err);
|
||||
content.setLog("err: " + err);
|
||||
content.mathjaxResultReady(identifier, id, timeStamp, 'png', '');
|
||||
contentDiv.removeChild(container);
|
||||
delete container;
|
||||
@ -132,7 +132,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
||||
try {
|
||||
var graph = flowchart.parse(text);
|
||||
} catch (err) {
|
||||
console.log("err: " + err);
|
||||
content.setLog("err: " + err);
|
||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||
return;
|
||||
}
|
||||
@ -152,7 +152,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
||||
try {
|
||||
graph.drawSVG(div.id);
|
||||
} catch (err) {
|
||||
console.log("err: " + err);
|
||||
content.setLog("err: " + err);
|
||||
contentDiv.removeChild(div);
|
||||
delete div;
|
||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||
@ -167,7 +167,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
||||
text,
|
||||
function(){});
|
||||
} catch (err) {
|
||||
console.log("err: " + err);
|
||||
content.setLog("err: " + err);
|
||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||
return;
|
||||
}
|
||||
@ -197,7 +197,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
||||
contentDiv.removeChild(div);
|
||||
delete div;
|
||||
}).catch(function (err) {
|
||||
console.log("err: " + err);
|
||||
content.setLog("err: " + err);
|
||||
contentDiv.removeChild(div);
|
||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||
delete div;
|
||||
|
Loading…
x
Reference in New Issue
Block a user