From 12d3c00fd71ef5019733d96bb9fadc3fa9042dfe Mon Sep 17 00:00:00 2001 From: Ralph Thesen Date: Thu, 10 Oct 2024 00:33:49 +0200 Subject: [PATCH] refactor: update_mermaid() does exactly that. diagrams in documentation as svgs. --- otterwiki/renderer.py | 3 ++- otterwiki/static/img/mermaid-example-dark.svg | 2 ++ otterwiki/static/img/mermaid-example-light.svg | 1 + otterwiki/static/js/otterwiki.js | 10 ++++++++++ otterwiki/templates/editor.html | 2 +- otterwiki/templates/snippets/syntax.html | 17 +++++++++++------ 6 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 otterwiki/static/img/mermaid-example-dark.svg create mode 100644 otterwiki/static/img/mermaid-example-light.svg diff --git a/otterwiki/renderer.py b/otterwiki/renderer.py index 79dbbdd..3129420 100644 --- a/otterwiki/renderer.py +++ b/otterwiki/renderer.py @@ -150,9 +150,10 @@ def block_code(self, code, info=None): ) # replace \n with
for convinient diagram writing (and match the github syntax) code = code.replace("\\n","
") - return '\n
{}
\n'.format( + html = '\n
{}\n
\n'.format( code.strip() ) + return html else: html = prefix + pygments_render(code, info) html = showmagicword(cursorline, html) diff --git a/otterwiki/static/img/mermaid-example-dark.svg b/otterwiki/static/img/mermaid-example-dark.svg new file mode 100644 index 0000000..e4920ba --- /dev/null +++ b/otterwiki/static/img/mermaid-example-dark.svg @@ -0,0 +1,2 @@ +

supports

An Otter Wiki

Mermaid

+ diff --git a/otterwiki/static/img/mermaid-example-light.svg b/otterwiki/static/img/mermaid-example-light.svg new file mode 100644 index 0000000..f145e64 --- /dev/null +++ b/otterwiki/static/img/mermaid-example-light.svg @@ -0,0 +1 @@ +

supports

An Otter Wiki

Mermaid

diff --git a/otterwiki/static/js/otterwiki.js b/otterwiki/static/js/otterwiki.js index 0813b7e..025bde8 100644 --- a/otterwiki/static/js/otterwiki.js +++ b/otterwiki/static/js/otterwiki.js @@ -633,6 +633,7 @@ var otterwiki = { if (ehm.style.display === "none") { ehm.style.display = "block"; + otterwiki.update_mermaid(); } else { @@ -664,6 +665,15 @@ var otterwiki = { } return false; }, + update_mermaid: function() { + if (typeof(mermaid) == 'undefined' || mermaid == null) { return; } + + var mm_diagrams = document.getElementsByClassName('mermaid'); + for (var i = 0; i < mm_diagrams.length; ++i) { + mm_diagrams[i].removeAttribute('data-processed'); + } + mermaid.contentLoaded(); + }, } var MathJax = { diff --git a/otterwiki/templates/editor.html b/otterwiki/templates/editor.html index 1567270..313fd76 100644 --- a/otterwiki/templates/editor.html +++ b/otterwiki/templates/editor.html @@ -426,7 +426,7 @@