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

transform.Plainify should return template.HTML instead of a string #8732

Open
richtera opened this issue Jul 7, 2021 · 3 comments
Open

transform.Plainify should return template.HTML instead of a string #8732

richtera opened this issue Jul 7, 2021 · 3 comments
Milestone

Comments

@richtera
Copy link
Contributor

richtera commented Jul 7, 2021

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.84.0+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

This is the latest release.

When using plainify hugo many times does the wrong thing. I realize that this is a feature, but I wonder if there is a better way to do it. Specifically, if the HTML contains any HTML entities plainify returns the plain HTML with the entities but not marked as a HTML safe string. So the plainify output for HTML like <div>This &amp; that</div> will be This &amp; that. Now it's easy to pipe it through safeHTML or markdownify or htmlUnescape to solve the problem, but it seems plainify should probably include an automatic htmlUnescape or at least mark the output as HTML safe.
This is a petty kind of thing, but in our code, we always must do plainify | htmlUnescape and whenever we forget it the entities are shown on the screen. Seems cumbersome.

@davidsneighbour
Copy link
Contributor

You should open that in the discourse instead of here.

Regarding the issue at hand: I think it's because of the security model of Golang templates. Go expects the developer to make everything safe, so plainify can't just do an html unescape or mark the string as safe. I think it was recently only that script and style tags were removed by plainify. Lot's of hijinks would have been possible if Go just assumes that the string is safe.

See here: https://golang.org/pkg/html/template/#hdr-Security_Model (the whole chapter is an interesting read)

@richtera
Copy link
Contributor Author

richtera commented Jul 7, 2021

Yes I don't like the safeHTML either, maybe to include htmlUnescape would be safer and useful. What is the current use case for plainify? In my code 100% of my plainify calls have to be followed by one of the other filters. Maybe there should be a new method to extract plain text from html and return it as unescaped string rather than messing with plainfy.

@bep bep added this to the v0.88 milestone Jul 30, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep added this to the v0.119.0 milestone Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@jmooring jmooring changed the title Plainify problems (more of an opinion than a real defect) transform.Plainify should return template.HTML instead of a string Apr 29, 2024
@jmooring
Copy link
Member

These transformation functions return template.HTML

  • transform.Emojify
  • transform.Highlight
  • transform.Markdownify

I think it makes sense to add transform.Plainify to the list.

@bep bep added Enhancement and removed Proposal labels Apr 30, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 30, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants