fix(export/markdown): fix code in tables

This commit is contained in:
Elian Doran 2025-03-19 18:42:40 +02:00
parent 884c5986ec
commit f23b45318d
No known key found for this signature in database
2 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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);
});
});