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
feat(mermaid): add basic syntax highlight
Elian Doran58b9d9074e0e
diff --git a/apps/client/src/widgets/type_widgets/abstract_split_type_widget.ts b/apps/client/src/widgets/type_widgets/abstract_split_type_widget.tsindex 3b1cb222b9..c3cd63272e 100644--- a/apps/client/src/widgets/type_widgets/abstract_split_type_widget.ts+++ b/apps/client/src/widgets/type_widgets/abstract_split_type_widget.ts@@ -8,6 +8,7 @@ import options from "../../services/options.js";import type SwitchSplitOrientationButton from "../floating_buttons/switch_layout_button.js";import type { EventData } from "../../components/app_context.js";import type OnClickButtonWidget from "../buttons/onclick_button.js";+import type { EditorConfig } from "@triliumnext/codemirror";const TPL = /*html*/`\<div class="note-detail-split note-detail-printable">@@ -242,7 +243,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {/*** Called upon when the code editor is being initialized. Can be used to add additional options to the editor.*/- buildEditorExtraOptions(): Partial<CodeMirrorOpts> {+ buildEditorExtraOptions(): Partial<EditorConfig> {return {lineWrapping: false};diff --git a/apps/client/src/widgets/type_widgets/mermaid.ts b/apps/client/src/widgets/type_widgets/mermaid.tsindex 50353e230b..c8642c9932 100644--- a/apps/client/src/widgets/type_widgets/mermaid.ts+++ b/apps/client/src/widgets/type_widgets/mermaid.ts@@ -1,3 +1,4 @@+import type { EditorConfig } from "@triliumnext/codemirror";import { getMermaidConfig, loadElkIfNeeded, postprocessMermaidSvg } from "../../services/mermaid.js";import AbstractSvgSplitTypeWidget from "./abstract_svg_split_type_widget.js";diff --git a/docs/Release Notes/Release Notes/v0.94.0.md b/docs/Release Notes/Release Notes/v0.94.0.mdindex 18062acc7b..ecc1e08c05 100644--- a/docs/Release Notes/Release Notes/v0.94.0.md+++ b/docs/Release Notes/Release Notes/v0.94.0.md@@ -26,6 +26,7 @@* [Make it show which node triggered the event when right-clicking on tree](https://github.com/TriliumNext/Notes/pull/1861) by @SiriusXT* [Only expand/collapse the left pane of the focused window](https://github.com/TriliumNext/Notes/pull/1905) by @SiriusXT* Code notes now have support for GDScript (Godot).+* Mermaid diagrams: basic syntax highlight (not all diagram types are supported) and code folding.## 📖 Documentationdiff --git a/packages/codemirror/package.json b/packages/codemirror/package.jsonindex 6982b5f29a..244b513ed3 100644--- a/packages/codemirror/package.json+++ b/packages/codemirror/package.json@@ -35,6 +35,7 @@"@ssddanbrown/codemirror-lang-smarty": "1.0.0","@ssddanbrown/codemirror-lang-twig": "1.0.0","codemirror-lang-hcl": "0.1.0",+ "codemirror-lang-mermaid": "0.5.0","eslint-linter-browserify": "9.26.0"}}diff --git a/packages/codemirror/src/syntax_highlighting.ts b/packages/codemirror/src/syntax_highlighting.tsindex ca10bd9f27..eb04b4955a 100644--- a/packages/codemirror/src/syntax_highlighting.ts+++ b/packages/codemirror/src/syntax_highlighting.ts@@ -17,6 +17,11 @@ async function buildJavaScript(mimeType: string) {return extensions;}+async function buildMermaid() {+ const { mermaid, foldByIndent } = (await import('codemirror-lang-mermaid'));+ return [ mermaid(), foldByIndent() ];+}+const byMimeType: Record<string, (() => Promise<StreamParser<unknown> | LanguageSupport | Extension[]>) | null> = {"text/plain": null,@@ -55,6 +60,8 @@ const byMimeType: Record<string, (() => Promise<StreamParser<unknown> | Language"text/typescript-jsx": async () => (await import('@codemirror/lang-javascript')).javascript({ typescript: true, jsx: true }),"text/vbscript": async () => (await import('@codemirror/legacy-modes/mode/vbscript')).vbScript,"text/velocity": async () => (await import('@codemirror/legacy-modes/mode/velocity')).velocity,+ "text/vnd.mermaid": async () => buildMermaid(),+ "text/mermaid": async () => buildMermaid(),"text/x-asm-mips": null,"text/x-asterisk": async () => (await import('@codemirror/legacy-modes/mode/asterisk')).asterisk,"text/x-brainfuck": async () => (await import('@codemirror/legacy-modes/mode/brainfuck')).brainfuck,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 2ad7918e72..e2d16b2d4f 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1199,6 +1199,9 @@ importers:codemirror-lang-hcl:specifier: 0.1.0version: 0.1.0+ codemirror-lang-mermaid:+ specifier: 0.5.0+ version: 0.5.0eslint-linter-browserify:specifier: 9.26.0version: 9.26.0@@ -6441,6 +6444,9 @@ packages:resolution: {integrity: sha512-duwKEaQDhkJWad4YQ9pv4282BS6hCdR+gS/qTAj3f9bypXNNZ42bIN43h9WK3DjyZRENtVlUQdrQM1sA44wHmA==}+ resolution: {integrity: sha512-Taw/2gPCyNArQJCxIP/HSUif+3zrvD+6Ugt7KJZ2dUKou/8r3ZhcfG8krNTZfV2iu8AuGnymKuo7bLPFyqsh/A==}+resolution: {integrity: sha512-+aFkvqhaAVr1gferNMuN8vkTSrWIFvzlMV9I2KBLCWS2WpZ2+UAkZjlMZmEuT+gcXTi6RrGQCkWq1/bDtGqhIA==}@@ -22058,6 +22064,12 @@ snapshots:'@lezer/highlight': 1.2.1'@lezer/lr': 1.4.2+ dependencies:+ '@codemirror/language': 6.11.0+ '@lezer/highlight': 1.2.1+ '@lezer/lr': 1.4.2+