From ec533934dea0959f96e72a88d95c562158187b85 Mon Sep 17 00:00:00 2001
From: Philipinho <16838612+Philipinho@users.noreply.github.com>
Date: Fri, 23 May 2025 12:40:34 -0700
Subject: [PATCH] turndown video tag
---
.../src/integrations/export/turndown-utils.ts | 23 +++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
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 + ')';
+ },
+ });
+}