mmikkel / Retcon-Craft

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

Code breaks if < is used within the redactor field #24

Closed terryupton closed 4 years ago

terryupton commented 4 years ago

Currently, have a situation where the less than character (<) is used within the redactor field. What is occurring is that content is getting cut off just before this character appears until the next html character. In this instance a new

tag.

When outputting this natively with twig code the character renders and there are no issues.

Here is this code for the retcon use case:

  {{ content | retcon([
    ['attr', 'h2', { class: 'font-semibold text-gray-900 text-2xl pt-12 mb-4' }],
    ['attr', 'h3', { class: 'font-semibold text-gray-900 text-lg pt-6 mb-4' }],
    ['attr', 'ul', { class: 'ml-8 list-disc' }],
    ['attr', 'ol', { class: 'ml-8 list-lower-roman' }],
    ['attr', 'li', { class: 'mb-4' }],
    ['attr', 'a', { class: 'text-blue-500 hover:text-green-500 underline hover:underline' }],
    ['attr', 'blockquote', { class: 'italic text-18 text-lime-600 font-light mx-8 my-12 pl-4 py-2 border-l-6 border-lime-600' }],
    ['attr', 'mark', { class: 'text-pink-500 bg-pink-100 p-px italic' }],
    ['removeEmpty'],
  ]) }}

I have tested with just content|raw with native twig output and it renders just fine.

I have not explored a solution, but thought I would raise this issue as it has occurred.

Thanks.

terryupton commented 4 years ago

Oh here is some copy to test with.

WAO application upstream of anaerobic digestion is intended to enhance the biodegradability of the organic matter in the downstream AD reactor. For this duty, lower temperatures (100–200 °C) and pressures (<20 bar) are used, sometimes with the addition of a catalyst. The WAO performance is measured in terms of the increase in either the liquid−phase organic carbon, or the subsequent removal of volatile suspended solids (VSS) by the AD process.

Most recently, there has been interest in the potentially high-value intermediate oxidation products (low molecular weight organic compounds such as acetic and propionic acid) generated by WAO. While these carboxylic acids are produced in appreciable concentrations by the WAO process, extracting and purifying them for reuse remains a challenge.

Note the (< 20- bar ) [art in the first paragraph.

mmikkel commented 4 years ago

Ouch. Thanks for reporting @terryupton – I'll have a look at this as soon as I have the time.

I spent exactly 30 seconds thinking about this :D but if you need a temporary hotfix, you could maybe try to replace the < character with something else, then add the Retcon filter, then convert back to the proper char? I.e. something like this:

{{ entry.body | replace({ '<': '%lessthan%' }) | retcon(...) | replace({ '%lessthan%': '<' }) }}
terryupton commented 4 years ago

Thanks @mmikkel - I am still in the development phase so it's not causing me a huge issue. However, hoping it isn't a hugely complicated fix for you. Look forward to the update/patch. :-)

mmikkel commented 4 years ago

@terryupton I think I've got a fix for this issue – if you're able to help me test it, that'd be much appreciated.

composer require mmikkel/retcon:dev-dev#a25040575c3b18e3b1b55448e7359795c2b87e14

I'll cut a new release once I'm confident I didn't break anything else (at that point you can do a simple composer require mmikkel/retcon to install the latest stable release).

Thanks!

terryupton commented 4 years ago

Hi @mmikkel - thanks for the prompt fix. I will certainly help to test. I will aim to get onto this today/tomorrow and pass some feedback.

mmikkel commented 4 years ago

@terryupton I appreciate that, thanks!

terryupton commented 4 years ago

Hi @mmikkel - apologies a day later than I had hoped to get onto this. I have updated to your dev branch and I have done some testing. Everything seems to be working nicely now. I have tested each special character individually throughout the content and there are no breakages. here are the characters I tested.

!@£$%^&*(){}[]_-+=~`;:'""|\?><,.

I am happy and confident this fix has resolved the issue, so on my part, feel free to commit and push this out.

Thanks again.

mmikkel commented 4 years ago

Thanks for the feedback @terryupton! Much appreciated.

I'm going to try and get some additional testing done over the weekend and hopefully have a new release out early next week.

terryupton commented 4 years ago

Sounds good.

mmikkel commented 4 years ago

Resolved in Retcon 2.2.0