Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
markdown editor/slash commands: add templates for Mermaid diagrams
Adorian Doran655a6aea6e76
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex d64fa47550..b3489da40d 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -265,6 +265,7 @@"math": "Insert a math equation block","footnote": "Insert a footnote","mermaid": "Insert a Mermaid diagram",+ "mermaid_template": "Insert a \"{{name}}\" Mermaid diagram","collapsible": "Insert a collapsible block","admonition": "Insert {{type}} admonition","todo": "Insert a \"{{title}}\" task item",diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.tsx b/apps/client/src/widgets/type_widgets/code/Markdown.tsxindex b4fe21e9f8..f3f3680457 100644--- a/apps/client/src/widgets/type_widgets/code/Markdown.tsx+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx@@ -27,6 +27,7 @@ import tree from "../../../services/tree";import utils, { isDesktop } from "../../../services/utils";import { useLegacyImperativeHandlers, useTriliumEvent } from "../../react/hooks";import SplitEditor from "../helpers/SplitEditor";+import SAMPLE_DIAGRAMS from "../mermaid/sample_diagrams";import { ReadOnlyTextContent } from "../text/ReadOnlyText";import { TypeWidgetProps } from "../type_widget";@@ -615,6 +616,19 @@ function useSlashCommands(parentComponent: TypeWidgetProps["parentComponent"], e});}},+ // One `/mermaid:<type>` per sample diagram (e.g. `/mermaid:flowchart`),+ // pre-filling the fenced block with that template's source.+ ...SAMPLE_DIAGRAMS.map((sample) => ({+ label: `/mermaid:${sample.name.toLowerCase().replace(/\s+/g, "-")}`,+ detail: t("markdown_slash_commands.mermaid_template", { name: sample.name }),+ apply(view: import("@codemirror/view").EditorView, _c: unknown, from: number, to: number) {+ const template = `\`\`\`mermaid\n${sample.content.trimEnd()}\n\`\`\``;+ view.dispatch({+ changes: { from, to, insert: template },+ selection: { anchor: from + 11 }+ });+ }+ })),{label: "/collapsible",detail: t("markdown_slash_commands.collapsible"),