From 08b04e9528cc12f1fe7dcedaab8ce10ab8f6c97f Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 4 Jan 2017 23:59:12 +0800 Subject: Workaround that graphviz might not recover from error --- public/js/extra.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index ba61a669..1f45606a 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -11,6 +11,7 @@ var PDFObject = require('pdfobject'); var S = require('string'); var saveAs = require('file-saver').saveAs; require('../vendor/md-toc'); +var Viz = require("viz.js"); //auto update last change window.createtime = null; @@ -335,22 +336,31 @@ function finishView(view) { } }); //graphviz - var Viz = require("viz.js"); var graphvizs = view.find("div.graphviz.raw").removeClass("raw"); - graphvizs.each(function (key, value) { - try { - var $value = $(value); - var $ele = $(value).parent().parent(); + function parseGraphviz(key, value) { + var $value = $(value); + var $ele = $(value).parent().parent(); - var graphviz = Viz($value.text()); - if (!graphviz) throw Error('viz.js output empty graph'); - $value.html(graphviz); + var graphviz = Viz($value.text()); + if (!graphviz) throw Error('viz.js output empty graph'); + $value.html(graphviz); - $ele.addClass('graphviz'); - $value.children().unwrap().unwrap(); + $ele.addClass('graphviz'); + $value.children().unwrap().unwrap(); + } + graphvizs.each(function (key, value) { + try { + parseGraphviz(key, value); } catch (err) { - $value.unwrap(); - console.warn(err); + // workaround for graphviz not recover from error + try { + parseGraphviz(key, value); + } catch (err) { + var $value = $(value); + $value.unwrap(); + $value.parent().append('
' + err + '
'); + console.warn(err); + } } }); //mermaid -- cgit v1.2.3 From eaf9218f612f9aa23414decb676d87c812e70f66 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 4 Jan 2017 23:59:28 +0800 Subject: Update to show yaml-metadata and diagram parsing error in the view --- public/js/extra.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index 1f45606a..4a9cc76e 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -309,6 +309,7 @@ function finishView(view) { svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet'); } catch (err) { $value.unwrap(); + $value.parent().append('
' + err + '
'); console.warn(err); } }); @@ -332,6 +333,7 @@ function finishView(view) { $value.children().unwrap().unwrap(); } catch (err) { $value.unwrap(); + $value.parent().append('
' + err + '
'); console.warn(err); } }); @@ -380,11 +382,11 @@ function finishView(view) { $ele.html($value.text()); mermaid.init(undefined, $ele); } else { - $value.unwrap(); - console.warn(mermaidError); + throw new Error(mermaidError); } } catch (err) { $value.unwrap(); + $value.parent().append('
' + err + '
'); console.warn(err); } }); @@ -543,6 +545,16 @@ function postProcess(code) { }); } } + // show yaml meta paring error + if (md.metaError) { + var warning = result.find('div#meta-error'); + if (warning && warning.length > 0) { + warning.text(md.metaError) + } else { + warning = $('
' + md.metaError + '
') + result.prepend(warning); + } + } return result; } window.postProcess = postProcess; @@ -1122,7 +1134,9 @@ function meta(state, start, end, silent) { try { md.meta = jsyaml.safeLoad(data.join('\n')) || {}; + delete md.metaError; } catch(err) { + md.metaError = err; console.warn(err); return false; } -- cgit v1.2.3