Skip to content

Commit 85ae1f2

Browse files
Merge pull request #51 from interledger/am/safari-mermaid
fix: mermaid not respecting <br> in safari
2 parents 317da3a + 9ce133f commit 85ae1f2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@interledger/docs-design-system",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"type": "module",
55
"description": "Shared styles and components used across all Interledger Starlight documentation sites",
66
"exports": {

src/components/Mermaid.astro

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,26 @@ const { graph, hasBorder = false } = Astro.props;
2424

2525
<script>
2626
import mermaid from "/node_modules/mermaid/dist/mermaid.esm.min.mjs";
27-
mermaid.initialize({ startOnLoad: true });
27+
mermaid.initialize({ startOnLoad: false });
28+
29+
const mermaidElements = document.querySelectorAll("pre.mermaid");
30+
31+
function unescapeHTML(str) {
32+
return str
33+
.replaceAll("&gt;", ">")
34+
.replaceAll("&lt;", "<")
35+
.replaceAll("&amp;", "&");
36+
}
37+
38+
async function drawDiagram(mermaidElement) {
39+
let graphDefinition = mermaidElement.innerHTML;
40+
graphDefinition = unescapeHTML(graphDefinition);
41+
const id = `graphDiv${Math.floor(Math.random() * 10000)}`;
42+
const { svg } = await mermaid.render(id, graphDefinition);
43+
mermaidElement.innerHTML = svg;
44+
}
45+
46+
for (let mermaidElement of mermaidElements) {
47+
await drawDiagram(mermaidElement);
48+
}
2849
</script>

0 commit comments

Comments
 (0)