mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	feat(markdown): preserve image width/height attribute
This commit is contained in:
		| @@ -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') || '') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user