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(export/markdown): preserve include section
Elian Doran2e4524361bec
diff --git a/src/services/export/markdown.spec.ts b/src/services/export/markdown.spec.tsindex a344d975f6..37e9bd82a1 100644--- a/src/services/export/markdown.spec.ts+++ b/src/services/export/markdown.spec.ts@@ -315,4 +315,10 @@ describe("Markdown export", () => {expect(markdownExportService.toMarkdown(html)).toBe(expected);});+ it("preserves include note", () => {+ const html = /*html*/`<section class="include-note" data-note-id="i4A5g9iOg9I0" data-box-size="full"> </section>`;+ const expected = /*markdown*/`<section class="include-note" data-note-id="i4A5g9iOg9I0" data-box-size="full"> </section>`;+ expect(markdownExportService.toMarkdown(html)).toBe(expected);+ });+});diff --git a/src/services/export/markdown.ts b/src/services/export/markdown.tsindex c4c71eee2d..8f6e3fa009 100644--- a/src/services/export/markdown.ts+++ b/src/services/export/markdown.ts@@ -37,7 +37,15 @@ function toMarkdown(content: string) {if (instance === null) {instance = new TurndownService({headingStyle: "atx",- codeBlockStyle: "fenced"+ codeBlockStyle: "fenced",+ blankReplacement(content, node, options) {+ if (node.nodeName === "SECTION" && (node as HTMLElement).classList.contains("include-note")) {+ return (node as HTMLElement).outerHTML;+ }++ // Original implementation as per https://github.com/mixmark-io/turndown/blob/master/src/turndown.js.+ return ("isBlock" in node && node.isBlock) ? '\n\n' : ''+ }});// Filter is heavily based on: https://github.com/mixmark-io/turndown/issues/274#issuecomment-458730974instance.addRule("fencedCodeBlock", fencedCodeBlockFilter);@@ -46,7 +54,7 @@ function toMarkdown(content: string) {instance.addRule("inlineLink", buildInlineLinkFilter());instance.addRule("figure", buildFigureFilter());instance.addRule("math", buildMathFilter());- instance.addRule("li-1", buildListItemFilter());+ instance.addRule("li", buildListItemFilter());instance.use(gfm);instance.keep([ "kbd" ]);}