hirasso / html-processor
A tiny HTML processor written in PHP 🐘
Fund package maintenance!
hirasso
Installs: 69
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/hirasso/html-processor
Requires
- php: >=8.2
- asika/autolink: ^2.2
- ivopetkov/html5-dom-document-php: ^2.10
- league/uri: ^7.7
Requires (Dev)
- laravel/pint: ^1.20
- pestphp/pest: ^3.7
- pestphp/pest-plugin-watch: ^3.0
- phpbench/phpbench: ^1.4
- phpstan/phpstan: ^2.1
- symfony/var-dumper: ^7.2
- dev-main
- v0.7.1
- v0.7.0
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-integrate-jolitypo
- dev-changeset-release/main
- dev-quote-normalizer-hardening
- dev-refactor-normalize-quotes
- dev-normalize-quotes
- dev-fix/link-type
- dev-feat/rename-helper-function
This package is auto-updated.
Last update: 2026-01-29 13:44:00 UTC
README
A tiny HTML processor written in PHP 🐘
Warning
The API hasn't stabilized, yet. Use with caution, ideally in combination with a tool like phpstan/phpstan
Features (all optional)
- Automatically convert raw URLs to links
- Remove empty elements
- Optimize typography:
- Localize quotes (currently supported languages,
en,de,fr) - Avoid short last lines (traditionally called "Widows")
- Localize quotes (currently supported languages,
- Process links:
- Add link classes based on type (e.g.
link--external link--file link--ext--pdf) - Open external links in new tab
- Add link classes based on type (e.g.
- Encode email addresses to confuse spam bots
- Automatically link prefixed words (e.g.
@mentionor#hashtag) to a URL of your choice
Promises
- Fluent API
- Understands HTML5
- Optimized for performance
- Extensively tested
Installation
composer require hirasso/html-processor
Minimal Example
use function Hirasso\HTMLProcessor\process; echo process($html)->typography('de');
Maximal Example
use function Hirasso\HTMLProcessor\process; echo process($html) ->autolinkUrls() ->removeEmptyElements('p') ->encodeEmails() ->typography('de', fn ($typo) => $typo->localizeQuotes()->avoidShortLastLines()) ->processLinks(fn ($link) => $link->addClasses()->openExternalInNewTab()) ->autolinkPrefix('@', 'https://your-instance.social/@') ->autolinkPrefix('#', 'https://your-instance.social/tags');
- Browse the tests/Feature folder for more usage examples.
- See the list of currently supported quote styles here.