Skip to content

hfagerlund/strip_anchors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strip_anchors

Minimum PHP Version Minimum Symfony Version Minimum Twig Version

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.

Sample output:

<!-- 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.

Usage

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:

Example:

{{ item.content|strip_anchors }}

Example 2: use in combination with another filter

<-- excerpt from rss.xml.twig: -->

<content:encoded>
   <![CDATA[
    {{ item.content|md2html|strip_anchors }}
   ]]>
</content:encoded>

How To use in Symfony 4

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.

Requirements

(Copyrights for the above remain with their respective owners.)

Installation

  • 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

Run (dev) Server:

$ php bin/console server:run

Run Tests:

From the project root dir, run one of the following:

using phpunit/phpunit:

$ ./vendor/phpunit/phpunit/phpunit ./tests/

Or (recommended):

using symfony/phpunit-bridge

$ ./bin/phpunit

License

Copyright (c) 2018 Heini Fagerlund. Licensed under the MIT License.