summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWu Cheng-Han2017-01-04 23:59:12 +0800
committerWu Cheng-Han2017-01-04 23:59:12 +0800
commit08b04e9528cc12f1fe7dcedaab8ce10ab8f6c97f (patch)
tree96a91ba0cbaa2c63b6109e6a6f46321ac2def5b4
parentc1b5e74cf915345bc608f71c8fb09e4f3f044d33 (diff)
Workaround that graphviz might not recover from error
Diffstat (limited to '')
-rw-r--r--public/js/extra.js34
1 files changed, 22 insertions, 12 deletions
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('<div class="alert alert-warning">' + err + '</div>');
+ console.warn(err);
+ }
}
});
//mermaid