mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	feat(markdown): preserve figures
This commit is contained in:
		| @@ -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("img", buildImageFilter()); | ||||||
|         instance.addRule("admonition", buildAdmonitionFilter()); |         instance.addRule("admonition", buildAdmonitionFilter()); | ||||||
|         instance.addRule("inlineLink", buildInlineLinkFilter()); |         instance.addRule("inlineLink", buildInlineLinkFilter()); | ||||||
|  |         instance.addRule("figure", buildFigureFilter()); | ||||||
|         instance.use(gfm); |         instance.use(gfm); | ||||||
|         instance.keep([ "kbd" ]); |         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. | // Taken from upstream since it's not exposed. | ||||||
| // https://github.com/mixmark-io/turndown/blob/master/src/commonmark-rules.js | // https://github.com/mixmark-io/turndown/blob/master/src/commonmark-rules.js | ||||||
| function cleanAttribute(attribute: string | null | undefined) { | function cleanAttribute(attribute: string | null | undefined) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user