- 🇺🇦Ukraine Stockticker
And here we are, 8 months later :)
re-roll for 2.1.x, based on a patch from a #15.
- Status changed to Needs review
over 2 years ago 1:15pm 6 July 2023 - 🇺🇸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
about 2 years ago 3:32pm 3 August 2023 - 🇺🇸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
about 2 years ago 6:20pm 18 August 2023 - 🇺🇸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
- Merge request !92#2901579 - Allow the possibility to specify which tags to be stripped when... → (Open) created by rossb89
- 🇬🇧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 👍
- 🇬🇧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
about 1 year ago 9:36pm 12 September 2024 - 🇺🇸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 thehref="[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. 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
- Status changed to Needs review
5 months ago 9:53pm 6 May 2025 - 🇺🇸United States damienmckenna NH, USA
Was looking for a way of doing this via twig, but didn't see any other way.
I think the configuration for listing the allowed tags should be built in a more user friendly way and then converted to a format that is passed to preg_replace(), rather than passing that value directly in - the risk for mucking up the syntax is a little high otherwise.
- 🇺🇸United States dsnopek USA
Here's a new patch that takes MR-92 (which we were using previously), and then fixes the regex issues called out in #2901579-39: Allow the possibility to specify which tags to be stripped when Strip HTML checkbox is ticked. → which came from 🐛 [regression] Space inserted before full stop, comma, etc Fixed which was merged in the meantime.
I'm not personally fond of the approach used in #2901579-41: Allow the possibility to specify which tags to be stripped when Strip HTML checkbox is ticked. → and #2901579-42: Allow the possibility to specify which tags to be stripped when Strip HTML checkbox is ticked. → which use some new custom regexes, rather than relying on
Xss::filter()
. - 🇺🇸United States timwood Rockville, Maryland
@dsnopek I tested applying your patch (which only applies cleanly to the active development branch for the 2.2 versions - 2.x-dev) and the functionality works as expected.
I also prefer this approach vs. the other approaches using custom regexes.
- Status changed to RTBC
3 months ago 1:51pm 21 July 2025 - 🇺🇸United States ultimike Florida, USA
I haven't done a full code review yet, but some initial thoughts:
- I would love an MR instead of a patch, but I know how old-school @dsnopek is so I'll let this one slide (for now.)
- I would much prefer if the "Allowed HTML tags" text field appeared directly under the "Strip HTML" checkbox. Perhaps we can change the order of the checkboxes to move "Strip HTML" to the bottom and then move "Allowed HTML tags" underneath it.
thanks,
-mike - 🇺🇸United States damienmckenna NH, USA
damienmckenna → changed the visibility of the branch 8.x-1.x to hidden.
- 🇺🇸United States damienmckenna NH, USA
I made a MR out of dsnopek's patch, moved the setting to underneath the option (per ultimike's request), and renamed the variable from "trim_options_allowed_html" to just "allowed_html".
- 🇺🇸United States ultimike Florida, USA
@damienmckenna - thanks for the MR and the change.
I went ahead and changed the order of the checkboxes so that "Strip HTML" is at the bottom.
During DrupalEasy Office Hours, we noticed that there were a couple of PhpStan issues for next minor and previous major - we attempted to fix them all, but ran out of time so I suspect there's still a little more work to do.
One is a bit of a chicken-and-egg issue, where support for annotations is deprecated and will be removed in Drupal 12, but using annotations results in PhpStan issues with previous major. Any ideas?
We didn't have time to try this, but maybe something like this is the solution?
/**
* Test the smart trim tokens.
*
* @group smart_trim
*
* @phpstan-ignore-next-line
*/
#[Group('smart_trim')]-mike
- 🇮🇪Ireland lostcarpark
I believe I have fixed the annotation PHPStan issue in 📌 Fix PHPStan for previous major Active . If that fix is valid, I suggest merging that first, then rebasing this one.