diff --git a/apps/server/src/integrations/export/turndown-utils.ts b/apps/server/src/integrations/export/turndown-utils.ts index 44e606f3..54fdef12 100644 --- a/apps/server/src/integrations/export/turndown-utils.ts +++ b/apps/server/src/integrations/export/turndown-utils.ts @@ -1,5 +1,6 @@ import * as TurndownService from '@joplin/turndown'; import * as TurndownPluginGfm from '@joplin/turndown-plugin-gfm'; +import * as path from 'path'; export function turndown(html: string): string { const turndownService = new TurndownService({ @@ -23,6 +24,7 @@ export function turndown(html: string): string { mathInline, mathBlock, iframeEmbed, + video, ]); return turndownService.turndown(html).replaceAll('
', ' '); } @@ -87,8 +89,12 @@ function preserveDetail(turndownService: TurndownService) { } const detailsContent = Array.from(node.childNodes) - .filter(child => child.nodeName !== 'SUMMARY') - .map(child => (child.nodeType === 1 ? turndownService.turndown((child as HTMLElement).outerHTML) : child.textContent)) + .filter((child) => child.nodeName !== 'SUMMARY') + .map((child) => + child.nodeType === 1 + ? turndownService.turndown((child as HTMLElement).outerHTML) + : child.textContent, + ) .join(''); return `\n
\n${detailSummary}\n\n${detailsContent}\n\n
\n`; @@ -135,3 +141,16 @@ function iframeEmbed(turndownService: TurndownService) { }, }); } + +function video(turndownService: TurndownService) { + turndownService.addRule('video', { + filter: function (node: HTMLInputElement) { + return node.tagName === 'VIDEO'; + }, + replacement: function (content: any, node: HTMLInputElement) { + const src = node.getAttribute('src') || ''; + const name = path.basename(src); + return '[' + name + '](' + src + ')'; + }, + }); +}