Workaround that graphviz might not recover from error
This commit is contained in:
parent
c1b5e74cf9
commit
08b04e9528
1 changed files with 22 additions and 12 deletions
|
@ -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,22 +336,31 @@ 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");
|
||||||
|
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);
|
||||||
|
|
||||||
|
$ele.addClass('graphviz');
|
||||||
|
$value.children().unwrap().unwrap();
|
||||||
|
}
|
||||||
graphvizs.each(function (key, value) {
|
graphvizs.each(function (key, value) {
|
||||||
try {
|
try {
|
||||||
var $value = $(value);
|
parseGraphviz(key, value);
|
||||||
var $ele = $(value).parent().parent();
|
|
||||||
|
|
||||||
var graphviz = Viz($value.text());
|
|
||||||
if (!graphviz) throw Error('viz.js output empty graph');
|
|
||||||
$value.html(graphviz);
|
|
||||||
|
|
||||||
$ele.addClass('graphviz');
|
|
||||||
$value.children().unwrap().unwrap();
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
$value.unwrap();
|
// workaround for graphviz not recover from error
|
||||||
console.warn(err);
|
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
|
//mermaid
|
||||||
|
|
Loading…
Reference in a new issue