Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Doesn't strip out HTML tags #4

Open
frankharrison-wj opened this issue Aug 23, 2017 · 4 comments
Open

Doesn't strip out HTML tags #4

frankharrison-wj opened this issue Aug 23, 2017 · 4 comments

Comments

@frankharrison-wj
Copy link

frankharrison-wj commented Aug 23, 2017

I may be misunderstanding how this works, but I can't get Hacksaw to strip out HTML. The docs suggest that it'll remove everything except P tags, but the following:

{{ '<p>A <strong>strong</strong> paragraph with <a href="#">a link</a></p>' | hacksaw(limit='1') }}

leaves the strong and a tags untouched. Am I missing something obvious? I'm on Craft 2.6.2987, Hacksaw 2.0.1.

@ryanshrum
Copy link
Owner

By default, Hacksaw is configured to hack by p. When hacking by p, <p> tags remain. If you want them removed, I would hack by words/w or characters/c.

As noted in read me:

Note: <p>'s are automatically allowed when hacking by paragraph.

@frankharrison-wj
Copy link
Author

Actually I'm happy for p tags to remain – it's the strong and link ones that I assumed would get stripped out, but don't. I can of course work around with twig's strip_tags filter, but thought I'd post here in case it's a bug...

@ryanshrum
Copy link
Owner

ryanshrum commented Aug 24, 2017

Ah, I misunderstood.

Admittedly, it's been a while since I've looked at the code, but after review, I can confirm this is by design. The reason I initially added the hack by p was for a blog index view. My thought was that you'd still want all other tags in there. I will update the read me to indicate this is the case.

I will also go in and add a remove param for when you want to get rid of a specific element when hacking by p.

@frankharrison-wj
Copy link
Author

Ah ok great stuff – thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants