purplebooth / twig-htmlstrip
Convert a small subset of html into something reasonable you can put in plain text email, or SMS.
Installs: 30 838
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 4
Requires
- purplebooth/htmlstrip: ^1.0.0
- twig/twig: ^1.12.0|^2.0.0
Requires (Dev)
- henrikbjorn/phpspec-code-coverage: ^2.1
- phpspec/phpspec: 2.0.*@dev
- satooshi/php-coveralls: ^1.0
- sllh/php-cs-fixer-styleci-bridge: ^2.1
This package is not auto-updated.
Last update: 2020-08-26 17:47:01 UTC
README
Filter for Twig to convert a small subset of html into something reasonable you can put in plain text email, or SMS.
How To Use
Add the dependency to your composer.json
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.
# src/Acme/DemoBundle/Resources/config/services.yml services: purplebooth.twig.html_stripper_extension: class: PurpleBooth\HtmlStripperExtension tags: - { name: twig.extension }
And use it
{{ yourhtml|html_strip }}
Examples
Input:
<p>Hello, world.</p>
Output:
Hello, world.
Input:
<a href="http://pleasestopbeingsad.tumblr.com/">Quote source</a>
Output:
Quote source (http://pleasestopbeingsad.tumblr.com/)
Input:
<ul> <li>You're a good person</li> <li>Don't be too hard on yourself</li> <li>Enjoy the little things</li> </ul>
Output:
* You're a good person
* Don't be too hard on yourself
* Enjoy the little things
Input:
<div>Tomorrow will be better.</div> 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:
<blockquote>It's always good to read a good book.</blockquote> You are not here, <i>but I am thinking of you.</i>
Output:
It's always good to read a good book. You are not here, but I am thinking of you.
Input:
<div> <p>If she wants to <i>dance</i> and drink all night.</p> <ul> <li>Well theres no one that can stop her</li> <li>Shes going until the house lights come up or her stomach spills on to the floor</li> <li>This night is gonna end when we're damn well ready for it to be over</li> <li>Worked all week long now the music is playing on our time</li> </ul> <div><div>Hello</div><div>Fin.</div></div> </div>
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
Versioning
We use semver. See the releases for a changelog and versions