-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add optional "preserve linebreaks" behavior for striptags
filter
#619
Conversation
It's often desired to pipe {{ text | striptags | nl2br }}. For example, when we're rendering email template from feedback form. This commit adds an option to remove tags, keeping significant whitespace.
return r.copySafeness(input, filters.trim(input.replace(tags, '')).replace(/\s+/gi, ' ')); | ||
var res = ''; | ||
if (preserve_linebreaks) { | ||
res = filters.trim(input.replace(tags, '')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not extract the common filters.trim(input.replace(tags, ''))
outside of the if/else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Looks good, thanks! Any chance you'd be willing to add docs for this new option to the PR? |
Right, I forgot about docs 😞 Will add them today. |
Added 😉 |
Thanks for the excellent PR, and for taking care of all the little details :-) Merging. |
Add optional "preserve linebreaks" behavior for `striptags` filter
Just released this feature in v2.3.0. Thanks again! |
@carljm nevermind, you are welcome! |
* Rebase * Add more real usecase for nl2br cf. #619 * no-extra-parens + remove \r support
It's often desired to pipe
{{ text | striptags | nl2br }}
.For example, when we're rendering email template from feedback form.
This commit adds an option to remove tags, keeping significant whitespace.
{{ text | striptags(true) | nl2br }}
This converts a messy
to a human-readable form