diff --git a/src/services/export/markdown.spec.ts b/src/services/export/markdown.spec.ts
index 0419e1765..2a4e5fbf1 100644
--- a/src/services/export/markdown.spec.ts
+++ b/src/services/export/markdown.spec.ts
@@ -268,4 +268,15 @@ describe("Markdown export", () => {
}
});
+ it("preserves figures", () => {
+ const html = /*html*/trimIndentation`\
+
+
+
+ `;
+ const expected = `
`;
+ expect(markdownExportService.toMarkdown(html)).toBe(expected);
+ });
+
});
diff --git a/src/services/export/markdown.ts b/src/services/export/markdown.ts
index f3fb9f9fc..fd125d0f6 100644
--- a/src/services/export/markdown.ts
+++ b/src/services/export/markdown.ts
@@ -45,6 +45,7 @@ function toMarkdown(content: string) {
instance.addRule("img", buildImageFilter());
instance.addRule("admonition", buildAdmonitionFilter());
instance.addRule("inlineLink", buildInlineLinkFilter());
+ instance.addRule("figure", buildFigureFilter());
instance.use(gfm);
instance.keep([ "kbd" ]);
}
@@ -195,6 +196,17 @@ function buildInlineLinkFilter(): Rule {
}
}
+function buildFigureFilter(): Rule {
+ return {
+ filter(node, options) {
+ return node.nodeName === 'FIGURE'
+ },
+ replacement(content, node) {
+ return (node as HTMLElement).outerHTML;
+ }
+ }
+}
+
// Taken from upstream since it's not exposed.
// https://github.com/mixmark-io/turndown/blob/master/src/commonmark-rules.js
function cleanAttribute(attribute: string | null | undefined) {