mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
feat(markdown): preserve figures
This commit is contained in:
parent
319cccfb15
commit
c80d016305
@ -268,4 +268,15 @@ describe("Markdown export", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves figures", () => {
|
||||
const html = /*html*/trimIndentation`\
|
||||
<figure class="image">
|
||||
<img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991"
|
||||
height="403">
|
||||
</figure>
|
||||
`;
|
||||
const expected = `<figure class="image"><img style="aspect-ratio:991/403;" src="Jump to Note_image.png" width="991" height="403"></figure>`;
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user