Skip to content

codingame_tools.puzzle_manager.statement_render

statement_render

Render a puzzle's cached HTML statement (.meta/statement.html, see codingame_tools. puzzle_manager.manager.CgPuzzleManager.statement_file) as an ordered list of plain-text display blocks, for cg puzzle description.

Purpose-built for CodinGame's specific puzzle-statement HTML structure (observed live, 2026-08-01)--not a general HTML-to-text converter:

<div class="statement-section statement-goal">
  <h2><span class="icon icon-goal">&nbsp;</span><span>Goal</span></h2>
  <span class="question-statement">paragraph text, <br><br> = paragraph break, inline
    <strong>/<var> emphasis ignored (just their text kept)</span>
</div>
<div class="statement-section statement-protocol">
  <div class="blk">
    <div class="title">Input</div>
    <div class="question-statement-input">description, <br> = single line break</div>
  </div>
  <div class="blk">...Output...</div>
  <div class="blk">...Constraints...</div>
  <div class="blk">
    <div class="title">Example</div>
    <div class="statement-inout">
      <div class="statement-inout-in">
        <div class="title">Input</div>
        <pre class="question-statement-example-in">literal test input</pre>
      </div>
      <div class="statement-inout-out">
        <div class="title">Output</div>
        <pre class="question-statement-example-out">literal expected output</pre>
      </div>
    </div>
  </div>
</div>

Every <div class="title"> (at any nesting depth) becomes a "header" block--this handles the top-level Input/Output/Constraints/Example titles and the nested Example Input/Output titles uniformly, with no special-casing needed. <br> is rendered as a literal newline, letting the source's own single-vs-double-<br> choices (line break vs. paragraph break) carry through unchanged--confirmed live to reproduce the intended structure (e.g. "Wanted elements"/"Wanted needle" reading as isolated sub-headings purely because they're <br><br>-surrounded within the single Goal paragraph, not because <strong> is treated specially--it isn't).

CgStatementBlock dataclass

CgStatementBlock(kind, text)

A single rendered block of a puzzle's HTML statement--see parse_statement_html.

kind instance-attribute

kind

One of "header" (a section title, e.g. "Goal"/"Input"/"Output"/"Constraints"/"Example"), "text" (ordinary paragraph/description text--may itself contain internal blank lines, e.g. the Goal section's multiple paragraphs), "example_input", or "example_output" (the literal, whitespace-preserved example test-case text under an "Example" section).

text instance-attribute

text

The block's rendered plain text (HTML tags stripped, entities unescaped).

parse_statement_html

parse_statement_html(html)

Parse a puzzle's cached HTML statement into an ordered list of display blocks--see CgStatementBlock and the module docstring.

Source code in codingame_tools/puzzle_manager/statement_render.py
169
170
171
172
173
174
175
def parse_statement_html(html: str) -> list[CgStatementBlock]:
    """Parse a puzzle's cached HTML statement into an ordered list of display blocks--see
       `CgStatementBlock` and the module docstring."""
    parser = _StatementHTMLParser()
    parser.feed(html)
    parser.close()
    return parser.blocks