Skip to content
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

Merged
merged 3 commits into from
Dec 23, 2015
Merged

Add optional "preserve linebreaks" behavior for striptags filter #619

merged 3 commits into from
Dec 23, 2015

Conversation

ivan-kleshnin
Copy link
Contributor

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

# HEADER      1    
<div>
  row1
row2
  <strong>row3</strong>
</div>

     ## HEADER 2

      <ul>
        <li>option 1</li>
        <li>option 2</li>
        <li>option 3</li>
      </ul>

to a human-readable form

# HEADER 1

row1
row2
row3

## HEADER 2

option 1
option 2
option 3

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, ''))
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@carljm
Copy link
Contributor

carljm commented Dec 22, 2015

Looks good, thanks! Any chance you'd be willing to add docs for this new option to the PR?

@ivan-kleshnin
Copy link
Contributor Author

Right, I forgot about docs 😞 Will add them today.

@ivan-kleshnin
Copy link
Contributor Author

Added 😉

@carljm
Copy link
Contributor

carljm commented Dec 23, 2015

Thanks for the excellent PR, and for taking care of all the little details :-) Merging.

carljm added a commit that referenced this pull request Dec 23, 2015
Add optional "preserve linebreaks" behavior for `striptags` filter
@carljm carljm merged commit e47e4d8 into mozilla:master Dec 23, 2015
@carljm
Copy link
Contributor

carljm commented Jan 6, 2016

Just released this feature in v2.3.0. Thanks again!

@ivan-kleshnin
Copy link
Contributor Author

@carljm nevermind, you are welcome!

vecmezoni pushed a commit that referenced this pull request Oct 24, 2016
* Rebase

* Add more real usecase for nl2br

cf. #619

* no-extra-parens + remove \r support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants