force redraw for asynchronously rendered plugin content

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

@ -297,6 +297,8 @@ define([
} }
}); });
DiffMd.onPluginLoaded(drawPreview);
return { return {
forceDraw: forceDrawPreview, forceDraw: forceDrawPreview,
draw: drawPreview, draw: drawPreview,

@ -19,6 +19,9 @@ define([
var renderer = new Marked.Renderer(); var renderer = new Marked.Renderer();
var restrictedRenderer = new Marked.Renderer(); var restrictedRenderer = new Marked.Renderer();
var pluginLoaded = Util.mkEvent();
DiffMd.onPluginLoaded = pluginLoaded.reg;
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; }" +
@ -42,6 +45,7 @@ define([
} }
Mermaid.init.call(args); Mermaid.init.call(args);
pluginLoaded.fire();
}); });
} }
}; };
@ -49,7 +53,6 @@ define([
var Mathjax = { var Mathjax = {
__stubbed: true, __stubbed: true,
tex2svg: function (a, b) { 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 () {
@ -57,7 +60,8 @@ define([
if (Mathjax.__stubbed) { if (Mathjax.__stubbed) {
Mathjax = window.MathJax; Mathjax = window.MathJax;
} }
Mathjax.tex2svg(a, b); //args[0], args[1]); Mathjax.tex2svg(a, b);
pluginLoaded.fire();
}); });
} }
}; };
@ -79,6 +83,7 @@ define([
markmapLoaded = true; markmapLoaded = true;
} }
drawMarkmap($el); drawMarkmap($el);
pluginLoaded.fire();
}); });
}; };
@ -194,7 +199,7 @@ define([
} else if (language === 'mathjax') { } else if (language === 'mathjax') {
var svg = Mathjax.tex2svg(code, {display: true}); var svg = Mathjax.tex2svg(code, {display: true});
if (!svg) { if (!svg) {
return defaultCode.apply(renderer, arguments); 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 {
@ -345,7 +350,7 @@ define([
parent.removeChild(node); parent.removeChild(node);
}; };
var removeForbiddenTags = function (root) { // YYY var removeForbiddenTags = function (root) {
if (!root) { return; } if (!root) { return; }
if (forbiddenTags.indexOf(root.nodeName.toUpperCase()) !== -1) { removeNode(root); } if (forbiddenTags.indexOf(root.nodeName.toUpperCase()) !== -1) { removeNode(root); }
slice(root.children).forEach(removeForbiddenTags); slice(root.children).forEach(removeForbiddenTags);

Loading…
Cancel
Save