Support math export in Markdown

This commit is contained in:
Philipinho
2024-07-22 13:20:00 +01:00
parent cd47c79d86
commit 5052a9ea40

View File

@ -21,6 +21,8 @@ export function turndown(html: string): string {
toggleListTitle,
toggleListBody,
listParagraph,
mathInline,
mathBlock,
]);
return turndownService.turndown(html).replaceAll('<br>', ' ');
@ -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}$$`;
},
});
}