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

v0.7.1 2026-01-29 09:26 UTC

README

Latest Version on Packagist Test Status Code Coverage

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")
  • Process links:
    • Add link classes based on type (e.g. link--external link--file link--ext--pdf)
    • Open external links in new tab
  • Encode email addresses to confuse spam bots
  • Automatically link prefixed words (e.g. @mention or #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');