From b5a18e8e098339786c6284fe69f5ee5031bf2f49 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 3 Jul 2020 17:38:00 -0400 Subject: [PATCH] force redraw for asynchronously rendered plugin content --- www/code/inner.js | 2 ++ www/common/diffMarked.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/www/code/inner.js b/www/code/inner.js index de91714c4..7f304e6bc 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -297,6 +297,8 @@ define([ } }); + DiffMd.onPluginLoaded(drawPreview); + return { forceDraw: forceDrawPreview, draw: drawPreview, diff --git a/www/common/diffMarked.js b/www/common/diffMarked.js index d6f317b7b..25d66187d 100644 --- a/www/common/diffMarked.js +++ b/www/common/diffMarked.js @@ -19,6 +19,9 @@ define([ var renderer = new Marked.Renderer(); var restrictedRenderer = new Marked.Renderer(); + var pluginLoaded = Util.mkEvent(); + DiffMd.onPluginLoaded = pluginLoaded.reg; + 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; }" + @@ -42,6 +45,7 @@ define([ } Mermaid.init.call(args); + pluginLoaded.fire(); }); } }; @@ -49,7 +53,6 @@ define([ var Mathjax = { __stubbed: true, tex2svg: function (a, b) { - var args = Util.slice(arguments); require([ '/bower_components/MathJax/es5/tex-svg.js', ], function () { @@ -57,7 +60,8 @@ define([ if (Mathjax.__stubbed) { Mathjax = window.MathJax; } - Mathjax.tex2svg(a, b); //args[0], args[1]); + Mathjax.tex2svg(a, b); + pluginLoaded.fire(); }); } }; @@ -79,6 +83,7 @@ define([ markmapLoaded = true; } drawMarkmap($el); + pluginLoaded.fire(); }); }; @@ -194,7 +199,7 @@ define([ } else if (language === 'mathjax') { var svg = Mathjax.tex2svg(code, {display: true}); if (!svg) { - return defaultCode.apply(renderer, arguments); + return defaultCode.apply(renderer, arguments); } return '
'+ svg.innerHTML.replace(/xlink:href/g, "href") +'
'; } else { @@ -345,7 +350,7 @@ define([ parent.removeChild(node); }; - var removeForbiddenTags = function (root) { // YYY + var removeForbiddenTags = function (root) { if (!root) { return; } if (forbiddenTags.indexOf(root.nodeName.toUpperCase()) !== -1) { removeNode(root); } slice(root.children).forEach(removeForbiddenTags);