Skip to content

Build your personal knowledge base with Trilium Notes

fix(import/markdown): support wikilinks in other elements other than paragraphs

Elian Doran8d90231f76e0
diff --git a/apps/server/src/services/import/markdown.spec.ts b/apps/server/src/services/import/markdown.spec.ts
index 3bb56580cf..916d461cb7 100644
--- a/apps/server/src/services/import/markdown.spec.ts
+++ b/apps/server/src/services/import/markdown.spec.ts
@@ -287,4 +287,10 @@ $$`;
expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
});
+ it("supports wikilink in lists", () => {
+ const input = `- oh no my banana I bought on [[journal/monday]] has gone off! I’m taking it back to the [[other/shop]] for a refund`;
+ const expected = `<ul><li>oh no my banana I bought on <a class="reference-link" href="/journal/monday">journal/monday</a> has gone off! I’m taking it back to the <a class="reference-link" href="/other/shop">other/shop</a> for a refund</li></ul>`;
+ expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected);
+ });
+
});
diff --git a/apps/server/src/services/import/markdown.ts b/apps/server/src/services/import/markdown.ts
index 77b35eebaf..9546b06158 100644
--- a/apps/server/src/services/import/markdown.ts
+++ b/apps/server/src/services/import/markdown.ts
@@ -23,9 +23,7 @@ class CustomMarkdownRenderer extends Renderer {
}
override paragraph(data: Tokens.Paragraph): string {
- let text = super.paragraph(data).trimEnd();
- text = processWikiLinks(text);
- return text;
+ return super.paragraph(data).trimEnd();
}
override code({ text, lang }: Tokens.Code): string {
@@ -117,6 +115,12 @@ class CustomMarkdownRenderer extends Renderer {
return `<blockquote>${body}</blockquote>`;
}
+ text(token: Tokens.Text | Tokens.Escape): string {
+ let text = super.text(token);
+ text = processWikiLinks(text);
+ return text;
+ }
+
}
function renderToHtml(content: string, title: string) {