forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemStatement.tsx
More file actions
67 lines (61 loc) · 2.12 KB
/
Copy pathProblemStatement.tsx
File metadata and controls
67 lines (61 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { ChallengeContent } from "@/lib/challenges";
import { renderMarkdown } from "@/lib/markdown";
/**
* Server component — renders a challenge's public content (statement + structured
* sections) to styled HTML. Prose fields are Markdown, rendered to sanitized HTML
* on the server (no client-side Markdown library); element styling lives in the
* `.arena-prose` scope in globals.css so it re-themes in dark mode. Hidden tests
* are never passed here.
*/
export default async function ProblemStatement({
challenge,
}: {
challenge: ChallengeContent;
}) {
const [statement, inputFormat, outputFormat, constraints, sampleExplanations] =
await Promise.all([
renderMarkdown(challenge.statement),
renderMarkdown(challenge.inputFormat ?? ""),
renderMarkdown(challenge.outputFormat ?? ""),
renderMarkdown(challenge.constraints ?? ""),
Promise.all(challenge.samples.map((s) => renderMarkdown(s.explanation ?? ""))),
]);
return (
<div className="arena-prose">
<div dangerouslySetInnerHTML={{ __html: statement }} />
{inputFormat && (
<>
<h2>Input Format</h2>
<div dangerouslySetInnerHTML={{ __html: inputFormat }} />
</>
)}
{outputFormat && (
<>
<h2>Output Format</h2>
<div dangerouslySetInnerHTML={{ __html: outputFormat }} />
</>
)}
{constraints && (
<>
<h2>Constraints</h2>
<div dangerouslySetInnerHTML={{ __html: constraints }} />
</>
)}
{challenge.samples.map((sample, i) => (
<section key={i}>
<h2>Sample{challenge.samples.length > 1 ? ` ${i + 1}` : ""}</h2>
<div className="arena-io-label">Input</div>
<pre>{sample.input.replace(/\n+$/, "")}</pre>
<div className="arena-io-label">Output</div>
<pre>{sample.output.replace(/\n+$/, "")}</pre>
{sampleExplanations[i] && (
<>
<h3>Explanation</h3>
<div dangerouslySetInnerHTML={{ __html: sampleExplanations[i] }} />
</>
)}
</section>
))}
</div>
);
}