-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 plainify template function #1915
Conversation
@bep This could come in really handy. How many steps away is something like this from a |
@rdwatters this is Jsonify:
|
@bep Working on your suggestion above, but this is getting a little more discourse-appropriate, so I'll comment here instead: https://discuss.gohugo.io/t/possible-to-get-markdown-escaped-as-just-plain-text-if-not-json/2607 |
Need tests. Did some research on what others do. Django and Jinja2 call this Why do you make it "safe" (return |
|
To strip away any HTML. May be useful for the .Title in head etc. People may shoot themself in the foot with this, maybe ... But if someone wants to merge this, I guess it would be fine. The replacement function is pretty fast.
PR updated with adjustments. |
My point about the name was that "plain" isn't very descriptive or intuitive to me. Our existing -ify funcs (where I use renderer very loosely):
So, More intuitive options: |
We already have |
I reviewed the code and it's good. As for the name, at first I was inclined to agree with @bep's validation for the name as it's consistent with other things we have. In using the function it felt wrong and the name did confuse me. I think it should be called either stripTags or stripHTML. I have a few reasons for this:
The function being called inside of this (and inside Plain) is helpers.StripHTML which feels like the right descriptive name for what it is doing. In retrospect, the helpers.StripHTML should have been named StripTags, but as it was only being used for HTML the name is accurate enough. |
Well, I don't agree - the other ify functions are also transformers, they transform a piece of content from a state/format to another. So does this. The interface of Feel free to add another template function with a more specific use case, but this isn't that function. Maybe we should have a The only thing I agree about here is that it it reads bad as a verb. But that is also true for jsonify, emojify etc. i.e. all of them. But the value of the naming convention makes up for the stupidity. |
Thank you for the clarification, I didn't realize that this function was doing more than just stripping. LGTM. merged as e5e1bcc |
Just to be clear, this new |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
To strip away any HTML. May be useful for the .Title in head etc.
People may shoot themself in the foot with this, maybe ...
But if someone wants to merge this, I guess it would be fine.
The replacement function is pretty fast.