Skip to content

Use HtmlKit tokenizer for HTML5 parsing#243

Open
jhaygood86 wants to merge 3 commits into
ArthurHub:masterfrom
jhaygood86:feature/html5-support
Open

Use HtmlKit tokenizer for HTML5 parsing#243
jhaygood86 wants to merge 3 commits into
ArthurHub:masterfrom
jhaygood86:feature/html5-support

Conversation

@jhaygood86

@jhaygood86 jhaygood86 commented Jul 14, 2026

Copy link
Copy Markdown

This is the first of many pull requests to bring in the various HTML and CSS fixes from PeachPDF (which is a stripped down fork) to upstream. The goal is as each change gets merged in, I'll start work on the next change. The eventual goal will be parity where possible for features. There are many cases where that won't be possible, especially on the PDF side, but where it is possible, I'll make sure it works.

Background:
PeachPDF replaced HTML 5 parsing with using the tokenizer in MimeKit. We also use various other functionalities from MimeKit, so we bring in the full library. HTML-Renderer just needs the tokenization, so I used HtmlKit. If any of the other changes that requiring MimeKit gets ported in, then it would make sense to use MimeKit. The only difference is a namespace import and package import. They are the same codebase from the same maintainer.

The reason for this is that the hand-rolled regex based parser is not compliant with HTML 5 parsing rules at all. There are some related changes in the DOM layer that were brought in as well to make it spec compliant.

Changes:

  • Replaces the hand-rolled HTML scanner with HtmlKit tokenization and updates DOM parsing to better follow HTML5 behavior, including omitted end-tag handling (p/td/tr), safer comment/script handling, and noscript re-parsing.
  • Adds anonymous table box correction logic and related DOM/CSS utilities
  • Migrates text storage from SubString to string (removing SubString.cs)
  • Includes a new demo sample showcasing malformed-HTML rendering improvements.

Replaces the hand-rolled HTML scanner with HtmlKit tokenization and updates DOM parsing to better follow HTML5 behavior, including omitted end-tag handling (`p`/`td`/`tr`), safer comment/script handling, and `noscript` re-parsing. Adds anonymous table box correction logic and related DOM/CSS utilities, migrates text storage from `SubString` to `string` (removing `SubString.cs`), and includes a new demo sample showcasing malformed-HTML rendering improvements.
Improve the HTML5 parsing demo snippet by expanding the inline `if` into a multi-line block and refining the demo string text. The escaped source example and live script output were updated together to stay consistent and easier to read.
Delete the `InternalsVisibleTo` entry for `HtmlParserVerify` from `HtmlRenderer.csproj`, narrowing assembly internals access and keeping project metadata aligned with current test/verification setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant