diff --git a/bower.json b/bower.json index 9fd787c20..bd9cebdd6 100644 --- a/bower.json +++ b/bower.json @@ -49,7 +49,8 @@ "saferphore": "^0.0.1", "jszip": "Stuk/jszip#^3.1.5", "requirejs-plugins": "^1.0.3", - "dragula.js": "3.7.2" + "dragula.js": "3.7.2", + "MathJax": "3.0.5" }, "resolutions": { "bootstrap": "^v4.0.0", diff --git a/www/common/diffMarked.js b/www/common/diffMarked.js index 48f800075..86f99aa42 100644 --- a/www/common/diffMarked.js +++ b/www/common/diffMarked.js @@ -2,6 +2,7 @@ define([ 'jquery', '/api/config', '/bower_components/marked/marked.min.js', + '/bower_components/MathJax/es5/tex-svg.js', '/common/common-hash.js', '/common/common-util.js', '/common/hyperscript.js', @@ -12,7 +13,7 @@ define([ '/bower_components/diff-dom/diffDOM.js', '/bower_components/tweetnacl/nacl-fast.min.js', 'css!/common/highlight/styles/github.css' -],function ($, ApiConfig, Marked, Hash, Util, h, MT, MediaTag, Highlight, Messages) { +],function ($, ApiConfig, Marked, MathJax, Hash, Util, h, MT, MediaTag, Highlight, Messages) { var DiffMd = {}; var DiffDOM = window.diffDOM; @@ -23,6 +24,8 @@ define([ init: function () {} }; + var MathJax = window.MathJax; + var mermaidThemeCSS = //".node rect { fill: #DDD; stroke: #AAA; } " + "rect.task, rect.task0, rect.task2 { stroke-width: 1 !important; rx: 0 !important; } " + "g.grid g.tick line { opacity: 0.25; }" + @@ -95,6 +98,9 @@ define([ renderer.code = function (code, language) { if (language === 'mermaid' && code.match(/^(graph|pie|gantt|sequenceDiagram|classDiagram|gitGraph)/)) { return '
'+Util.fixHTML(code)+''; + } else if (language === 'mathjax') { + var svg = MathJax.tex2svg(code, {display: true}) + return '
'+ svg.innerHTML.replace(/xlink:href/g, "href") +''; } else { return defaultCode.apply(renderer, arguments); }