mermaid diagram
This commit is contained in:
@@ -0,0 +1,98 @@
|
|||||||
|
let mermaidPromise;
|
||||||
|
|
||||||
|
async function getMermaid() {
|
||||||
|
if (!mermaidPromise) {
|
||||||
|
mermaidPromise = import("https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs").then(
|
||||||
|
(module) => {
|
||||||
|
const mermaid = module.default ?? module;
|
||||||
|
mermaid.initialize({ startOnLoad: false });
|
||||||
|
return mermaid;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mermaidPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readDiagramSource(block) {
|
||||||
|
const code = block.querySelector("code");
|
||||||
|
return (code?.textContent ?? block.textContent ?? "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renderBlock(block) {
|
||||||
|
if (block.dataset.mermaidOverrideState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const source = readDiagramSource(block);
|
||||||
|
if (!source) {
|
||||||
|
block.dataset.mermaidOverrideState = "empty";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
block.dataset.mermaidOverrideState = "pending";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mermaid = await getMermaid();
|
||||||
|
const replacement = document.createElement("div");
|
||||||
|
replacement.className = "mermaid";
|
||||||
|
replacement.textContent = source;
|
||||||
|
replacement.dataset.mermaidOverrideState = "rendered";
|
||||||
|
block.replaceWith(replacement);
|
||||||
|
await mermaid.run({ nodes: [replacement] });
|
||||||
|
} catch (error) {
|
||||||
|
block.dataset.mermaidOverrideState = "failed";
|
||||||
|
console.warn("Mermaid override failed", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findBlocks(root = document) {
|
||||||
|
const blocks = [];
|
||||||
|
|
||||||
|
if (root instanceof Element && root.matches("pre.mermaid")) {
|
||||||
|
blocks.push(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root instanceof Document || root instanceof Element) {
|
||||||
|
blocks.push(...root.querySelectorAll("pre.mermaid"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderAll(root = document) {
|
||||||
|
for (const block of findBlocks(root)) {
|
||||||
|
void renderBlock(block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function installObserver() {
|
||||||
|
if (!(document.body instanceof HTMLBodyElement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const observer = new MutationObserver((mutations) => {
|
||||||
|
for (const mutation of mutations) {
|
||||||
|
for (const node of mutation.addedNodes) {
|
||||||
|
if (node instanceof Element) {
|
||||||
|
renderAll(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(document.body, { childList: true, subtree: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.readyState === "loading") {
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
renderAll();
|
||||||
|
installObserver();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
renderAll();
|
||||||
|
installObserver();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("pageshow", () => renderAll());
|
||||||
|
window.addEventListener("popstate", () => renderAll());
|
||||||
+41
-38
@@ -10,44 +10,47 @@ It also treats Markdown as the single source of truth for both MCP resources and
|
|||||||
|
|
||||||
## Completed-State Layout
|
## Completed-State Layout
|
||||||
|
|
||||||
```text
|
```mermaid
|
||||||
project-root/
|
---
|
||||||
|
|
config:
|
||||||
|- pyproject.toml
|
themeVariables:
|
||||||
|- uv.lock
|
treeView:
|
||||||
|- zensical.toml
|
labelColor: '#FFFFFF'
|
||||||
|
|
lineColor: '#FFFFFF'
|
||||||
|- docs/
|
---
|
||||||
| |- index.md
|
treeView-beta
|
||||||
| |- architecture.md
|
"project-root"
|
||||||
| |- mcp_layout.md
|
"pyproject.toml"
|
||||||
|
|
"uv.lock"
|
||||||
|- site/
|
"zensical.toml"
|
||||||
| |- ... static files built by zensical ...
|
"docs"
|
||||||
|
|
"index.md"
|
||||||
|- skills/
|
"architecture.md"
|
||||||
| |- pytest-scaffolding/
|
"mcp_layout.md"
|
||||||
| | |- SKILL.md
|
"site"
|
||||||
| | |- references/
|
"static build output"
|
||||||
| |- python-logging-dictconfig/
|
"skills"
|
||||||
| | |- SKILL.md
|
"pytest-scaffolding"
|
||||||
| | |- references/
|
"SKILL.md"
|
||||||
| |- fastapi-uv-docker/
|
"references"
|
||||||
| |- SKILL.md
|
"python-logging-dictconfig"
|
||||||
| |- references/
|
"SKILL.md"
|
||||||
|
|
"references"
|
||||||
|- src/
|
"fastapi-uv-docker"
|
||||||
|- personal_mcp/
|
"SKILL.md"
|
||||||
|- main.py
|
"references"
|
||||||
|- web/
|
"src"
|
||||||
| |- app.py
|
"personal_mcp"
|
||||||
| |- docs_mount.py
|
"main.py"
|
||||||
|- catalog/
|
"web"
|
||||||
| |- server.py
|
"app.py"
|
||||||
|- skills/
|
"docs_mount.py"
|
||||||
|- pytest_scaffolding/
|
"catalog"
|
||||||
|- python_logging_dictconfig/
|
"server.py"
|
||||||
|- fastapi_uv_docker/
|
"skills"
|
||||||
|
"pytest_scaffolding"
|
||||||
|
"python_logging_dictconfig"
|
||||||
|
"fastapi_uv_docker"
|
||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
.mermaid svg text,
|
||||||
|
.mermaid svg tspan,
|
||||||
|
.mermaid svg foreignObject,
|
||||||
|
.mermaid svg foreignObject div,
|
||||||
|
.mermaid svg foreignObject span,
|
||||||
|
.mermaid svg .nodeLabel,
|
||||||
|
.mermaid svg .edgeLabel {
|
||||||
|
color: var(--md-primary-bg-color, #fff);
|
||||||
|
fill: var(--md-primary-bg-color, #fff);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mermaid svg .treeView-node-label {
|
||||||
|
fill: var(--md-primary-bg-color, #fff) !important;
|
||||||
|
}
|
||||||
+2
-2
@@ -57,7 +57,7 @@ Copyright © 2026 The authors
|
|||||||
#
|
#
|
||||||
# Read more: https://zensical.org/docs/customization/#additional-css
|
# Read more: https://zensical.org/docs/customization/#additional-css
|
||||||
#
|
#
|
||||||
#extra_css = ["stylesheets/extra.css"]
|
extra_css = ["stylesheets/mermaid-override.css"]
|
||||||
|
|
||||||
# With the `extra_javascript` option you can add your own JavaScript to your
|
# With the `extra_javascript` option you can add your own JavaScript to your
|
||||||
# project to customize the behavior according to your needs.
|
# project to customize the behavior according to your needs.
|
||||||
@@ -65,7 +65,7 @@ Copyright © 2026 The authors
|
|||||||
# The path provided should be relative to the "docs_dir".
|
# The path provided should be relative to the "docs_dir".
|
||||||
#
|
#
|
||||||
# Read more: https://zensical.org/docs/customization/#additional-javascript
|
# Read more: https://zensical.org/docs/customization/#additional-javascript
|
||||||
#extra_javascript = ["javascripts/extra.js"]
|
extra_javascript = ["javascripts/mermaid-override.js"]
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Section for configuring theme options
|
# Section for configuring theme options
|
||||||
|
|||||||
Reference in New Issue
Block a user