Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Html5 Laravel Package

masterminds/html5

HTML5-PHP is a standards-compliant HTML5 parser and serializer written entirely in PHP. It includes both a DOM tree builder and an event-based SAX-like parser, supports PHP namespaces and Composer, interoperates with QueryPath, and requires PHP 7.4+. Stable and widely used in production.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit. masterminds/html5 is a single-purpose, Composer-native, PSR-4 library that does exactly two things: parse HTML5 into a DOMDocument and serialize a DOMDocument back to HTML5. That narrow scope is a good fit for Laravel: it has no framework assumptions, no service provider of its own, and no hidden coupling to Laravel internals. Its output is a standard DOMDocument, which composes cleanly with DOMXPath, Symfony DomCrawler, and any custom tree logic already in the codebase. The event-based (EventHandler, SAX-like) API also gives us an escape hatch if a future use case needs streaming-style tokenization instead of full-tree DOM. The package is already pulled into many Laravel/Symfony-adjacent trees transitively (Symfony DomCrawler uses it for HTML5 parsing), so for a subset of projects we are formalizing an existing dependency rather than adding a new one.

Integration feasibility. High. Installation is a single composer require masterminds/html5:^2.9. PHP 7.4+ baseline aligns with all currently supported Laravel versions (8–12). The ext-libxml requirement was dropped in 2.8.0, so the surface area beyond core PHP's DOM extension is minimal. API is small — loadHTML, save, saveHTML, options array — and the four documented options (encode_entities, disable_html_ns, target_document, implicit_namespaces) cover the practical configuration space. CI covers PHP 8.1–8.3, and there is a clean, non-breaking upgrade history across 2.x. The wrapper cost is one interface, one binding, and one config file.

Technical risk.

  • License ambiguity (highest process risk, low actual risk). The package metadata reports NOASSERTION, which will stop legal sign-off. README.md and LICENSE.txt both state MIT. This is almost certainly a metadata detection artifact, but it must be verified and documented before approval.
  • Adoption/popularity data discrepancy. The reported "Dependents: 0" contradicts the README's "well over five million downloads" and production-usage claims. This is a data-quality signal in the source metrics, not evidence of abandonment, but it means we should independently confirm maintenance activity (open-issue response, security handling) before relying on the number.
  • Release-date anomaly. The reported last-release date (2026-10-25) is in the future, which is a metadata artifact. Actual release history shows a slow but steady cadence (2.7.x → 2.8.x → 2.9.0). Treat the "active" signal as soft.
  • Spec incompleteness. The parser is explicitly non-validating and does not implement the Adoption Agency Algorithm, HTML manifests, or PLAINTEXT. For well-formed input this is fine; for adversarially malformed HTML the produced tree may diverge from browser behavior.
  • Silent data loss. Attributes whose names do not conform to XML 1.0 are silently dropped by the PHP DOM layer. This matters for scraping/normalization pipelines where attribute fidelity is a requirement.
  • Not re-entrant. You cannot pause and mutate the input mid-parse. Acceptable for batch jobs, a constraint for interactive tooling.
  • Not a sanitizer. The library parses and serializes; it does not strip scripts, event handlers, or unsafe URLs. Any security assumption based on "we parse it with an HTML5 parser" is a category error.

Key questions.

  1. Which use case is driving adoption — scraping/normalization, template post-processing, email HTML manipulation, or feed parsing?
  2. Has Legal confirmed the MIT license against LICENSE.txt?
  3. Do we have a representative "ugliest realistic HTML" corpus (largest pages, worst markup) to benchmark against?
  4. Will we consume masterminds/html5 directly, or via Symfony DomCrawler's HTML5 mode, to avoid a parallel parsing stack?
  5. What is the maximum document size in our pipeline, and is full-DOM memory acceptable?
  6. Do we already depend on it transitively — and if so, which version constraint is pinned where?
  7. Is there a sanitization requirement in the same feature that is currently unaddressed?

Integration Approach

