mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
强烈谴责fps格式内嵌katex-html,div和stylesheet的行为
This commit is contained in:
1 parent
32a4f5eb4e
commit
0b0c34b0c6
6 files changed
+66
-9
No files matched your search
@@ -2,17 +2,15 @@
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import fs from 'fs-extra';
|
||||
import TurndownService from 'turndown';
|
||||
import AdmZip from 'adm-zip';
|
||||
import xml2js from 'xml2js';
|
||||
import { LocalProblemConfig } from 'hydrooj';
|
||||
import { convertHTML } from '@hydrooj/html2md';
|
||||
import {
|
||||
Route, Handler, param, Types,
|
||||
} from 'hydrooj/dist/service/server';
|
||||
import { PERM } from 'hydrooj/dist/model/builtin';
|
||||
|
||||
const turndownService = new TurndownService();
|
||||
|
||||
class FpsProblemImportHandler extends Handler {
|
||||
async get() {
|
||||
this.response.template = 'problem_import_fps.html';
|
||||
@@ -28,19 +26,19 @@ class FpsProblemImportHandler extends Handler {
|
||||
if (p.description) {
|
||||
content.push(
|
||||
this.translate('problem.import.problem_description'),
|
||||
p.description.map((i) => turndownService.turndown(i)).join('\n'),
|
||||
p.description.map(convertHTML).join('\n'),
|
||||
);
|
||||
}
|
||||
if (p.input) {
|
||||
content.push(
|
||||
this.translate('problem.import.input_format'),
|
||||
p.input.map((i) => turndownService.turndown(i)).join('\n'),
|
||||
p.input.map(convertHTML).join('\n'),
|
||||
);
|
||||
}
|
||||
if (p.output) {
|
||||
content.push(
|
||||
this.translate('problem.import.output_format'),
|
||||
p.output.map((i) => turndownService.turndown(i)).join('\n'),
|
||||
p.output.map(convertHTML).join('\n'),
|
||||
);
|
||||
}
|
||||
if (p.sample_input) {
|
||||
@@ -60,7 +58,7 @@ class FpsProblemImportHandler extends Handler {
|
||||
if (p.hint) {
|
||||
content.push(
|
||||
this.translate('problem.import.hint'),
|
||||
p.hint.map((i) => turndownService.turndown(i)).join('\n'),
|
||||
p.hint.map(convertHTML).join('\n'),
|
||||
);
|
||||
}
|
||||
const config: LocalProblemConfig = {
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"@hydrooj/html2md": "^1.0.0",
|
||||
"adm-zip": "^0.4.16",
|
||||
"fs-extra": "^9.0.1",
|
||||
"hydrooj": "^2.12.22",
|
||||
"turndown": "^6.0.0",
|
||||
"xml2js": "^0.4.23"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/turndown": "^5.0.0",
|
||||
"@types/xml2js": "^0.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'hydrooj';
|
||||
import TurndownService from 'turndown';
|
||||
import { JSDOM } from 'jsdom';
|
||||
|
||||
const turndownService = new TurndownService();
|
||||
|
||||
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);
|
||||
});
|
||||
return turndownService.turndown(DOM.serialize());
|
||||
}
|
||||
|
||||
global.Hydro.lib.convertHTML = convertHTML;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@hydrooj/html2md",
|
||||
"version": "1.0.0",
|
||||
"description": "turn html into markdown",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"hydrooj": "^2.12.22",
|
||||
"jsdom": "^16.4.0",
|
||||
"turndown": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "^16.2.3",
|
||||
"@types/turndown": "^5.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "eslint . --ext ts --fix"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2019",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"composite": true,
|
||||
"strictBindCallApply": true,
|
||||
"experimentalDecorators": true,
|
||||
"outDir": ".",
|
||||
"rootDir": "."
|
||||
},
|
||||
"include": [
|
||||
"*.ts"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
{ "path": "packages/hydrooj" },
|
||||
{ "path": "packages/hydrojudge" },
|
||||
{ "path": "packages/geoip" },
|
||||
{ "path": "packages/html2md" },
|
||||
{ "path": "packages/fps-importer" },
|
||||
{ "path": "packages/login-with-github" },
|
||||
{ "path": "packages/login-with-google" },
|
||||
{ "path": "packages/login-with-osu" },
|
||||
|
||||
Reference in new issue
Block a user