error handling for Mermaid and Mathjax

This commit is contained in:
Le Tan 2017-03-24 20:31:05 +08:00
parent 1894606c10
commit 2a1cba1fed
5 changed files with 30 additions and 8 deletions

View File

@ -9,7 +9,12 @@ var updateHtml = function(html) {
if (code.parentElement.tagName.toLowerCase() == 'pre') { if (code.parentElement.tagName.toLowerCase() == 'pre') {
if (VEnableMermaid && code.classList.contains('language-mermaid')) { if (VEnableMermaid && code.classList.contains('language-mermaid')) {
// Mermaid code block. // Mermaid code block.
try {
var graph = mermaidAPI.render('mermaid-diagram-' + mermaidIdx++, code.innerText, function(){}); var graph = mermaidAPI.render('mermaid-diagram-' + mermaidIdx++, code.innerText, function(){});
} catch (err) {
content.setLog("err: " + err);
continue;
}
var graphDiv = document.createElement('div'); var graphDiv = document.createElement('div');
graphDiv.classList.add(VMermaidDivClass); graphDiv.classList.add(VMermaidDivClass);
graphDiv.innerHTML = graph; graphDiv.innerHTML = graph;
@ -24,8 +29,12 @@ var updateHtml = function(html) {
} }
} }
if (VEnableMathjax && (typeof MathJax != 'undefined')) { if (VEnableMathjax) {
try {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]); MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]);
} catch (err) {
content.setLog("err: " + err);
}
} }
} }

View File

@ -170,7 +170,11 @@ var updateText = function(text) {
handleToc(needToc); handleToc(needToc);
renderMermaid('lang-mermaid'); renderMermaid('lang-mermaid');
if (VEnableMathjax) { if (VEnableMathjax) {
try {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]); MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]);
} catch (err) {
content.setLog("err: " + err);
}
} }
} }

View File

@ -147,7 +147,12 @@ var renderMermaid = function(className) {
var code = codes[i]; var code = codes[i];
if (code.classList.contains(className)) { if (code.classList.contains(className)) {
// Mermaid code block. // Mermaid code block.
try {
var graph = mermaidAPI.render('mermaid-diagram-' + mermaidIdx++, code.innerText, function(){}); var graph = mermaidAPI.render('mermaid-diagram-' + mermaidIdx++, code.innerText, function(){});
} catch (err) {
content.setLog("err: " + err);
continue;
}
var graphDiv = document.createElement('div'); var graphDiv = document.createElement('div');
graphDiv.classList.add(VMermaidDivClass); graphDiv.classList.add(VMermaidDivClass);
graphDiv.innerHTML = graph; graphDiv.innerHTML = graph;

View File

@ -123,7 +123,11 @@ var updateText = function(text) {
handleToc(needToc); handleToc(needToc);
renderMermaid('lang-mermaid'); renderMermaid('lang-mermaid');
if (VEnableMathjax) { if (VEnableMathjax) {
try {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]); MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]);
} catch (err) {
content.setLog("err: " + err);
}
} }
}; };

View File

@ -13,8 +13,8 @@ language=System
editor_font_size=12 editor_font_size=12
; 0 - Hoedown, 1 - Marked, 2 - Markdown-it ; 0 - Hoedown, 1 - Marked, 2 - Markdown-it
markdown_converter=2 markdown_converter=2
enable_mermaid=true enable_mermaid=false
enable_mathjax=true enable_mathjax=false
[session] [session]
tools_dock_checked=true tools_dock_checked=true