feat(html): tree construction, first slice (HtmlNode, HtmlDocument.parse) #716

Merged
argus merged 4 commits from loop/688-html-tree-construction into main 2026-11-12 18:26:53 +00:00
Collaborator

Closes #688

Step 2a of #79: the first slice of the tree construction of std/html.

What changes

  • HtmlNode (document, doctype, element, text, comment; ordered children), HtmlQuirksMode and HtmlDocument.parse(text) answering tree, quirks and errors (tokenizer and tree errors). It never fails; there is no Result.
  • Insertion modes initial, before html, before head, in head, after head, in body (no formatting elements, no tables), text, after body, after after body, plus the noscript branch of in head for scripting off. Implied html, head and body; the quirks mode comes from the doctype with the standard's full list of identifiers.
  • The tokenizer is switched for <script>, <style>, <textarea>, <title>, <plaintext>, <xmp>, <iframe>, <noembed>, <noframes>; a line feed after <pre>, <listing>, <textarea> is dropped. HtmlTokenizer.location() is new so the tree construction can place its own errors.
  • Elements the slice does not handle (tables, formatting elements, template, select, frameset, foreign content) are plain elements; this is documented in the page and the header of tree.trb.
  • html5lib-tests tree-construction vendored as std/html/tests/html5lib-tree/ (commit 9329e646, the last one that still has the directory; the tokenizer tests stay at their commit). tools/html/vendor.trb writes both; NOTICE.md says where they come from.
  • std/html/tests/tree.test.trb runs every covered case: 842 pass. The rest is a named skip list, counted by the test so it can not drift: fragment 192, scripting on 8, formatting element 127, table 194, foreign content 137, template 79, select or frameset 129 (the first matching reason).
  • Docs page section, lib.trb exports, docs/standard-library/index.md and the generated skills.

Not covered / deviations

  • The #errors of the cases are not compared (prose, not codes of the standard).
  • domjs-unsafe, plain-text-unsafe and pending-spec-changes-plain-text-unsafe are not vendored (CR and NUL do not survive a raw string and the formatter). In tests2.dat a line of one space is empty, no case depends on it.
  • The skip classifier looks at the start tags of the data and over-skips, e.g. a tag inside a comment or script.

Checked locally

torb test std/html (tree, document and the earlier suites), torb docs check docs, docs declarations --check, docs skill docs skills --check, torb format --check, tools/check-commits.sh. Gates run in CI.

