mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
24 lines
677 B
TypeScript
24 lines
677 B
TypeScript
import 'hydrooj';
|
|
import TurndownService from 'turndown';
|
|
import { JSDOM } from 'jsdom';
|
|
|
|
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
|
|
.replace(/\\{/gmi, '{')
|
|
.replace(/\\}/gmi, '}');
|
|
ele.parentElement.replaceWith(`$${MathML}$`);
|
|
});
|
|
return turndownService.turndown(DOM.serialize());
|
|
}
|
|
|
|
global.Hydro.lib.convertHTML = convertHTML;
|