-
-
Notifications
You must be signed in to change notification settings - Fork 363
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 a helper to strip HTML tags #179
Conversation
/cc @shawnthompson |
@LaurentGoderre can you do this PR against the v0.6.0 branch? we're going to be merging any day now. thx! |
@jonschlinkert will we still be able to use it on v0.4.x? |
hmm, if we merge into the current branch, would you be okay with doing another pr afterwards to merge into v0.6.0? we wouldn't be able to merge it otherwise, the versions are too different. @doowb any problems with that? |
Absolutely |
That sounds good to me. |
* @param {[type]} options [description] | ||
* @return {[type]} Text with HTML tags removed | ||
*/ | ||
striptags: function (options) { |
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.
@doowb @jonschlinkert is options right her or should it be context? I never know
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.
options
are what handlebars passes as the last argument automatically. If you're planning on passing in a context
when using the helper in a template, then you want to do striptags: function (context, options) {
.
Your test below says {{#striptags context options}}
but it's not actually testing that.
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.
Fixed
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.
👍 to add a little more to what @doowb mentioned (b/c it took me forever to remember these), when you do console.log()
on those objects, if you see hash
, it's really the options
object that is created by Handlebars, with additional properties that handlebars creates, like root
. But context is the actual data object that is being built-up from various sources to pass to your templates. Both of these objects can be merged inside the helper function. Hope that helps (or maybe it made it worse lol)
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.
don't merge this just yet, give me a minute I'll add some comments. I think we need to make this a little more robust.
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.
maybe we could just get a couple more unit tests before merging to ensure it won't hang on unclosed tags or code comments. does that work for you guys?
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.
When you unclosed tags do you mean <a this is a link
or <a href="">this is a link
?
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.
exactly, the first example.
There's a sanitize helper that does this for a passed in string. If you still need something like this for block helpers, please submit a new PR since this was against an older version. |
No description provided.