PHPackages                             webfactory/html5-tagrewriter-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. webfactory/html5-tagrewriter-bundle

ActiveSymfony-bundle[Parsing &amp; Serialization](/categories/parsing)

webfactory/html5-tagrewriter-bundle
===================================

Symfony bundle for webfactory/html5-tagrewriter integration

1.0.1(3mo ago)0122MITPHPPHP &gt;= 8.4CI passing

Since Jan 29Pushed 3mo agoCompare

[ Source](https://github.com/webfactory/WebfactoryHtml5TagRewriterBundle)[ Packagist](https://packagist.org/packages/webfactory/html5-tagrewriter-bundle)[ Docs](https://github.com/webfactory/WebfactoryHtml5TagRewriterBundle)[ RSS](/packages/webfactory-html5-tagrewriter-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (4)Used By (0)

WebfactoryHtml5TagRewriterBundle
================================

[](#webfactoryhtml5tagrewriterbundle)

This bundle provides Symfony integration for the [webfactory/html5-tagrewriter](https://github.com/webfactory/html5-tagrewriter) package.

Core feature is the Twig filter `rewriteTags`, which allows sections of HTML5 in Twig templates to be processed by RewriteHandlers. RewriteHandlers can be configured in the container through tags or using an autoconfiguration attribute.

See the [webfactory/html5-tagrewriter documentation](https://github.com/webfactory/html5-tagrewriter) for details on what a RewriteHandler is and how to implement one. Processing is based on the PHP 8.4 DOM HTML5 parser (`Dom\HTMLDocument`).

Usage in Twig
-------------

[](#usage-in-twig)

Use the `rewriteTags` filter to process HTML through a TagRewriter:

```
{# With the apply tag #}
{% apply rewriteTags %}
    Link
{% endfilter %}

{# ... or the pipe notation #}
{{ content|rewriteTags }}

{# Using a named TagRewriter #}
{{ content|rewriteTags('special') }}
```

Registering RewriteHandlers
---------------------------

[](#registering-rewritehandlers)

### Using the `#[AsRewriteHandler]` Attribute (Recommended)

[](#using-the-asrewritehandler-attribute-recommended)

The easiest way to register a RewriteHandler is using the `#[AsRewriteHandler]` attribute. With autowiring and autoconfiguration enabled, the handler will be automatically registered:

```
use Webfactory\Html5TagRewriter\Handler\BaseRewriteHandler;
use Webfactory\Html5TagRewriterBundle\Attribute\AsRewriteHandler;
use Dom\Element;

#[AsRewriteHandler]
class MyRewriteHandler extends BaseRewriteHandler
{
    public function appliesTo(): string
    {
        return '//html:a';
    }

    public function match(Element $element): void
    {
        $element->setAttribute('target', '_blank');
    }
}
```

### Attribute Options

[](#attribute-options)

The `#[AsRewriteHandler]` attribute accepts two optional parameters:

- `priority` (int, default: `0`): Higher values are processed first
- `rewriter` (string or array, default: `'default'`): The name(s) of the TagRewriter instance(s) to register with

```
// Register with high priority on the default rewriter
#[AsRewriteHandler(priority: 100)]
class HighPriorityHandler extends BaseRewriteHandler { /* ... */ }

// Register on a named rewriter
#[AsRewriteHandler(rewriter: 'special')]
class SpecialHandler extends BaseRewriteHandler { /* ... */ }

// Register on multiple rewriters
#[AsRewriteHandler(rewriter: ['default', 'special'])]
class SharedHandler extends BaseRewriteHandler { /* ... */ }

// Combine priority and named rewriter
#[AsRewriteHandler(priority: 50, rewriter: 'special')]
class PrioritizedSpecialHandler extends BaseRewriteHandler { /* ... */ }
```

### Using Service Tags

[](#using-service-tags)

If you need more control or cannot use autoconfiguration, you can manually tag your services with `webfactory.html5_tag_rewriter.rewrite_handler`:

```
// config/services.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $container): void {
    $services = $container->services();

    $services->set(App\Handler\MyRewriteHandler::class)
        // ... arguments or other configuration here
        ->tag('webfactory.html5_tag_rewriter.rewrite_handler');

    $services->set(App\Handler\SpecialHandler::class)
        // ... arguments or other configuration here
        ->tag('webfactory.html5_tag_rewriter.rewrite_handler', [
            'rewriter' => 'special',
            'priority' => 10,
        ]);
};
```

Credits, Copyright and License
------------------------------

[](#credits-copyright-and-license)

This bundle is based on internal work that we have been using at webfactory GmbH, Bonn, since 2019. However, that (old) bundle implementation was written for the legacy PHP DOM extension, leading to several quirks in HTML processing and requiring the use of [Polyglot HTML 5](https://www.w3.org/TR/html-polyglot/).

Thus, we decided to overhaul the bundle for PHP 8.4 HTML5 DOM support and re-release it as open source.

-

Copyright 2026 webfactory GmbH, Bonn. Code released under [the MIT license](LICENSE).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance80

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d4ed0a0f5a1c56f7df31bb8c854a2ad99d24281dc8df4b4d3dd986a9e84b7a24?d=identicon)[webfactory](/maintainers/webfactory)

---

Top Contributors

[![mpdude](https://avatars.githubusercontent.com/u/1202333?v=4)](https://github.com/mpdude "mpdude (6 commits)")

---

Tags

parserHTML5domtransformerrewritertagrewriter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webfactory-html5-tagrewriter-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/webfactory-html5-tagrewriter-bundle/health.svg)](https://phpackages.com/packages/webfactory-html5-tagrewriter-bundle)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[ressio/pharse

Fastest PHP HTML Parser

8478.4k](/packages/ressio-pharse)[sulu/article-bundle

Bundle for managing localized content-rich entities like blog-posts in the Sulu content management system

66409.6k2](/packages/sulu-article-bundle)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
