gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.06k stars 7.54k forks source link

Add a global "trim 1 empty newline" from templates with an option to turn it off #11319

Open bep opened 1 year ago

bep commented 1 year ago

See https://discourse.gohugo.io/t/extra-newline-after-every-link-due-to-render-link-html/45562/6

I suspect this isn't a problem with just render hooks, and doing it for "all templates" is certainly easier to implement.

<a href="foo">foo</foo>\n
\n

Would become

<a href="foo">foo</foo>\n
<a href="foo">foo</foo>\n
\n
\n

Would become

<a href="foo">foo</foo>\n
\n
<a href="foo">foo</foo>\n

Would be preserved as is.

jmooring commented 1 year ago

markdown

{{< a >}}{{< b >}}

layouts/shortcodes/a.html

a\n

layouts/shortcodes/b.html

b\n

rendered in browser (what you see):

a b

So, after the proposed change, you will see:

ab

Is that correct? If yes, can we flip the default?

bep commented 1 year ago

ab

According to my proposal (trim 1 empty newline), both of your shortcodes would be left untouched and rendered to

a b
bep commented 1 year ago

... but then again, looking at the original discussion, that would not solve the original problem. Oh, well, I need to think.

antoinentl commented 1 year ago

Just a comment after the @jmooring proposal: as a user of Hugo I want to obtain:

ab

In my opinion, if I want a space between these two letters I introduce it:

  1. manually with {{< a >}} {{< b >}}
  2. automatically in layouts/shortcodes/a.html with something like a\n

Two notes:

  1. @bep I'm not sure to understand which use case needs a b as a result
  2. perhaps it will break something if n new lines or no new spaces are generated
jmooring commented 1 year ago

Just a comment after the @jmooring proposal

That was a question, not a proposal. This issue is really about removing the trailing new line from templates, which has been requested in the past, but at this point is a bit of a breaking change.