e30e75b5d4
Changesets / Create Version PR (push) Has been cancelled
Deploy Shadcn Registry / Deploy Production (push) Has been cancelled
Template Metrics / LOC + Bundle Size (push) Has been cancelled
Code Quality / Oxlint + Oxfmt (push) Has been cancelled
Code Quality / Template Sync (push) Has been cancelled
Code Quality / Build Changed Packages (push) Has been cancelled
Code Quality / Test Changed Packages (push) Has been cancelled
Deploy Expo Example / Deploy Production (push) Has been cancelled
Deploy Ink Example / Deploy Production (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.12) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Has been cancelled
52 lines
1.0 KiB
TypeScript
52 lines
1.0 KiB
TypeScript
import { visit } from "unist-util-visit";
|
|
|
|
interface CodeNode {
|
|
type: "code";
|
|
lang?: string | null;
|
|
value: string;
|
|
}
|
|
|
|
interface Parent {
|
|
children: Array<{ type: string }>;
|
|
}
|
|
|
|
interface MdxJsxFlowElement {
|
|
type: "mdxJsxFlowElement";
|
|
name: string;
|
|
attributes: never[];
|
|
children: Array<{ type: "text"; value: string }>;
|
|
}
|
|
|
|
export function remarkMermaid() {
|
|
return (tree: unknown) => {
|
|
visit(
|
|
tree as never,
|
|
"code",
|
|
(
|
|
node: CodeNode,
|
|
index: number | undefined,
|
|
parent: Parent | undefined,
|
|
) => {
|
|
if (
|
|
node.lang !== "mermaid" ||
|
|
!node.value.trim() ||
|
|
parent === undefined ||
|
|
index === undefined
|
|
)
|
|
return;
|
|
|
|
const element: MdxJsxFlowElement = {
|
|
type: "mdxJsxFlowElement",
|
|
name: "MermaidDiagram",
|
|
attributes: [],
|
|
children: [{ type: "text", value: node.value }],
|
|
};
|
|
|
|
parent.children[index] = element;
|
|
},
|
|
);
|
|
};
|
|
}
|
|
|
|
export default remarkMermaid;
|