mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
flowchart: support both flow and flowchart as the language
This commit is contained in:
parent
dfbb692b15
commit
de7ea32104
@ -32,7 +32,9 @@ var updateHtml = function(html) {
|
|||||||
--i;
|
--i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (VEnableFlowchart && code.classList.contains('language-flowchart')) {
|
} else if (VEnableFlowchart
|
||||||
|
&& (code.classList.contains('language-flowchart')
|
||||||
|
|| code.classList.contains('language-flow'))) {
|
||||||
// Flowchart code block.
|
// Flowchart code block.
|
||||||
if (renderFlowchartOne(code)) {
|
if (renderFlowchartOne(code)) {
|
||||||
// replaceChild() will decrease codes.length.
|
// replaceChild() will decrease codes.length.
|
||||||
|
@ -44,10 +44,7 @@ var mdit = window.markdownit({
|
|||||||
typographer: true,
|
typographer: true,
|
||||||
langPrefix: 'lang-',
|
langPrefix: 'lang-',
|
||||||
highlight: function(str, lang) {
|
highlight: function(str, lang) {
|
||||||
if (lang
|
if (lang && !specialCodeBlock(lang)) {
|
||||||
&& (!VEnableMathjax || lang != 'mathjax')
|
|
||||||
&& (!VEnableMermaid || lang != 'mermaid')
|
|
||||||
&& (!VEnableFlowchart || lang != 'flowchart')) {
|
|
||||||
if (hljs.getLanguage(lang)) {
|
if (hljs.getLanguage(lang)) {
|
||||||
return hljs.highlight(lang, str, true).value;
|
return hljs.highlight(lang, str, true).value;
|
||||||
} else {
|
} else {
|
||||||
@ -110,7 +107,7 @@ var updateText = function(text) {
|
|||||||
handleToc(needToc);
|
handleToc(needToc);
|
||||||
insertImageCaption();
|
insertImageCaption();
|
||||||
renderMermaid('lang-mermaid');
|
renderMermaid('lang-mermaid');
|
||||||
renderFlowchart('lang-flowchart');
|
renderFlowchart(['lang-flowchart', 'lang-flow']);
|
||||||
addClassToCodeBlock();
|
addClassToCodeBlock();
|
||||||
renderCodeBlockLineNumber();
|
renderCodeBlockLineNumber();
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ var renderMermaidOne = function(code) {
|
|||||||
var flowchartIdx = 0;
|
var flowchartIdx = 0;
|
||||||
|
|
||||||
// @className, the class name of the flowchart code block, such as 'lang-flowchart'.
|
// @className, the class name of the flowchart code block, such as 'lang-flowchart'.
|
||||||
var renderFlowchart = function(className) {
|
var renderFlowchart = function(classNames) {
|
||||||
if (!VEnableFlowchart) {
|
if (!VEnableFlowchart) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -552,7 +552,15 @@ var renderFlowchart = function(className) {
|
|||||||
flowchartIdx = 0;
|
flowchartIdx = 0;
|
||||||
for (var i = 0; i < codes.length; ++i) {
|
for (var i = 0; i < codes.length; ++i) {
|
||||||
var code = codes[i];
|
var code = codes[i];
|
||||||
if (code.classList.contains(className)) {
|
var matched = false;
|
||||||
|
for (var j = 0; j < classNames.length; ++j) {
|
||||||
|
if (code.classList.contains(classNames[j])) {
|
||||||
|
matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matched) {
|
||||||
if (renderFlowchartOne(code, flowchartIdx)) {
|
if (renderFlowchartOne(code, flowchartIdx)) {
|
||||||
// replaceChild() will decrease codes.length.
|
// replaceChild() will decrease codes.length.
|
||||||
--i;
|
--i;
|
||||||
@ -1157,3 +1165,10 @@ var calculateWordCount = function() {
|
|||||||
|
|
||||||
content.updateWordCountInfo(wc, cns, cc);
|
content.updateWordCountInfo(wc, cns, cc);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Whether it is a special code block, such as MathJax, Mermaid, or Flowchart.
|
||||||
|
var specialCodeBlock = function(lang) {
|
||||||
|
return (VEnableMathjax && lang == 'mathjax')
|
||||||
|
|| (VEnableMermaid && lang == 'mermaid')
|
||||||
|
|| (VEnableFlowchart && (lang == 'flowchart' || lang == 'flow'));
|
||||||
|
};
|
||||||
|
@ -17,10 +17,7 @@ renderer.heading = function(text, level) {
|
|||||||
// Highlight.js to highlight code block
|
// Highlight.js to highlight code block
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
highlight: function(code, lang) {
|
highlight: function(code, lang) {
|
||||||
if (lang
|
if (lang && !specialCodeBlock(lang)) {
|
||||||
&& (!VEnableMathjax || lang != 'mathjax')
|
|
||||||
&& (!VEnableMermaid || lang != 'mermaid')
|
|
||||||
&& (!VEnableFlowchart || lang != 'flowchart')) {
|
|
||||||
if (hljs.getLanguage(lang)) {
|
if (hljs.getLanguage(lang)) {
|
||||||
return hljs.highlight(lang, code, true).value;
|
return hljs.highlight(lang, code, true).value;
|
||||||
} else {
|
} else {
|
||||||
@ -59,7 +56,7 @@ var updateText = function(text) {
|
|||||||
handleToc(needToc);
|
handleToc(needToc);
|
||||||
insertImageCaption();
|
insertImageCaption();
|
||||||
renderMermaid('lang-mermaid');
|
renderMermaid('lang-mermaid');
|
||||||
renderFlowchart('lang-flowchart');
|
renderFlowchart(['lang-flowchart', 'lang-flow']);
|
||||||
addClassToCodeBlock();
|
addClassToCodeBlock();
|
||||||
renderCodeBlockLineNumber();
|
renderCodeBlockLineNumber();
|
||||||
|
|
||||||
|
@ -57,7 +57,9 @@ var highlightCodeBlocks = function(doc, enableMermaid, enableFlowchart, enableMa
|
|||||||
if (enableMermaid && code.classList.contains('language-mermaid')) {
|
if (enableMermaid && code.classList.contains('language-mermaid')) {
|
||||||
// Mermaid code block.
|
// Mermaid code block.
|
||||||
continue;
|
continue;
|
||||||
} else if (enableFlowchart && code.classList.contains('language-flowchart')) {
|
} else if (enableFlowchart
|
||||||
|
&& (code.classList.contains('language-flowchart')
|
||||||
|
|| code.classList.contains('language-flow'))) {
|
||||||
// Flowchart code block.
|
// Flowchart code block.
|
||||||
continue;
|
continue;
|
||||||
} else if (enableMathJax && code.classList.contains('language-mathjax')) {
|
} else if (enableMathJax && code.classList.contains('language-mathjax')) {
|
||||||
@ -84,7 +86,7 @@ var updateText = function(text) {
|
|||||||
insertImageCaption();
|
insertImageCaption();
|
||||||
highlightCodeBlocks(document, VEnableMermaid, VEnableFlowchart, VEnableMathjax);
|
highlightCodeBlocks(document, VEnableMermaid, VEnableFlowchart, VEnableMathjax);
|
||||||
renderMermaid('language-mermaid');
|
renderMermaid('language-mermaid');
|
||||||
renderFlowchart('language-flowchart');
|
renderFlowchart(['language-flowchart', 'language-flow']);
|
||||||
addClassToCodeBlock();
|
addClassToCodeBlock();
|
||||||
renderCodeBlockLineNumber();
|
renderCodeBlockLineNumber();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user