From 5052a9ea409aa93fbe9e742bbaae28a953a7b8de Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 22 Jul 2024 13:20:00 +0100 Subject: [PATCH] Support math export in Markdown --- .../src/integrations/export/turndown-utils.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/server/src/integrations/export/turndown-utils.ts b/apps/server/src/integrations/export/turndown-utils.ts index 3f720508..a7cf514c 100644 --- a/apps/server/src/integrations/export/turndown-utils.ts +++ b/apps/server/src/integrations/export/turndown-utils.ts @@ -21,6 +21,8 @@ export function turndown(html: string): string { toggleListTitle, toggleListBody, listParagraph, + mathInline, + mathBlock, ]); return turndownService.turndown(html).replaceAll('
', ' '); @@ -98,3 +100,31 @@ function toggleListBody(turndownService: TurndownService) { }, }); } + +function mathInline(turndownService: TurndownService) { + turndownService.addRule('mathInline', { + filter: function (node: HTMLInputElement) { + return ( + node.nodeName === 'SPAN' && + node.getAttribute('data-type') === 'mathInline' + ); + }, + replacement: function (content: any, node: HTMLInputElement) { + return `$${content}$`; + }, + }); +} + +function mathBlock(turndownService: TurndownService) { + turndownService.addRule('mathBlock', { + filter: function (node: HTMLInputElement) { + return ( + node.nodeName === 'DIV' && + node.getAttribute('data-type') === 'mathBlock' + ); + }, + replacement: function (content: any, node: HTMLInputElement) { + return `$$${content}$$`; + }, + }); +}