Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/markdown): handle markup in note title

Elian Doran27ccc56b6d41
diff --git a/docs/Release Notes/Release Notes/v0.92.8-beta.md b/docs/Release Notes/Release Notes/v0.92.8-beta.md
index b3f3158fec..791a1af620 100644
--- a/docs/Release Notes/Release Notes/v0.92.8-beta.md
+++ b/docs/Release Notes/Release Notes/v0.92.8-beta.md
@@ -15,9 +15,10 @@
## ✨ Improvements
* Add week note and quarter note support by @JYC333
-* Markdown export:
+* Markdown import/export:
* Reduce extra whitespace between list items.
* Preserve include note.
+ * Handle note titles that contain inline code.
* In-app help:
* Document structure is now precalculated, so start-up time should be slightly increased.
* Optimized the content in order to reduce the size on disk.
diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.ts
index 429e61b67a..02d0a81e86 100644
--- a/src/services/import/markdown.spec.ts
+++ b/src/services/import/markdown.spec.ts
@@ -44,11 +44,18 @@ describe("markdown", () => {
});
it("parses duplicate title with escape correctly", () => {
- const result = markdownService.renderToHtml(trimIndentation`\
- # What's new
- Hi there
- `, "What's new")
- expect(result).toBe(`<p>Hi there</p>`);
+ const titles = [
+ "What's new",
+ "Node.js, Electron and `better-sqlite3`"
+ ];
+
+ for (const title of titles) {
+ const result = markdownService.renderToHtml(trimIndentation`\
+ # ${title}
+ Hi there
+ `, title)
+ expect(result).toBe(`<p>Hi there</p>`);
+ }
});
it("trims unnecessary whitespace", () => {
diff --git a/src/services/import/markdown.ts b/src/services/import/markdown.ts
index e9554c2f57..d84deb0432 100644
--- a/src/services/import/markdown.ts
+++ b/src/services/import/markdown.ts
@@ -8,6 +8,11 @@ import { parse, Renderer, type Tokens } from "marked";
class CustomMarkdownRenderer extends Renderer {
heading(data: Tokens.Heading): string {
+ // Treat h1 as raw text.
+ if (data.depth === 1) {
+ return `<h1>${data.text}</h1>`;
+ }
+
return super.heading(data).trimEnd();
}