Mermaid support in the code app

This commit is contained in:
yflory
2019-04-03 14:45:42 +02:00
parent 27eb2a81d5
commit e5d7a0f5c6
3 changed files with 59445 additions and 1 deletions

View File

@@ -7,10 +7,12 @@ define([
'/common/media-tag.js',
'/common/highlight/highlight.pack.js',
'/customize/messages.js',
'/code/mermaid.js',
'css!/code/mermaid.css',
'/bower_components/diff-dom/diffDOM.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
'css!/common/highlight/styles/github.css'
],function ($, Marked, Hash, Util, h, MediaTag, Highlight, Messages) {
],function ($, Marked, Hash, Util, h, MediaTag, Highlight, Messages, Mermaid) {
var DiffMd = {};
var DiffDOM = window.diffDOM;
@@ -67,6 +69,14 @@ define([
var mediaMap = {};
renderer.code = function (code, language) {
if(language == 'mermaid' && (code.match(/^sequenceDiagram/) || code.match(/^graph/))) {
return '<pre class="mermaid">'+code+'</pre>';
} else {
return '<pre><code>'+code+'</code></pre>';
}
};
renderer.heading = function (text, level) {
var i = 0;
var safeText = text.toLowerCase().replace(/[^\w]+/g, '-');
@@ -271,6 +281,9 @@ define([
throw new Error(patch);
} else {
DD.apply($content[0], patch);
try {
Mermaid.init();
} catch (e) { console.error(e); }
var $mts = $content.find('media-tag:not(:has(*))');
$mts.each(function (i, el) {
$(el).contextmenu(function (e) {