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

Trim all whitespace in elements written to hugo_stats.json #7958

Closed
yaaax opened this issue Nov 13, 2020 · 5 comments
Closed

Trim all whitespace in elements written to hugo_stats.json #7958

yaaax opened this issue Nov 13, 2020 · 5 comments
Milestone

Comments

@yaaax
Copy link

yaaax commented Nov 13, 2020

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

$ hugo version
Hugo Static Site Generator v0.78.2/extended darwin/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes


I have a markdown content file with a form element declared on several lines :

<form
  action="[URL]"
  method="POST"
>

I run hugo server -e production

EXPECTED: a "form" tag is added in hugo_stats.json tags list
ACTUAL: a "form\n" tag is added in hugo_stats.json tags list

Note: The issue does not happen if the form is declared in one line :

<form action="[URL]" method="POST">
@bep bep added the Bug label Nov 13, 2020
@bep bep added this to the v0.79 milestone Nov 13, 2020
@bep bep changed the title Extra "\n" at the end of some tags in hugo_stats.json Trim all whitespace in elements written to hugo_stats.json Nov 13, 2020
@udaya2899
Copy link

udaya2899 commented Nov 17, 2020

I'm looking to contribute to Hugo. This will be my first issue in a big project. Let me know if this is simple enough for me to make as a PR. Also, please guide me with more context if any.

Edit: As far as I understand, the whitespaces like \n \t should be trimmed from hugo_stats.json

Edit2: Would using json.Compact work for this? Source: https://stackoverflow.com/questions/24777101/how-to-remove-all-spaces-newlines-tabs-from-byte-array

@bep
Copy link
Member

bep commented Nov 17, 2020

Edit2: Would using json.Compact

I don't know what that does, but I was thinking more inline of doing strings.TrimSpace on all the Classes, IDs etc. in

https://github.com/gohugoio/hugo/blob/master/publisher/htmlElementsCollector.go#L233

@yaaax
Copy link
Author

yaaax commented Nov 17, 2020

My skills in Go language are pretty poor at the moment, I let you fix that one 😅
Happy to see the fix for a bit of learning.

My 2 cents : trimming the spaces while parsing HTML elements, as suggested by @bep, is probably more efficient than calling a function like json.Compact after building an entire json.

@udaya2899
Copy link

@bep

https://github.com/gohugoio/hugo/blob/master/publisher/htmlElementsCollector.go#L234 has the strings.TrimSpace already. Am I missing something then?

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants