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
fix(markdown): give tabs in separate list items their own source lines
Elian Doran70d075ac21f4
diff --git a/apps/client/src/widgets/type_widgets/markdown/Markdown.spec.ts b/apps/client/src/widgets/type_widgets/markdown/Markdown.spec.tsindex dad8b5a0f6..c3eed681a2 100644--- a/apps/client/src/widgets/type_widgets/markdown/Markdown.spec.ts+++ b/apps/client/src/widgets/type_widgets/markdown/Markdown.spec.ts@@ -441,6 +441,28 @@ describe("revealTabAtLine", () => {expect(activeTitles(el)).toEqual([ "A", "B2" ]);});+ it("tags the tabs of separate list items with their own lines", () => {+ const listSrc = [+ "- First", // 1+ "", // 2+ " === \"A\"", // 3+ "", // 4+ " a", // 5+ "", // 6+ "- Second", // 7+ "", // 8+ " === \"B\"", // 9+ "", // 10+ " b" // 11+ ].join("\n");+ const el = document.createElement("div");+ el.innerHTML = renderWithSourceLines(listSrc).html;+ const tabs = [ ...el.querySelectorAll<HTMLElement>("li section.trilium-tab") ];++ expect(tabs.map((tab) => tab.querySelector(".trilium-tab-title")?.textContent)).toEqual([ "A", "B" ]);+ expect(tabs.map((tab) => tab.dataset.tabSourceLine)).toEqual([ "3", "9" ]);+ });+it("leaves the tabs alone for a line outside the block", () => {const el = preview();revealTabAtLine(el, 13);diff --git a/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx b/apps/client/src/widgets/type_widgets/markdown/Markdown.tsxindex cfc5d72272..8f01f3574d 100644--- a/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx+++ b/apps/client/src/widgets/type_widgets/markdown/Markdown.tsx@@ -728,8 +728,10 @@ function collectTabLines(tokens: Token[], firstLine: number): number[] {tabLine += countNewlines(tab.raw);}} else if (token.type === "list") {+ let itemLine = line;for (const item of (token as Tokens.List).items) {- lines.push(...collectTabLines(item.tokens, line));+ lines.push(...collectTabLines(item.tokens, itemLine));+ itemLine += countNewlines(item.raw);}} else if (token.type === "blockquote") {lines.push(...collectTabLines((token as Tokens.Blockquote).tokens, line));