Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/PurpleBooth/twig-htmlstrip

Filter for Twig to convert HTML into Text
https://github.com/PurpleBooth/twig-htmlstrip

Last synced: 21 days ago
JSON representation

Filter for Twig to convert HTML into Text

Lists

README

        

twig-htmlstrip
==============

Filter for Twig to convert a small subset of html into something reasonable you can put in plain text email, or SMS.

[![Build Status](https://travis-ci.org/PurpleBooth/twig-htmlstrip.svg?branch=master)](https://travis-ci.org/PurpleBooth/twig-htmlstrip)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PurpleBooth/twig-htmlstrip/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PurpleBooth/twig-htmlstrip/?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/PurpleBooth/twig-htmlstrip/badge.svg?branch=master)](https://coveralls.io/github/PurpleBooth/twig-htmlstrip?branch=master)
[![Dependency Status](https://www.versioneye.com/user/projects/57952479b4e86c004c3338f7/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/57952479b4e86c004c3338f7)
[![Latest Stable Version](https://poser.pugx.org/purplebooth/twig-htmlstrip/v/stable)](https://packagist.org/packages/purplebooth/twig-htmlstrip)
[![Total Downloads](https://poser.pugx.org/purplebooth/twig-htmlstrip/downloads)](https://packagist.org/packages/purplebooth/twig-htmlstrip)
[![License](https://poser.pugx.org/purplebooth/twig-htmlstrip/license)](https://packagist.org/packages/purplebooth/twig-htmlstrip)

How To Use
----------

Add the dependency to your composer.json
```bash
php composer.phar require purplebooth/twig-htmlstrip:^1.0.0
```

Add a service which points to the class, and tag it with the twig.extension tag.
```yaml
# src/Acme/DemoBundle/Resources/config/services.yml
services:
purplebooth.twig.html_stripper_extension:
class: PurpleBooth\HtmlStripperExtension
tags:
- { name: twig.extension }
```

And use it
```twig
{{ yourhtml|html_strip }}
```

Examples
--------
Input:
```html

Hello, world.


```

Output:
```
Hello, world.
```

Input:
```html
Quote source
```

Output:
```
Quote source (http://pleasestopbeingsad.tumblr.com/)
```

Input:
```html


  • You're a good person

  • Don't be too hard on yourself

  • Enjoy the little things


```

Output:
```
* You're a good person
* Don't be too hard on yourself
* Enjoy the little things
```

Input:
```html

Tomorrow will be better.

You're doing your best, and I'm proud of you.
```

Output:
```
Tomorrow will be better.

You're doing your best, and I'm proud of you.
```

Input:
```html

It's always good to read a good book.

You are not here, but I am thinking of you.
```

Output:
```
It's always good to read a good book. You are not here, but I am thinking of you.
```

Input:
```html


If she wants to dance and drink all night.



  • Well theres no one that can stop her

  • Shes going until the house lights come up or her stomach spills on to the floor

  • This night is gonna end when we're damn well ready for it to be over

  • Worked all week long now the music is playing on our time



Hello

Fin.



```

Output
```
If she wants to dance and drink all night.

* Well theres no one that can stop her
* Shes going until the house lights come up or her stomach spills on to the floor
* This night is gonna end when we're damn well ready for it to be over
* Worked all week long now the music is playing on our time

Hello

Fin.
```

Related
-------

* [Stand alone library](https://github.com/PurpleBooth/htmlstrip)

Versioning
----------

We use [semver](http://semver.org/). See the [releases](https://github.com/PurpleBooth/twig-htmlstrip/releases) for a changelog and versions