Allow the possibility to specify which tags to be stripped when Strip HTML checkbox is ticked.

Created on 11 August 2017, over 7 years ago
Updated 12 September 2024, 2 months ago

When the user chooses the Strip HTML option it should be able to specify which tags to be stripped.

✨ Feature request
Status

Needs work

Version

2.1

Component

Code

Created by

πŸ‡·πŸ‡΄Romania anemes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine Stockticker

    And here we are, 8 months later :)

    re-roll for 2.1.x, based on a patch from a #15.

  • πŸ‡ΊπŸ‡¦Ukraine Stockticker

    re-roll for 2.1.0, based on a patch from a #15.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States timwood Rockville, Maryland

    Thanks for the updated patch @Stockticker. It's working for us!

    I'm not sure whether this new patch "uses the same implementation as the views functionality mentioned in the parent meta issue?", so not marking RTBC.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States markie Albuquerque, NM

    MR was updated to reflect the proper branch. Needs updating or re-rolled patch applied. Might have to close and open a new MR.

  • First commit to issue fork.
  • @mortona2k opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I rebased onto the 2.1.x branch.

    I had to change:

               // https://stackoverflow.com/questions/12824899/strip-tags-replace-tags-by-space-rather-than-deleting-them
               $output = preg_replace('/<(\w+)(?![^>]*\/>)[^>]*>/', ' <\1>', $output);
    -          $output = strip_tags($output);
               $output = str_replace('  ', ' ', $output);
    +          $output = strip_tags($output, $this->getSetting('trim_options_allowed_html'));
               $output = trim($output);
     
    -          $output = Xss::filter($output, $this->getSetting('trim_options_allowed_html'));
    

    Seems to be working so far.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Very helpful functionality that was also requested in ✨ Add preserve tags option to formatter Closed: duplicate

  • πŸ‡¬πŸ‡§United Kingdom rossb89 Bristol

    rossb89 β†’ changed the visibility of the branch 2901579-selective-html-stripping-2.1.x to hidden.

  • πŸ‡¬πŸ‡§United Kingdom rossb89 Bristol

    rossb89 β†’ changed the visibility of the branch 2901579-selective-html-stripping-2.1.x to active.

  • Pipeline finished with Failed
    6 months ago
    Total: 516s
    #177799
  • πŸ‡¬πŸ‡§United Kingdom rossb89 Bristol

    I've redone the last MR (68) as the rebase wasn't done correctly and it appeared to contain duplicated code that was already in 2.1.x...

    I've done a new clean MR (92) with the patch re-rolled which is working nicely πŸ‘

  • Pipeline finished with Failed
    6 months ago
    Total: 241s
    #177806
  • Pipeline finished with Failed
    6 months ago
    Total: 247s
    #177816
  • Pipeline finished with Failed
    6 months ago
    Total: 257s
    #177818
  • Pipeline finished with Failed
    6 months ago
    Total: 228s
    #177848
  • Pipeline finished with Success
    6 months ago
    Total: 322s
    #177913
  • πŸ‡¬πŸ‡§United Kingdom rossb89 Bristol

    rossb89 β†’ changed the visibility of the branch 2901579-selective-html-stripping to hidden.

  • πŸ‡¬πŸ‡§United Kingdom rossb89 Bristol

    rossb89 β†’ changed the visibility of the branch 2901579-selective-html-stripping-2.1.x to hidden.

  • πŸ‡¬πŸ‡§United Kingdom rossb89 Bristol

    Did a few more tweaks to the work here in MR-92 to get tests passing, which they are now!

  • Status changed to Needs work 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States timwood Rockville, Maryland

    Thanks to all those who have contributed to this issue, however in recent testing after first applying patch from the older MR-68 and then later from MR-92 I've found that allowed tags attributes are removed. So if you allow <a> tags the href="[URL]" (and any other attributes) are removed, breaking the links.

    The last working patch was https://www.drupal.org/files/issues/2023-07-05/smart_trim--2901579--allo... β†’ (still listed here) from July 2023 against version 2.0.1. It looks like it was actually an unrelated change release (2.1.1) of this module.

    Code above patch changes in src/Plugin/Field/FieldFormatter/SmartTrimFormatter.php from MR-92

               $output = preg_replace('/<(\w+)(?![^>]*\/>)[^>]*>/', ' <\1>', $output);
    

    Code above patch changes in src/Plugin/Field/FieldFormatter/SmartTrimFormatter.php from patch #25

               $output = str_replace('<', ' <', $output);
    

    Reverting this change after applying the latest patch, or reverting back to version 2.1.0 and using the older patch both restore links in allowed <a> tags.

  • πŸ‡ΊπŸ‡ΈUnited States timwood Rockville, Maryland
  • This patch will specify which elements will be deleted and force them only by not using the default strip after them.

  • This patch removes the default 'img' from href=" https://www.drupal.org/project/smart_trim/issues/2901579#comment-15822933 ✨ Allow the possibility to specify which tags to be stripped when Strip HTML checkbox is ticked. Needs work ">#41

Production build 0.71.5 2024