mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
添加html支持
This commit is contained in:
1 parent
0b0c34b0c6
commit
3f2d98534f
9 files changed
+73
-20
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user