gohugoio / hugo

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

Indentation in .html and .gohtml shortcodes are outputed as code blocks #6599

Closed iu4u57k3 closed 4 years ago

iu4u57k3 commented 4 years ago

Lets say you created a shortcode named info.html or info.gohtml in idea community edition editor with gohtml plugin installed.

You opened it in code editor and pressed Ctrl + Alt + L to beautify it for the nice formatting.

Then it looks something like this:

hugo_info_1

Then you added this shortcode to a post using: hugo_info_2

However, they are being treated as markdown code blocks and not .gohtml or .html files:

hugo_info_3

Once the first indent is removed, then code starts to get rendered correctly.

.gohtml, .html and .md shortcodes must be treated differently by hugo,.

This issue is somewhat similar to: https://github.com/gohugoio/hugo/issues/6553

moorereason commented 4 years ago

This is the correct behavior for CommonMark.

iu4u57k3 commented 4 years ago

So what's the fix?

moorereason commented 4 years ago

Read https://spec.commonmark.org/0.29/#html-blocks (esp. start condition 6).

Don't indent the first line of embedded HTML blocks. End the HTML block with a blank line.

iu4u57k3 commented 4 years ago

Ok, thanks!

iu4u57k3 commented 4 years ago

Can these optimizations be done by hugo itself for html and gohtml files and these files being treated differently?

moorereason commented 4 years ago

@bep, Am I correct here?

When a content file contains a shortcode, does Hugo insert the rendered shortcode output into the main markdown content and then render the combined content (essentially re-rendering the shortcode output)? Did the rendering pipeline/workflow change with the addition of goldmark?

I'm assuming the rendering pipeline is essentially that same and that blackfriday allowed indented HTML whereas goldmark follows the CommonMark spec.

satotake commented 4 years ago

I think this is the intentional behaviour .

According to https://gohugo.io/content-management/shortcodes/#shortcodes-with-markdown , In @iu4u57k3 7k3 's case, it is proper to use not {{% info title="Some product name"%}} but {{< info title="Some product name">}} . They are different.

The former is handled as texts to be processed further so it is converted into code blocks. The latter is treated as raw (=ready to use) html by hugo. I checked it works at least with v0.65.2.

Honestly speaking, I did not know this tip until now! I have been and am using {{< xxx >}} without intension

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

github-actions[bot] commented 2 years ago

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.