feat: Mermaid diagram rendering in WASM doc

This commit is contained in:
Accusys
2026-05-18 12:44:47 +08:00
parent 47caf0cc4a
commit b373608e67

View File

@@ -4,6 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Momentry API Docs</title>
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:false,theme:'base',themeVariables:{primaryColor:'#1a1a2e',lineColor:'#e94560',secondaryColor:'#16213e'}});</script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; color: #333; }
@@ -114,7 +116,10 @@ function md2html(md) {
const rlen = result[1];
const ret = new TextDecoder().decode(new Uint8Array(memory.buffer, rptr, rlen));
free(rptr, rlen, 1);
return ret.replace(/<table>/g, '<table class="table">');
// Convert mermaid code blocks: <pre><code class="language-mermaid">...</code></pre> → <pre class="mermaid">...</pre>
var h = ret.replace(/<table>/g, '<table class="table">');
h = h.replace(/<pre><code class="language-mermaid">([\s\S]*?)<\/code><\/pre>/g, '<pre class="mermaid">$1</pre>');
return h;
}
async function loadDoc(name) {
@@ -125,6 +130,7 @@ async function loadDoc(name) {
const md = await resp.text();
if (!wasm_exports) throw new Error('WASM not loaded');
el.innerHTML = md2html(md);
if (typeof mermaid !== 'undefined') mermaid.run({nodes:[el.querySelector('.mermaid')].filter(Boolean)});
document.querySelectorAll('.sidebar a.module-link').forEach(function(a) { a.classList.remove('active'); });
var link = document.querySelector('.sidebar a[data-module="' + name + '"]');
if (link) link.classList.add('active');