Update to show yaml-metadata and diagram parsing error in the view

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

View file

@ -309,6 +309,7 @@ function finishView(view) {
svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet'); svg[0].setAttribute('preserveAspectRatio', 'xMidYMid meet');
} catch (err) { } catch (err) {
$value.unwrap(); $value.unwrap();
$value.parent().append('<div class="alert alert-warning">' + err + '</div>');
console.warn(err); console.warn(err);
} }
}); });
@ -332,6 +333,7 @@ function finishView(view) {
$value.children().unwrap().unwrap(); $value.children().unwrap().unwrap();
} catch (err) { } catch (err) {
$value.unwrap(); $value.unwrap();
$value.parent().append('<div class="alert alert-warning">' + err + '</div>');
console.warn(err); console.warn(err);
} }
}); });
@ -380,11 +382,11 @@ function finishView(view) {
$ele.html($value.text()); $ele.html($value.text());
mermaid.init(undefined, $ele); mermaid.init(undefined, $ele);
} else { } else {
$value.unwrap(); throw new Error(mermaidError);
console.warn(mermaidError);
} }
} catch (err) { } catch (err) {
$value.unwrap(); $value.unwrap();
$value.parent().append('<div class="alert alert-warning">' + err + '</div>');
console.warn(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 = $('<div id="meta-error" class="alert alert-warning">' + md.metaError + '</div>')
result.prepend(warning);
}
}
return result; return result;
} }
window.postProcess = postProcess; window.postProcess = postProcess;
@ -1122,7 +1134,9 @@ function meta(state, start, end, silent) {
try { try {
md.meta = jsyaml.safeLoad(data.join('\n')) || {}; md.meta = jsyaml.safeLoad(data.join('\n')) || {};
delete md.metaError;
} catch(err) { } catch(err) {
md.metaError = err;
console.warn(err); console.warn(err);
return false; return false;
} }