mermaid/demos/dev/example.html

68 lines
1.7 KiB
HTML
Raw Normal View History

2023-08-09 09:51:24 +02:00
<!--Do not edit this file-->
<!--Duplicate this file to any name you like, run `pnpm dev`, open http://localhost:9000/dev/name.html to view-->
<html>
<head>
<title>Mermaid development page</title>
2023-09-18 19:59:27 +02:00
<style>
.container {
display: flex;
flex-direction: row;
}
#code {
max-width: 30vw;
width: 30vw;
}
#dynamicDiagram {
2023-09-18 20:01:23 +02:00
padding-left: 2em;
2023-09-18 19:59:27 +02:00
flex: 1;
}
</style>
2023-08-09 09:51:24 +02:00
</head>
<body>
<pre id="diagram" class="mermaid">
graph TB
a --> b
a --> c
b --> d
c --> d
</pre>
2023-09-18 19:59:27 +02:00
<hr />
Type code to view diagram:
<div class="container">
<textarea name="code" id="code" cols="30" rows="10"></textarea>
<div id="dynamicDiagram"></div>
</div>
<pre class="mermaid">info</pre>
2023-08-09 09:51:24 +02:00
<script type="module">
import mermaid from '/mermaid.esm.mjs';
2024-03-23 10:37:21 +01:00
import flowchartELK from '/mermaid-flowchart-elk.esm.mjs';
await mermaid.registerExternalDiagrams([flowchartELK]);
2023-09-18 19:59:27 +02:00
async function render(str) {
const { svg } = await mermaid.render('dynamic', str);
document.getElementById('dynamicDiagram').innerHTML = svg;
}
const storeKey = window.location.pathname;
const code = localStorage.getItem(storeKey);
if (code) {
document.getElementById('code').value = code;
await render(code);
}
2023-08-09 09:51:24 +02:00
mermaid.initialize({
startOnLoad: true,
logLevel: 0,
});
2023-09-18 19:59:27 +02:00
document.getElementById('code').addEventListener('input', async (e) => {
const value = e.target.value;
localStorage.setItem(storeKey, value);
await render(value);
});
2023-08-09 09:51:24 +02:00
</script>
2023-08-13 15:21:02 +02:00
<script src="/dev/reload.js"></script>
2023-08-09 09:51:24 +02:00
</body>
</html>