mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
feat(markdown): preserve image width/height attribute
This commit is contained in:
parent
1f98e75c54
commit
319cccfb15
@ -250,4 +250,22 @@ describe("Markdown export", () => {
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
it("converts image if it has no custom properties", () => {
|
||||
const html = /*html*/`<p><img src="Include Note_image.png"></p>`;
|
||||
const expected = ``;
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
});
|
||||
|
||||
it("preserves image verbatim if it has a width or height attribute", () => {
|
||||
const scenarios = [
|
||||
`<img src="Include Note_image.png" width="16" height="16">`,
|
||||
`<img src="Include Note_image.png" width="16">`,
|
||||
`<img src="Include Note_image.png" height="16">`
|
||||
];
|
||||
for (const expected of scenarios) {
|
||||
const html = /*html*/`<p>${expected}</p>`;
|
||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -97,7 +97,15 @@ function buildImageFilter() {
|
||||
|
||||
const imageFilter: TurndownService.Rule = {
|
||||
filter: "img",
|
||||
replacement(content, node) {
|
||||
replacement(content, _node) {
|
||||
const node = _node as HTMLElement;
|
||||
|
||||
// Preserve image verbatim if it has a width or height attribute.
|
||||
if (node.hasAttribute("width") || node.hasAttribute("height")) {
|
||||
return node.outerHTML;
|
||||
}
|
||||
|
||||
// TODO: Deduplicate with upstream.
|
||||
const untypedNode = (node as any);
|
||||
const alt = escapeMarkdown(cleanAttribute(untypedNode.getAttribute('alt')))
|
||||
const src = escapeLinkDestination(untypedNode.getAttribute('src') || '')
|
||||
|
Loading…
x
Reference in New Issue
Block a user