Readme

Display Mermaid

Takes a mermaid document (as a string) and returns an http handler that renders it.

import { displayMermaid } from "https://esm.town/v/saolsen/display_mermaid";

const mermaid = `
sequenceDiagram
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
    Alice-)John: See you later!
`;

export default displayMermaid(mermaid);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/// Create a handler function that displays the mermaid diagram.
export function displayMermaid(mermaid: string): (req: Request) => Response {
function handler(req: Request): Response {
return new Response(
`
<html>
<head>
<title>nn</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0">
</meta>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
mermaid.initialize({ startOnLoad: true });
</script>
</head>
<body>
<pre class="mermaid">
${mermaid}
</pre>
</body>
</html>`,
{ headers: { "Content-Type": "text/html" } },
);
}
return handler;
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.