Skip to content

Sanitize and expose statement HTML for math rendering; add client-side math renderer#54

Merged
enlorik merged 2 commits into
mainfrom
codex/fix-math-rendering-in-codeforces-statements-lqcjdy
Jun 23, 2026
Merged

Sanitize and expose statement HTML for math rendering; add client-side math renderer#54
enlorik merged 2 commits into
mainfrom
codex/fix-math-rendering-in-codeforces-statements-lqcjdy

Conversation

@enlorik

@enlorik enlorik commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Preserve Codeforces pre-rendered math markup (e.g. tex-span, superscripts, subscripts) for client-side rendering while removing unsafe tags and attributes.
  • Provide a safe HTML fragment alongside plain-text fields so the frontend can render math and richer markup without leaking scripts or event handlers.

Description

  • Add a conservative sanitizer safeHtml to cfStatementParser.js that whitelists allowed tags and class prefixes and strips scripts, styles and other attributes, and return new HTML fields statementHtml, inputSpecificationHtml, and outputSpecificationHtml alongside existing text fields.
  • Update cfStatementParser.test.js to expect the new HTML fields and to verify preservation of sanitized math markup.
  • Add client-side utilities in src/utils/renderMath.js providing escapeHtml, normalizeLatex, renderMathExpression, renderMathInHtml, and textToHtml to convert LaTeX-like delimiters to safe HTML and to turn plain text into paragraph HTML.
  • Integrate server-provided HTML into the workspace by adding StatementHtml in ProblemWorkspace.jsx which uses renderMathInHtml and textToHtml as a fallback, and wire the statement/input/output sections to use the new HTML fields.
  • Add styling in ProblemWorkspace.css for .problem-workspace-stmt-text, .tex-span, .problem-workspace-math and related elements.
  • Add src/utils/renderMath.test.js with unit tests for math rendering and update parser tests accordingly.

Testing

  • Ran the updated parser unit tests in cfStatementParser.test.js under the test runner and they succeeded.
  • Ran the new renderMath unit tests in src/utils/renderMath.test.js and they succeeded.
  • The combined test suite (Vitest) completed without failures.

Codex Task

@enlorik
enlorik marked this pull request as ready for review June 23, 2026 20:58
@enlorik
enlorik merged commit 113bcab into main Jun 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant