address some race conditions when rendering multiple elements

pull/1/head
ansuz 5 years ago
parent a528d857a7
commit f7529d2908

@ -19,43 +19,45 @@ define([
var renderer = new Marked.Renderer(); var renderer = new Marked.Renderer();
var restrictedRenderer = new Marked.Renderer(); var restrictedRenderer = new Marked.Renderer();
var argsMap = {};
var mermaidThemeCSS = //".node rect { fill: #DDD; stroke: #AAA; } " + var mermaidThemeCSS = //".node rect { fill: #DDD; stroke: #AAA; } " +
"rect.task, rect.task0, rect.task2 { stroke-width: 1 !important; rx: 0 !important; } " + "rect.task, rect.task0, rect.task2 { stroke-width: 1 !important; rx: 0 !important; } " +
"g.grid g.tick line { opacity: 0.25; }" + "g.grid g.tick line { opacity: 0.25; }" +
"g.today line { stroke: red; stroke-width: 1; stroke-dasharray: 3; opacity: 0.5; }"; "g.today line { stroke: red; stroke-width: 1; stroke-dasharray: 3; opacity: 0.5; }";
var Mermaid = { var Mermaid = {
__stubbed: true,
init: function () { init: function () {
argsMap.mermaid = Util.slice(arguments); var args = Util.slice(arguments);
require([ require([
'mermaid', 'mermaid',
'css!/code/mermaid-new.css' 'css!/code/mermaid-new.css'
], function (_Mermaid) { ], function (_Mermaid) {
console.debug("loaded mermaid"); console.debug("loaded mermaid");
if (Mermaid.__stubbed) {
Mermaid = _Mermaid; Mermaid = _Mermaid;
Mermaid.initialize({ Mermaid.initialize({
gantt: { axisFormat: '%m-%d', }, gantt: { axisFormat: '%m-%d', },
"themeCSS": mermaidThemeCSS, "themeCSS": mermaidThemeCSS,
}); });
Mermaid.init.call(argsMap.mermaid); }
delete argsMap.mermaid;
Mermaid.init.call(args);
}); });
} }
}; };
var Mathjax = { var Mathjax = {
tex2svg: function () { __stubbed: true,
argsMap.Mathjax = Util.slice(arguments); tex2svg: function (a, b) {
var args = Util.slice(arguments);
require([ require([
'/bower_components/MathJax/es5/tex-svg.js', '/bower_components/MathJax/es5/tex-svg.js',
], function () { ], function () {
console.debug("Loaded mathjax"); console.debug("Loaded mathjax");
if (Mathjax.__stubbed) {
Mathjax = window.MathJax; Mathjax = window.MathJax;
if (!argsMap.Mathjax) { return; } }
Mathjax.tex2svg(argsMap.Mathjax[0], argsMap.Mathjax[1]); Mathjax.tex2svg(a, b); //args[0], args[1]);
delete argsMap.Mathjax;
}); });
} }
}; };
@ -65,18 +67,18 @@ define([
var Markmap; var Markmap;
var markmapLoaded = false; var markmapLoaded = false;
var loadMarkmap = function () { var loadMarkmap = function ($el) {
require([ require([
'/lib/markmap/transform.min.js', '/lib/markmap/transform.min.js',
'/lib/markmap/view.min.js', '/lib/markmap/view.min.js',
], function (_Transform, _View) { ], function (_Transform, _View) {
if (!markmapLoaded) {
console.debug("Loaded markmap"); console.debug("Loaded markmap");
MarkMapTransform = _Transform; MarkMapTransform = _Transform;
Markmap = _View; Markmap = _View;
markmapLoaded = true; markmapLoaded = true;
drawMarkmap(argsMap.markmap); }
delete argsMap.markmap; drawMarkmap($el);
}); });
}; };
@ -120,14 +122,8 @@ define([
}; };
drawMarkmap = function ($el) { drawMarkmap = function ($el) {
if (!markmapLoaded) { if (!markmapLoaded) { return void loadMarkmap($el); }
argsMap.markmap = $el; //Util.slice(arguments);
loadMarkmap();
return;
}
if (!$el) { return console.error("no element provided"); } if (!$el) { return console.error("no element provided"); }
var data = MarkMapTransform.transform($el[0].getAttribute("markmap-source")); var data = MarkMapTransform.transform($el[0].getAttribute("markmap-source"));
$el[0].innerHTML = "<svg width='100%' height='600'/>"; $el[0].innerHTML = "<svg width='100%' height='600'/>";
Markmap.markmap($el[0].firstChild, data); Markmap.markmap($el[0].firstChild, data);
@ -197,7 +193,9 @@ define([
return '<pre class="markmap" data-plugin="markmap">'+Util.fixHTML(code)+'</pre>'; return '<pre class="markmap" data-plugin="markmap">'+Util.fixHTML(code)+'</pre>';
} else if (language === 'mathjax') { } else if (language === 'mathjax') {
var svg = Mathjax.tex2svg(code, {display: true}); var svg = Mathjax.tex2svg(code, {display: true});
if (!svg) { return ''; } if (!svg) {
return defaultCode.apply(renderer, arguments);
}
return '<pre class="mathjax">'+ svg.innerHTML.replace(/xlink:href/g, "href") +'</pre>'; return '<pre class="mathjax">'+ svg.innerHTML.replace(/xlink:href/g, "href") +'</pre>';
} else { } else {
return defaultCode.apply(renderer, arguments); return defaultCode.apply(renderer, arguments);

Loading…
Cancel
Save