You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
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;
|