TopShelfCraft / Wordsmith

A plugin for Craft CMS to help you manage and manipulate text.
Other
30 stars 20 forks source link

`chop` filter glitches when allowed HTML tags have attributes #15

Open michaelrog opened 5 years ago

michaelrog commented 5 years ago

The chop filter appears to have issues when allowed HTML tags have attributes, such as the a tag with title attribute in this example.

Source HTML:

<h2>Do you have what it takes to join our firm?</h2>
<p>We are <a href="http://localhost:8000/about-us#entry:15350:url">looking for students</a> who exhibit the skillsets and ambition to deliver <strong><a href="/about/our-ten-imperatives-of-client-service" title="Our Ten Imperatives of Client Service">The Ten Imperatives of Client Service</a>.</strong></p>

Craft Template Code:

{{ career.basicPageContent|chop(limit=30, unit='w', allowedTags="<em> <p> <h2> <a> <strong>", append="...") }} 

Resulting HTML:

<h2>Do you have what it takes to join our firm?</h2>
<p>We are <a href="http://localhost:8000/about-us#entry:15350:url">looking for students</a> who exhibit the skillsets and ambition to deliver <strong><a href="/about/our-ten-imperatives-of...</a></p>