Use HtmlKit tokenizer for HTML5 parsing#243
Open
jhaygood86 wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
p/td/tr), safer comment/script handling, andnoscriptre-parsing.SubStringtostring(removingSubString.cs)