Stack fit. Composer-native and framework-agnostic; it drops into Laravel without ceremony. The recommended pattern is a thin adapter: a HtmlParser/HtmlSerializer contract, a concrete implementation wrapping Masterminds\HTML5, a singleton binding in a service provider, and a config/html5.php exposing the four options (encode_entities, disable_html_ns, xmlNamespaces, implicit_namespaces). This preserves the ability to swap implementations later (Symfony DomCrawler, a streaming parser, or a browser-backed service) without touching call sites.

Migration path.

  • From regex / string manipulation: replace with loadHTML()/saveHTML() and validate against golden files. This is the highest-value migration because regex HTML handling is a known defect source.
  • From DOMDocument::loadHTML: this is the most common current pattern and its behavior on HTML5 markup differs materially from masterminds/html5. Migrate deliberately, not silently, and diff outputs.
  • From Symfony DomCrawler: do not add masterminds/html5 as a parallel parser. DomCrawler's HTML5 mode already delegates to it; expose that through the adapter instead.
  • Sanitization: explicitly out of scope. Pair with HTMLPurifier (or equivalent) if untrusted HTML is in the path; the parser is the front-end of the pipeline, not the gate.

Compatibility. PHP 7.4+ matches Laravel 8+; no native extensions beyond the standard DOM/XML stack; PHP 8.1–8.3 tested. Safe under OPcache/JIT. The main compatibility constraint is behavioral, not environmental: consumers must be aware of namespace defaults (disable_html_ns, xmlNamespaces) and entity encoding settings.

Sequencing.

  1. Legal verification of the MIT license; record the artifact in the dependency register.
  2. Spike against a representative HTML corpus; capture parse time, peak memory, and output diffs versus current tooling.
  3. Land the adapter interface, service provider, and config with no call-site changes.
  4. Migrate a single, low-blast-radius use case first (e.g., a scraping normalization job) with golden-file regression tests.
  5. Add observability: parse duration, memory, malformed-input counter, attribute-drop detection.
  6. Broaden adoption use case by use case; keep a feature flag to fall back.
  7. Document the "not a sanitizer" boundary in the internal wiki and code comments.

Operational Impact

Maintenance. Low. The package is mature, carries a "Sustained" stability badge, has a narrow dependency footprint, and a documented, mostly non-breaking upgrade history. The real maintenance cost lives in our adapter, the config surface, and the regression corpus — not in the library itself. Expect a slow upstream cadence (multi-year gaps between minor versions), which means bug fixes for edge cases may not arrive on our schedule.

Support. Community-only, no commercial SLA, small active contributor base. We should budget internal ownership for the wrapper and for triaging upstream issues, and we should not design a critical path that depends on upstream turnaround.

Scaling. The dominant cost model is in-memory DOM: peak memory scales roughly with document size plus tree overhead, and throughput scales horizontally via queue workers. For large or repetitive documents, prefer the SAX-like EventHandler path over full DOMDocument construction. Keep parsing off the request hot path — dispatch to jobs. Cap input size and time-box parses; treat parsing as an untrusted-input boundary.

Failure modes to instrument and guard against.

  • Silently dropped attributes (non-XML-1.0 names) — detect via post-parse attribute-count checks on known-sensitive selectors.
  • Divergent trees on malformed markup due to the missing Adoption Agency Algorithm — cover with a fixture corpus, not just happy-path tests.
  • Memory exhaustion on oversized pages — enforce a size ceiling before loadHTML.
  • Encoding/entity surprises — pin UTF-8 and set encode_entities deliberately per use case.
  • Non-reentrancy — prohibit mid-parse mutation patterns by design.
  • XSS exposure from assuming parser output is sanitized — enforce a separate sanitization stage.

Ramp-up. Very low for the common path: a developer can be productive with loadHTML/saveHTML in under an hour. The learning curve is concentrated in three areas: PHP DOMDocument semantics (encoding, namespaces, node types), the difference between parsing and sanitizing, and the low-level API (custom EventHandler or RulesInterface implementations) — which is only needed if we customize traversal or output rules, and should be treated as a specialized task rather than a team-wide skill.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin