mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09: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', {
|
ts.addRule('mark', {
|
||||||
filter: 'mark',
|
filter: 'mark',
|
||||||
replacement: function(content, node, options) {
|
replacement: function(content, node, options) {
|
||||||
|
if (!content) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return '<mark>' + content + '</mark>';
|
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);
|
var markdown = ts.turndown(html);
|
||||||
content.htmlToTextCB(identifier, id, timeStamp, markdown);
|
content.htmlToTextCB(identifier, id, timeStamp, markdown);
|
||||||
};
|
};
|
||||||
|
@ -72,7 +72,7 @@ var previewMathJax = function(identifier, id, timeStamp, text, isHtml) {
|
|||||||
p,
|
p,
|
||||||
[postProcessMathJax, identifier, id, timeStamp, p, isBlock]]);
|
[postProcessMathJax, identifier, id, timeStamp, p, isBlock]]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("err: " + err);
|
content.setLog("err: " + err);
|
||||||
content.mathjaxResultReady(identifier, id, timeStamp, 'png', '');
|
content.mathjaxResultReady(identifier, id, timeStamp, 'png', '');
|
||||||
contentDiv.removeChild(p);
|
contentDiv.removeChild(p);
|
||||||
delete p;
|
delete p;
|
||||||
@ -94,7 +94,7 @@ var postProcessMathJax = function(identifier, id, timeStamp, container, isBlock)
|
|||||||
contentDiv.removeChild(container);
|
contentDiv.removeChild(container);
|
||||||
delete container;
|
delete container;
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
console.log("err: " + err);
|
content.setLog("err: " + err);
|
||||||
content.mathjaxResultReady(identifier, id, timeStamp, 'png', '');
|
content.mathjaxResultReady(identifier, id, timeStamp, 'png', '');
|
||||||
contentDiv.removeChild(container);
|
contentDiv.removeChild(container);
|
||||||
delete container;
|
delete container;
|
||||||
@ -132,7 +132,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
|||||||
try {
|
try {
|
||||||
var graph = flowchart.parse(text);
|
var graph = flowchart.parse(text);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("err: " + err);
|
content.setLog("err: " + err);
|
||||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
|||||||
try {
|
try {
|
||||||
graph.drawSVG(div.id);
|
graph.drawSVG(div.id);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("err: " + err);
|
content.setLog("err: " + err);
|
||||||
contentDiv.removeChild(div);
|
contentDiv.removeChild(div);
|
||||||
delete div;
|
delete div;
|
||||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||||
@ -167,7 +167,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
|||||||
text,
|
text,
|
||||||
function(){});
|
function(){});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("err: " + err);
|
content.setLog("err: " + err);
|
||||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ var previewDiagram = function(identifier, id, timeStamp, lang, text) {
|
|||||||
contentDiv.removeChild(div);
|
contentDiv.removeChild(div);
|
||||||
delete div;
|
delete div;
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
console.log("err: " + err);
|
content.setLog("err: " + err);
|
||||||
contentDiv.removeChild(div);
|
contentDiv.removeChild(div);
|
||||||
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
content.diagramResultReady(identifier, id, timeStamp, 'png', '');
|
||||||
delete div;
|
delete div;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user