diff options
author | Yukai Huang | 2017-01-07 00:05:15 +0800 |
---|---|---|
committer | Yukai Huang | 2017-01-07 00:05:15 +0800 |
commit | 3566d71aea5486709f73ba7fac5a421993b41f00 (patch) | |
tree | 487cec8110bdb7f004d761dcdb5c719bc5303cd6 /public/js | |
parent | e2694d7a62f9a9b626794d2eeef0235c8a348ad3 (diff) | |
parent | 23a12dd927b66880fa991b377d450455851b69a9 (diff) |
Merge branch 'master' into frontend-next
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/extra.js | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/public/js/extra.js b/public/js/extra.js index f1681b2e..6cfb5b0a 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -13,6 +13,7 @@ import { saveAs } from 'file-saver'; require('./common'); require('../vendor/md-toc'); +var Viz = require("viz.js"); //auto update last change window.createtime = null; @@ -314,6 +315,7 @@ export function finishView(view) { svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet'); } catch (err) { $value.unwrap(); + $value.parent().append('<div class="alert alert-warning">' + err + '</div>'); console.warn(err); } }); @@ -337,26 +339,36 @@ export function finishView(view) { $value.children().unwrap().unwrap(); } catch (err) { $value.unwrap(); + $value.parent().append('<div class="alert alert-warning">' + err + '</div>'); console.warn(err); } }); //graphviz - const Viz = require("viz.js"); - const graphvizs = view.find("div.graphviz.raw").removeClass("raw"); - graphvizs.each((key, value) => { - try { - var $value = $(value); - const $ele = $(value).parent().parent(); + var graphvizs = view.find("div.graphviz.raw").removeClass("raw"); + function parseGraphviz(key, value) { + var $value = $(value); + var $ele = $(value).parent().parent(); - const 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 @@ -376,11 +388,11 @@ export 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('<div class="alert alert-warning">' + err + '</div>'); console.warn(err); } }); @@ -539,6 +551,16 @@ export 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 = $('<div id="meta-error" class="alert alert-warning">' + md.metaError + '</div>') + result.prepend(warning); + } + } return result; } window.postProcess = postProcess; @@ -1103,7 +1125,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; } |