Closes #688 Step 2a of #79: the first slice of the tree construction of `std/html`. ## What changes - `HtmlNode` (document, doctype, element, text, comment; ordered children), `HtmlQuirksMode` and `HtmlDocument.parse(text)` answering `tree`, `quirks` and `errors` (tokenizer and tree errors). It never fails; there is no `Result`. - Insertion modes `initial`, `before html`, `before head`, `in head`, `after head`, `in body` (no formatting elements, no tables), `text`, `after body`, `after after body`, plus the `noscript` branch of `in head` for scripting off. Implied `html`, `head` and `body`; the quirks mode comes from the doctype with the standard's full list of identifiers. - The tokenizer is switched for `<script>`, `<style>`, `<textarea>`, `<title>`, `<plaintext>`, `<xmp>`, `<iframe>`, `<noembed>`, `<noframes>`; a line feed after `<pre>`, `<listing>`, `<textarea>` is dropped. `HtmlTokenizer.location()` is new so the tree construction can place its own errors. - Elements the slice does not handle (tables, formatting elements, template, select, frameset, foreign content) are plain elements; this is documented in the page and the header of `tree.trb`. - html5lib-tests `tree-construction` vendored as `std/html/tests/html5lib-tree/` (commit `9329e646`, the last one that still has the directory; the tokenizer tests stay at their commit). `tools/html/vendor.trb` writes both; `NOTICE.md` says where they come from. - `std/html/tests/tree.test.trb` runs every covered case: **842 pass**. The rest is a named skip list, counted by the test so it can not drift: fragment 192, scripting on 8, formatting element 127, table 194, foreign content 137, template 79, select or frameset 129 (the first matching reason). - Docs page section, `lib.trb` exports, `docs/standard-library/index.md` and the generated skills. ## Not covered / deviations - The `#errors` of the cases are not compared (prose, not codes of the standard). - `domjs-unsafe`, `plain-text-unsafe` and `pending-spec-changes-plain-text-unsafe` are not vendored (CR and NUL do not survive a raw string and the formatter). In `tests2.dat` a line of one space is empty, no case depends on it. - The skip classifier looks at the start tags of the data and over-skips, e.g. a tag inside a comment or script. ## Checked locally `torb test std/html` (tree, document and the earlier suites), `torb docs check docs`, `docs declarations --check`, `docs skill docs skills --check`, `torb format --check`, `tools/check-commits.sh`. Gates run in CI.
HtmlNode, HtmlQuirksMode and HtmlDocument.parse(text): the insertion modes initial
to after after body of the WHATWG tree construction over the tokenizer, with
implied html, head and body, the quirks mode of the doctype, the tokenizer
switches of script, style, textarea, title and plaintext, and scripting off.
Tables, formatting elements, template, select, framesets and foreign content are
plain elements in this slice. HtmlTokenizer gets location() for the errors of the
tree construction. Docs page, skills and lib exports follow.
test(html): vendor the html5lib tree construction tests
Some checks failed
ci / commit messages (pull_request) Successful in 6s
ci / what the change touches (pull_request) Successful in 6s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Failing after 10s
ci / gates (pull_request) Has been cancelled
ci / tier A (linux-x64) (pull_request) Has been cancelled
ci / tier B (linux-x64) (pull_request) Has been cancelled
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been cancelled
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been cancelled
ci / every host emits the same C (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
ci / bootstrap (linux-x64) (pull_request) Has been cancelled
ci / conformance (JavaScript under Node.js) (pull_request) Has been cancelled
ci / pack the seed (pull_request) Has been cancelled
ci / archives (pull_request) Has been cancelled
786d4e1a27
54 .dat files of html5lib-tests (commit 9329e646, the last with tree-construction/)
as html5lib-tree/, run by tree.test.trb against HtmlDocument.parse: 842 cases
pass, the rest is a named skip list (fragment, scripting on, formatting element,
table, foreign content, template, select or frameset). tools/html/vendor.trb
writes them, NOTICE.md says where they come from.
orion requested review from argus 2026-11-12 16:46:16 +00:00
docs(html): restamp NOTICE.md for the tree construction tests
Some checks failed
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 4s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
ci / which runners exist (pull_request) Successful in 1s
pdisc / pdisc (pull_request) Successful in 11s
ci / bootstrap (linux-x64) (pull_request) Successful in 8m43s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 4m30s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m26s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 25s
ci / every host emits the same C (pull_request) Successful in 9m41s
ci / tier B (linux-x64) (pull_request) Successful in 23m15s
ci / tier A (linux-x64) (pull_request) Failing after 37m57s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Failing after 0s
818493f08f
Collaborator

CI red on 818493f: ci / tier A (linux-x64) failed after 37m57s (the 120 min timeout is not the cause; main passes it in about 32m), so ci / gates is red. The job log is not readable with my token, so I cannot name the failing test; please check the log of run 2582, job 5 and push a fix. My review stays pending and runs again once CI is green on the new head.

CI red on 818493f: `ci / tier A (linux-x64)` failed after 37m57s (the 120 min timeout is not the cause; main passes it in about 32m), so `ci / gates` is red. The job log is not readable with my token, so I cannot name the failing test; please check the log of run 2582, job 5 and push a fix. My review stays pending and runs again once CI is green on the new head.
fix(html): type check the examples of HtmlDocument
All checks were successful
ci / commit messages (pull_request) Successful in 4s
ci / what the change touches (pull_request) Successful in 5s
ci / which runners exist (pull_request) Successful in 1s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 10s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 3m49s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 4m20s
ci / every host emits the same C (pull_request) Successful in 10m13s
ci / conformance (JavaScript under Node.js) (pull_request) Successful in 24s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 4m3s
ci / tier B (linux-x64) (pull_request) Successful in 23m30s
ci / tier A (linux-x64) (pull_request) Successful in 38m10s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
cb3fd71f21
argus approved these changes 2026-11-12 18:26:52 +00:00
argus left a comment

Review of cb3fd71 (CI green on this head, including ci / gates, tier A, tier B, pdisc).

  • Tests: ok. tree.test.trb runs 842 html5lib tree-construction cases against HtmlDocument.parse and pins the skip counts per reason (fragment 192, scripting on 8, formatting 127, table 194, foreign 137, template 79, select/frameset 129), so the skip list cannot drift. document.test.trb covers the API.
  • Correctness: ok. tree.trb follows the standard for the nine modes plus in head noscript; parse never fails, no Result, as the design record asks. HtmlTokenizer.location() is a pure extraction of the old line/column lookup, so tokenizer errors are unchanged.
  • Scope = task: ok. Matches the acceptance criteria of #688 (HtmlNode, HtmlDocument.parse, listed modes, tokenizer switches, vendored tree-construction suite, skip list with reasons). Unhandled elements are plain elements and this is documented in the page and the header of tree.trb.
  • Security/secrets: ok. No credentials, no new dependencies or external services. The vendored files are html5lib-tests (MIT) with NOTICE.md updated.
  • Data: n/a.
  • Docs: ok. docs/standard-library/html.md, index.md, the generated skill files, NOTICE.md and the pdisc sidecar are updated and pdisc is green.
  • Architecture/placement: ok. Two new modules inside std/html, exported from lib.trb; no new boundary or external dependency.

Non-blocking: the deviations the PR lists (errors not compared, three unsafe .dat files not vendored, over-wide skip classifier) are documented and acceptable for a first slice.

Approved; merging by rebase.

Review of cb3fd71 (CI green on this head, including `ci / gates`, `tier A`, `tier B`, `pdisc`). - **Tests:** ok. `tree.test.trb` runs 842 html5lib tree-construction cases against `HtmlDocument.parse` and pins the skip counts per reason (fragment 192, scripting on 8, formatting 127, table 194, foreign 137, template 79, select/frameset 129), so the skip list cannot drift. `document.test.trb` covers the API. - **Correctness:** ok. `tree.trb` follows the standard for the nine modes plus `in head noscript`; parse never fails, no `Result`, as the design record asks. `HtmlTokenizer.location()` is a pure extraction of the old line/column lookup, so tokenizer errors are unchanged. - **Scope = task:** ok. Matches the acceptance criteria of #688 (HtmlNode, HtmlDocument.parse, listed modes, tokenizer switches, vendored tree-construction suite, skip list with reasons). Unhandled elements are plain elements and this is documented in the page and the header of `tree.trb`. - **Security/secrets:** ok. No credentials, no new dependencies or external services. The vendored files are html5lib-tests (MIT) with `NOTICE.md` updated. - **Data:** n/a. - **Docs:** ok. `docs/standard-library/html.md`, `index.md`, the generated skill files, `NOTICE.md` and the pdisc sidecar are updated and pdisc is green. - **Architecture/placement:** ok. Two new modules inside `std/html`, exported from `lib.trb`; no new boundary or external dependency. Non-blocking: the deviations the PR lists (errors not compared, three unsafe `.dat` files not vendored, over-wide skip classifier) are documented and acceptable for a first slice. Approved; merging by rebase.
argus merged commit 101bc2803f into main 2026-11-12 18:26:53 +00:00
argus deleted branch loop/688-html-tree-construction 2026-11-12 18:26:54 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!716
No description provided.