Skip to content

Comments

Improve openpdf-html with htmlunit-neko DOMParser integration and HTML5 feature tests#1490

Merged
andreasrosdal merged 3 commits intomasterfrom
copilot/improve-openpdf-html-parser
Feb 17, 2026
Merged

Improve openpdf-html with htmlunit-neko DOMParser integration and HTML5 feature tests#1490
andreasrosdal merged 3 commits intomasterfrom
copilot/improve-openpdf-html-parser

Conversation

Copy link
Contributor

Copilot AI commented Feb 17, 2026

Description of the new Feature/Bugfix

Better utilizes htmlunit-neko as an HTML5 parser by adding a new HtmlResource class that uses DOMParser directly instead of only SAXParser. Adds comprehensive HTML5 feature tests demonstrating current capabilities and areas for future improvement.

New classes:

  • HtmlResource - HTML5-compliant parsing via htmlunit-neko's DOMParser with error tolerance and automatic tag balancing
  • HtmlParserConfig - Builder API for parser configuration (error reporting, self-closing tags, encoding, element/attribute name casing)

Usage:

// Parse with defaults
HtmlResource resource = HtmlResource.load("<html><body><h1>Hello</h1></body></html>");
Document doc = resource.getDocument();

// Parse with custom config
HtmlParserConfig config = HtmlParserConfig.builder()
    .reportErrors(true)
    .allowSelfClosingTags(true)
    .encoding("UTF-8")
    .build();
HtmlResource resource = HtmlResource.load(html, config);

Documentation:

  • Updated README with htmlunit-neko integration details, usage examples, and configuration options table

Unit-Tests for the new Feature/Bugfix

  • Unit-Tests added to reproduce the bug
  • Unit-Tests added to the added feature

Html5FeaturesTest (7 tests): HTML5 semantic elements, data-* attributes, malformed HTML handling, form elements, CSS3 features, void elements, comprehensive document

HtmlResourceTest (12 tests): Parsing from String/Reader/InputStream, HTML5 elements, malformed HTML tolerance, custom config, error reporting, config builder validation

Compatibilities Issues

No breaking changes. New classes only; existing XMLResource and ITextRenderer APIs unchanged.

Your real name

GitHub Copilot

Testing details

Run tests: mvn test -pl openpdf-html -Dtest=Html5FeaturesTest,HtmlResourceTest

All 19 new tests pass. Existing test suite (121 tests) unaffected.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.w3.org
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java -Dnet.bytebuddy.experimental=true -jar /home/REDACTED/work/OpenPDF/OpenPDF/openpdf-html/target/surefire/surefirebooter-20260217180107067_3.jar /home/REDACTED/work/OpenPDF/OpenPDF/openpdf-html/target/surefire 2026-02-17T18-01-05_892-jvmRun1 surefire-20260217180107067_1tmp surefire_0-20260217180107067_2tmp (dns block)
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java -Dnet.bytebuddy.experimental=true -jar /home/REDACTED/work/OpenPDF/OpenPDF/openpdf-html/target/surefire/surefirebooter-20260217180827797_3.jar /home/REDACTED/work/OpenPDF/OpenPDF/openpdf-html/target/surefire 2026-02-17T18-08-27_719-jvmRun1 surefire-20260217180827797_1tmp surefire_0-20260217180827797_2tmp (dns block)
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java -Dnet.bytebuddy.experimental=true -jar /home/REDACTED/work/OpenPDF/OpenPDF/openpdf-html/target/surefire/surefirebooter-20260217181015121_3.jar /home/REDACTED/work/OpenPDF/OpenPDF/openpdf-html/target/surefire 2026-02-17T18-10-15_053-jvmRun1 surefire-20260217181015121_1tmp surefire_0-20260217181015121_2tmp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 17, 2026 18:08
- Created HtmlResource class for direct HTML5 parsing using htmlunit-neko's DOMParser
- Created HtmlParserConfig for configurable HTML parsing options
- Added comprehensive Html5FeaturesTest demonstrating modern HTML5 features
- Added HtmlResourceTest validating htmlunit-neko integration
- Updated README with documentation for new features

Co-authored-by: andreasrosdal <259156774+andreasrosdal@users.noreply.github.com>
Co-authored-by: andreasrosdal <259156774+andreasrosdal@users.noreply.github.com>
@sonarqubecloud
Copy link

Copilot AI changed the title [WIP] Improve HTML parsing with HtmlUnit-Neko support Improve openpdf-html with htmlunit-neko DOMParser integration and HTML5 feature tests Feb 17, 2026
Copilot AI requested a review from andreasrosdal February 17, 2026 18:12
@andreasrosdal andreasrosdal marked this pull request as ready for review February 17, 2026 18:16
@andreasrosdal andreasrosdal merged commit 6955f6b into master Feb 17, 2026
13 of 14 checks passed
@andreasrosdal andreasrosdal deleted the copilot/improve-openpdf-html-parser branch February 17, 2026 18:16
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.

2 participants