Skip to content

Commit 1383210

Browse files
committed
Stop marked processing diagram code as Markdown
This was causing issues with Mermaid state diagrams, as the `*` in the start and end nodes (`[*]`) was being interpreted as emphasis (`<em>` tags were finding their way into the DOM). I found inspiration in [this solution](https://revealjs.com/math/#markdown) in the reveal.js docs which uses a single backtick to wrap text in a `<code>` block, which prevents marked (the JS Markdown processor used by reveal.js) from processing the text as markdown. To accommodate this change I’ve tweaked our JS to strip the code tag out of the Mermaid diagram code. This change may also provide an alternative approach for #35. I’ve upgraded Mermaid to default to 11.0.2, and users can now override this version in their `config.yml` like this: `mermaid_version: 11.0.2`. 11.0.2 is the most recent which didn’t introduce weird rendering issues with state diagrams which I’ve not spent time investigating.
1 parent 87d1dd8 commit 1383210

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ reveal_path: reveal.js/
3737
# mermaid.js diagram integration
3838
mermaid_diagrams: true
3939
mermaid_theme: dark # See https://mermaid-js.github.io/mermaid/#/theming?id=deployable-themes
40+
# mermaid_version: 11.0.2
4041

4142
# Exclude directories and/or files from the conversion
4243
exclude:

_layouts/reveal.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<!doctype html>
1+
{%
2+
assign mermaid_version = site.mermaid_version | default: '11.0.2'
3+
%}<!doctype html>
24
<html lang="en">
35

46
<head>
@@ -55,7 +57,7 @@
5557
%}{%
5658
assign mermaid_theme = site.mermaid_theme | default: 'dark'
5759
%}{%
58-
assign mermaid_span = '<!-- .slide: class="diagram-slide" data-transition="none"--><span class="diagram-data" style="display:none;">%%{init: {&#39;theme&#39;:&#39;' | append: mermaid_theme | append: '&#39;}}%%'
60+
assign mermaid_span = '<!-- .slide: class="diagram-slide" data-transition="none"--><span class="diagram-data" style="display:none;" data-mermaid-config="%%{init: {&#39;theme&#39;:&#39;' | append: mermaid_theme | append: '&#39;}}%%">`'
5961
%}{%
6062
for line in lines
6163
%}{%
@@ -68,7 +70,7 @@
6870
| replace:'<backgroundimageopacity>','<!-- .slide: data-background-opacity="'
6971
| replace:'</backgroundimageopacity>','" -->'
7072
| replace:'<mermaid>',mermaid_span
71-
| replace:'</mermaid>','</span><div class="diagram-display" style="height: 300px;"></div>'
73+
| replace:'</mermaid>','`</span><div class="diagram-display" style="height: 300px;"></div>'
7274
%}{%
7375
assign first_char = line | strip
7476
| slice: 0,1
@@ -126,7 +128,7 @@
126128
{ src: '{{ site.reveal_path }}plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
127129
{ src: '{{ site.reveal_path }}plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
128130
{% if site.mermaid_diagrams %}
129-
{ src: 'https://cdn.jsdelivr.net/npm/mermaid@9.1.6/dist/mermaid.min.js'},
131+
{ src: 'https://cdn.jsdelivr.net/npm/mermaid@{{ mermaid_version }}/dist/mermaid.min.js'},
130132
{ src: '{{ 'assets/js/mermaid/reveal-js-mermaid-plugin.js' | relative_url }}'},
131133
{% endif %}
132134
{% if site.reveal_notes_server %}

assets/js/mermaid/reveal-js-mermaid-plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
var dataElem = getDataElem(slide);
6767
var svgDiv = getDisplayDiv(slide);
6868

69-
svgDiv.innerHTML = dataElem.innerHTML;
69+
svgDiv.innerHTML = `${dataElem.getAttribute('data-mermaid-config')}\n${dataElem.getElementsByTagName('code')[0].innerHTML}`;
7070

7171
mermaid.flowchartConfig
7272
var config = {};

0 commit comments

Comments
 (0)