Skip to content

Build your personal knowledge base with Trilium Notes

fix(export/markdown): fix code in tables

Elian Doranf23b45318d22
diff --git a/packages/turndown-plugin-gfm/src/tables.js b/packages/turndown-plugin-gfm/src/tables.js
index 7bdc0ed367..4b202f2b4d 100644
--- a/packages/turndown-plugin-gfm/src/tables.js
+++ b/packages/turndown-plugin-gfm/src/tables.js
@@ -221,6 +221,7 @@ const tableShouldBeHtml = (tableNode, options) => {
'H6',
'HR',
'BLOCKQUOTE',
+ 'PRE'
];
// In general we should leave as HTML tables that include other tables. The
diff --git a/src/services/export/markdown.spec.ts b/src/services/export/markdown.spec.ts
index b0285b0465..6baa194a2f 100644
--- a/src/services/export/markdown.spec.ts
+++ b/src/services/export/markdown.spec.ts
@@ -193,4 +193,37 @@ describe("Markdown export", () => {
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
+ it("exports code in tables properly", () => {
+ const html = trimIndentation`\
+ <table>
+ <tr>
+ <td>
+ Row 1
+ </td>
+ <td>
+ <p>Allows displaying the value of one or more attributes in the calendar
+ like this:&nbsp;</p>
+ <p>
+ <img src="13_Calendar View_image.png" alt="">
+ </p>
+
+ <pre><code class="language-text-x-trilium-auto">#weight="70"
+ #Mood="Good"
+ #calendar:displayedAttributes="weight,Mood"</code></pre>
+ <p>It can also be used with relations, case in which it will display the
+ title of the target note:</p><pre><code class="language-text-x-trilium-auto">~assignee=@My assignee
+ #calendar:displayedAttributes="assignee"</code></pre>
+ </td>
+ </tr>
+ </table>
+ `;
+
+ const expected = trimIndentation`\
+ <div class="joplin-table-wrapper"><table><tbody><tr><td>Row 1</td><td><p>Allows displaying the value of one or more attributes in the calendar like this:&nbsp;</p><p><img src="13_Calendar View_image.png" alt=""></p><pre><code class="language-text-x-trilium-auto">#weight="70"
+ #Mood="Good"
+ #calendar:displayedAttributes="weight,Mood"</code></pre><p>It can also be used with relations, case in which it will display the title of the target note:</p><pre><code class="language-text-x-trilium-auto">~assignee=@My assignee
+ #calendar:displayedAttributes="assignee"</code></pre></td></tr></tbody></table></div>`;
+ expect(markdownExportService.toMarkdown(html)).toBe(expected);
+ });
+
});