mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
feat: allow fps zipfile
This commit is contained in:
1 parent
efa3faea5d
commit
c0489546b8
5 files changed
+17
-51
No files matched your search
@@ -19,8 +19,21 @@ class FpsProblemImportHandler extends Handler {
|
||||
if (ufid) {
|
||||
const stream = await file.get(ufid);
|
||||
const buf = await streamToBuffer(stream);
|
||||
let input = buf.toString();
|
||||
try {
|
||||
await xml2js.parseStringPromise(input);
|
||||
} catch (e) {
|
||||
const zip = new AdmZip(buf);
|
||||
const entries = zip.getEntries();
|
||||
for (const entry of entries) {
|
||||
if (entry.entryName.endsWith('.xml')) {
|
||||
input = entry.getData().toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
await this.post({ domainId, input: buf.toString() });
|
||||
await this.post({ domainId, input });
|
||||
await file.del(ufid);
|
||||
} else this.response.template = 'problem_import_fps.html';
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/fps-importer",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"description": "Import FPS problems",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
+1
-10
@@ -1,6 +1,5 @@
|
||||
import 'hydrooj';
|
||||
import TurndownService from 'turndown';
|
||||
import { JSDOM } from 'jsdom';
|
||||
|
||||
const turndownService = new TurndownService({
|
||||
headingStyle: 'atx',
|
||||
@@ -9,15 +8,7 @@ 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
|
||||
.replace(/\\{/gmi, '{')
|
||||
.replace(/\\}/gmi, '}');
|
||||
ele.parentElement.replaceWith(`$${MathML}$`);
|
||||
});
|
||||
return turndownService.turndown(DOM.serialize());
|
||||
return turndownService.turndown(html);
|
||||
}
|
||||
|
||||
global.Hydro.lib.convertHTML = convertHTML;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/html2md",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "turn html into markdown",
|
||||
"main": "lib.js",
|
||||
"typings": "lib.d.ts",
|
||||
@@ -8,11 +8,9 @@
|
||||
"author": "undefined <masnn0@outlook.com>",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"jsdom": "^16.4.0",
|
||||
"turndown": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsdom": "^16.2.3",
|
||||
"@types/turndown": "^5.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -2,43 +2,7 @@ import 'hydrooj';
|
||||
import { convertHTML } from '@hydrooj/html2md/lib';
|
||||
|
||||
describe('html2md', () => {
|
||||
const Katex1 = `\
|
||||
<span class="katex">
|
||||
<span class="katex-mathml">nn</span>
|
||||
<span class="katex-html">
|
||||
<span class="strut"></span>
|
||||
<span class="strut bottom" style="vertical-align:0em;"></span>
|
||||
<span class="base textstyle uncramped">
|
||||
<span class="mord mathit">n</span>
|
||||
</span>
|
||||
</span>
|
||||
</span>`;
|
||||
const Katex2 = `\
|
||||
<span class="katex">
|
||||
<span class="katex-mathml">E={1,2,..,n}E=\\{1,2,..,n\\}</span>
|
||||
<span class="katex-html">
|
||||
<span class="strut"></span>
|
||||
<span class="strut bottom" style="vertical-align:-0.25em;"></span>
|
||||
<span class="base textstyle uncramped">
|
||||
<span class="mord mathit">E</span>
|
||||
<span class="mrel">=</span>
|
||||
<span class="mopen">{</span>
|
||||
<span class="mord mathrm">1</span>
|
||||
<span class="mpunct">,</span>
|
||||
<span class="mord mathrm">2</span>
|
||||
<span class="mpunct">,</span>
|
||||
<span class="mord mathrm">.</span>
|
||||
<span class="mord mathrm">.</span>
|
||||
<span class="mpunct">,</span>
|
||||
<span class="mord mathit">n</span>
|
||||
<span class="mclose">}</span>
|
||||
</span>
|
||||
</span>
|
||||
</span>`;
|
||||
|
||||
test('convertHTML', () => {
|
||||
expect(convertHTML('<h1>Test</h1><p>test</p>')).toStrictEqual('# Test\n\ntest');
|
||||
expect(convertHTML(Katex1)).toStrictEqual('$n$');
|
||||
expect(convertHTML(Katex2)).toStrictEqual('$E={1,2,..,n}$');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user