Workaround that graphviz might not recover from error

This commit is contained in:
Wu Cheng-Han 2017-01-04 23:59:12 +08:00
parent c1b5e74cf9
commit 08b04e9528

View file

@ -11,6 +11,7 @@ var PDFObject = require('pdfobject');
var S = require('string'); var S = require('string');
var saveAs = require('file-saver').saveAs; var saveAs = require('file-saver').saveAs;
require('../vendor/md-toc'); require('../vendor/md-toc');
var Viz = require("viz.js");
//auto update last change //auto update last change
window.createtime = null; window.createtime = null;
@ -335,10 +336,8 @@ function finishView(view) {
} }
}); });
//graphviz //graphviz
var Viz = require("viz.js");
var graphvizs = view.find("div.graphviz.raw").removeClass("raw"); var graphvizs = view.find("div.graphviz.raw").removeClass("raw");
graphvizs.each(function (key, value) { function parseGraphviz(key, value) {
try {
var $value = $(value); var $value = $(value);
var $ele = $(value).parent().parent(); var $ele = $(value).parent().parent();
@ -348,10 +347,21 @@ function finishView(view) {
$ele.addClass('graphviz'); $ele.addClass('graphviz');
$value.children().unwrap().unwrap(); $value.children().unwrap().unwrap();
}
graphvizs.each(function (key, value) {
try {
parseGraphviz(key, value);
} catch (err) { } catch (err) {
// workaround for graphviz not recover from error
try {
parseGraphviz(key, value);
} catch (err) {
var $value = $(value);
$value.unwrap(); $value.unwrap();
$value.parent().append('<div class="alert alert-warning">' + err + '</div>');
console.warn(err); console.warn(err);
} }
}
}); });
//mermaid //mermaid
var mermaids = view.find("div.mermaid.raw").removeClass("raw"); var mermaids = view.find("div.mermaid.raw").removeClass("raw");