Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

724 B
Raw Blame
export const MERMAID_LAYOUT_ATTR = "custom-mermaid-layout";

export type TMermaidLayout = "dagre" | "cose-bilkent" | "tidy-tree";

const MERMAID_LAYOUTS = new Set<TMermaidLayout>([
    "dagre",
    "cose-bilkent",
    "tidy-tree",
]);

export const getMermaidLayout = (value?: string | null): TMermaidLayout | undefined => {
    const layout = value?.trim().toLowerCase() as TMermaidLayout;
    return MERMAID_LAYOUTS.has(layout) ? layout : undefined;
};

export const applyMermaidLayout = (content: string, layout?: TMermaidLayout) => {
    if (!layout) {
        return content;
    }
    const separator = content.endsWith("\n") ? "" : "\n";
    return `${content}${separator}%%{init: ${JSON.stringify({layout})}}%%`;
};