The strip_anchors
Twig (v.2.5.0) filter removes all anchor links (ie. links pointing to different sections of the same page where they are located) from input.
<!-- BEFORE applying filter: -->
<h2><a href="#features">Features of this Twig Extension</a></h2>
<!-- AFTER applying `strip_anchors` filter: -->
<h2>Features of this Twig Extension</h2>
Please note: This repository only shows directories and files from a Symfony 4 skeleton project that need to be added or modified to enable the 'strip_anchors' Twig extension.
Use this Twig filter in an RSS feed template to help transform HTML input into valid RSS 2.0, as shown in the following examples:
{{ item.content|strip_anchors }}
<-- excerpt from rss.xml.twig: -->
<content:encoded>
<![CDATA[
{{ item.content|md2html|strip_anchors }}
]]>
</content:encoded>
This repository shows how this custom Twig extension (ie. the strip_anchors
Twig filter) can be implemented in a Symfony 4 project structure created using symfony/skeleton.
- PHP (v.7.1.16)
- Composer (v.1.6.5)
- symfony/skeleton (v.4.1.4.2)
- symfony/twig-bundle (v.4.1.4)
- symfony/web-server-bundle (optional: for dev environment)
- phpunit/phpunit (v.7.3) OR symfony/phpunit-bridge, symfony/test-pack
(Copyrights for the above remain with their respective owners.)
- Create a new project:
$ composer create-project symfony/skeleton my-project
- Clone this repository (as shown below) and make the corresponding modifications:
$ git clone https://github.com/hfagerlund/strip_anchors.git
$ php bin/console server:run
From the project root dir, run one of the following:
$ ./vendor/phpunit/phpunit/phpunit ./tests/
Or (recommended):
$ ./bin/phpunit
Copyright (c) 2018 Heini Fagerlund. Licensed under the MIT License.