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(linter/mermaid): better handling of zero position
Elian Doran8b08e67fdc9a
diff --git a/src/public/app/widgets/type_widgets/linters/mermaid.spec.ts b/src/public/app/widgets/type_widgets/linters/mermaid.spec.tsindex 1d0808f30e..458d1649a6 100644--- a/src/public/app/widgets/type_widgets/linters/mermaid.spec.ts+++ b/src/public/app/widgets/type_widgets/linters/mermaid.spec.ts@@ -21,22 +21,25 @@ describe("Mermaid linter", () => {expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));expect(result[0]).toMatchObject({from: { line: 0, col: 0 },- to: { line: 0, col: 0 }+ to: { line: 0, col: 1 }});});it("reports correctly basic arrow missing in diagram", async () => {const input = trimIndentation`\- stateDiagram-v2- [*] -> Still+ xychart-beta horizontal+ title "Percentage usge"+ x-axis [data, sys, usr, var]+ y-axis 0--->100+ bar [20, 70, 0, 0]`;const result = await validateMermaid(input);expect(result.length).toBe(1);- expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'SPACE'"));+ expect(result[0].message).toSatisfy((v: string) => v.includes("Expecting 'ARROW_DELIMITER'"));expect(result[0]).toMatchObject({- from: { line: 1, col: 0 },- to: { line: 1, col: 3 }+ from: { line: 3, col: 8 },+ to: { line: 3, col: 9 }});});});diff --git a/src/public/app/widgets/type_widgets/linters/mermaid.ts b/src/public/app/widgets/type_widgets/linters/mermaid.tsindex 0df2ee8244..34048ba600 100644--- a/src/public/app/widgets/type_widgets/linters/mermaid.ts+++ b/src/public/app/widgets/type_widgets/linters/mermaid.ts@@ -31,12 +31,12 @@ export async function validateMermaid(text: string) {const mermaidError = (e as MermaidParseError);const loc = mermaidError.hash.loc;- let firstCol = loc.first_column;- let lastCol = loc.last_column;- if (firstCol !== 0 && lastCol !== 0) {- firstCol = lastCol + 1;- lastCol = firstCol + 1;+ let firstCol = loc.first_column + 1;+ let lastCol = loc.last_column + 1;++ if (firstCol === 1 && lastCol === 1) {+ firstCol = 0;}return [