mmikkel / Retcon-Craft

A collection of powerful Twig filters for modifying HTML
MIT License
79 stars 9 forks source link

Removing P tag not working? #61

Closed brianrivet-tilt closed 1 year ago

brianrivet-tilt commented 1 year ago

Hi,

I'm sure this is a user error situation, but I'm trying to remove p tags and then add classes to the a tags in code. The class add is working, but the p tags are not being removed. Here's my code:

{{contactItem.multiContactItemNumbers| retcon([
['change', 'p', false],
['attr', 'a', { class: 'text-blue-primary hover:text-blue-secondary' }]
])}}

The field in question is a redactor field that only contains a p tag with a couple of links and
tags. Can you tell me what I'm doing wrong that would cause the p tags not to strip?

Thanks!

brianrivet-tilt commented 1 year ago

Nevermind. Sorted it out myself. I didn't realize the order of the functions mattered. It works fine if the remove p tags line is last.

mmikkel commented 1 year ago

Hm, in this case the order shouldn't matter. I'm going to take a closer look at this when I have a chance.

mmikkel commented 1 year ago

I found the culprit here, and it had nothing to do with the order of operations per se. Turns out it was DOMDocument wrapping the text node (i.e. text content without a HTML tag) in a <p> tag. A fix will be included in the next release!