Skip to content

Commit e33e052

Browse files
committed
add cses and atcoder parsers
1 parent 53f0d28 commit e33e052

File tree

4 files changed

+830
-0
lines changed

4 files changed

+830
-0
lines changed

src/components/Editor/parsers/ac.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// example url: https://atcoder.jp/contests/arc084/tasks/arc084_b
2+
export default function parseAc(url: string, html: string) {
3+
const titleRegex = /<span class="h2">[\r\n\t]+(.*?)[\r\n\t]+/;
4+
const name = html.match(titleRegex)?.[1].split('-', 2)[1] ?? 'Unknown';
5+
const uniqueId = `ac-${name.replace(/ /g, '').toLowerCase()}`;
6+
return {
7+
uniqueId,
8+
name,
9+
source: 'AC',
10+
solutionMetadata: {
11+
kind: 'CHANGE THIS',
12+
},
13+
};
14+
}

src/components/Editor/parsers/cses.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// example url: https://cses.fi/problemset/task/1083
2+
export default function parseCses(url: string, html: string) {
3+
const urlSplit = url.split('/');
4+
const problemId = urlSplit.at(-1);
5+
const titleRegex = /<h1>(.*?)<\/h1>/;
6+
return {
7+
uniqueId: `cses-${problemId}`, // e.g. cses-1083
8+
name: html.match(titleRegex)?.[1] ?? 'Unknown',
9+
source: 'CSES',
10+
solutionMetadata: {
11+
kind: 'CHANGE THIS',
12+
},
13+
};
14+
}

src/components/Editor/parsers/parse.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import parseAc from './ac';
12
import parseCf from './cf';
3+
import parseCses from './cses';
24
import parseUsaco from './usaco';
35
export const parsers = {
46
'codeforces.com': parseCf,
57
'usaco.org': parseUsaco,
8+
'cses.fi': parseCses,
9+
'atcoder.jp': parseAc,
610
};
711
export default function parse(url: string, html: string) {
812
for (const [domain, parser] of Object.entries(parsers)) {

0 commit comments

Comments
 (0)