mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 17:31:09 +10:00
turndown video tag
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import * as TurndownService from '@joplin/turndown';
|
import * as TurndownService from '@joplin/turndown';
|
||||||
import * as TurndownPluginGfm from '@joplin/turndown-plugin-gfm';
|
import * as TurndownPluginGfm from '@joplin/turndown-plugin-gfm';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
export function turndown(html: string): string {
|
export function turndown(html: string): string {
|
||||||
const turndownService = new TurndownService({
|
const turndownService = new TurndownService({
|
||||||
@ -23,6 +24,7 @@ export function turndown(html: string): string {
|
|||||||
mathInline,
|
mathInline,
|
||||||
mathBlock,
|
mathBlock,
|
||||||
iframeEmbed,
|
iframeEmbed,
|
||||||
|
video,
|
||||||
]);
|
]);
|
||||||
return turndownService.turndown(html).replaceAll('<br>', ' ');
|
return turndownService.turndown(html).replaceAll('<br>', ' ');
|
||||||
}
|
}
|
||||||
@ -87,8 +89,12 @@ function preserveDetail(turndownService: TurndownService) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const detailsContent = Array.from(node.childNodes)
|
const detailsContent = Array.from(node.childNodes)
|
||||||
.filter(child => child.nodeName !== 'SUMMARY')
|
.filter((child) => child.nodeName !== 'SUMMARY')
|
||||||
.map(child => (child.nodeType === 1 ? turndownService.turndown((child as HTMLElement).outerHTML) : child.textContent))
|
.map((child) =>
|
||||||
|
child.nodeType === 1
|
||||||
|
? turndownService.turndown((child as HTMLElement).outerHTML)
|
||||||
|
: child.textContent,
|
||||||
|
)
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
return `\n<details>\n${detailSummary}\n\n${detailsContent}\n\n</details>\n`;
|
return `\n<details>\n${detailSummary}\n\n${detailsContent}\n\n</details>\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 + ')';
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user