添加html支持

This commit is contained in:
undefined committed 2020-09-02 13:32:47 +08:00
1 parent 0b0c34b0c6
commit 3f2d98534f
9 files changed
+73 -20

No files matched your search

+9 -3
View File
@@ -2,14 +2,20 @@ import 'hydrooj';
import TurndownService from 'turndown';
import { JSDOM } from 'jsdom';
const turndownService = new TurndownService();
const turndownService = new TurndownService({
headingStyle: 'atx',
codeBlockStyle: 'fenced',
bulletListMarker: '-',
});
export function convertHTML(html: string) {
const DOM = new JSDOM(html);
const eles = DOM.window.document.querySelectorAll('span.katex-mathml');
eles.forEach((ele) => {
const MathML = ele.innerHTML;
ele.parentElement.replaceWith(MathML);
const MathML = ele.innerHTML
.replace(/\\{/gmi, '{')
.replace(/\\}/gmi, '}');
ele.parentElement.replaceWith(`$${MathML}$`);
});
return turndownService.turndown(DOM.serialize());
}