From 22655baad8207c30fe12e6345ecf45d21a8fcc24 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 20 Feb 2023 19:14:15 +0800 Subject: [PATCH] feat(apps/html2markdown): katex support --- web/app/controllers/apps/html2markdown.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/web/app/controllers/apps/html2markdown.php b/web/app/controllers/apps/html2markdown.php index d0c02f7..e3b0004 100644 --- a/web/app/controllers/apps/html2markdown.php +++ b/web/app/controllers/apps/html2markdown.php @@ -93,6 +93,33 @@ } }); + turndownService.addRule('katexInline', { + filter: function(node) { + return node.nodeName === 'SPAN' && node.getAttribute('class') === 'katex'; + }, + + escapeContent: function() { + return false; + }, + + replacement: function(content, node, options) { + return '$' + $('.katex-mathml annotation[encoding="application/x-tex"]', node).html() + '$'; + } + }); + turndownService.addRule('katexInline', { + filter: function(node) { + return node.nodeName === 'SPAN' && node.getAttribute('class') === 'katex-display'; + }, + + escapeContent: function() { + return false; + }, + + replacement: function(content, node, options) { + return '$$\n' + $('.katex-mathml annotation[encoding="application/x-tex"]', node).html() + '\n$$'; + } + }); + $(document).ready(function() { $('#html').on('input', function() { $('#markdown').val(turndownService.turndown($('#html').val()));