P-wrapping bug, still alive, opt-out would be good

Like https://discourse.gohugo.io/t/shortcodes-and-p-tags-2/9987 and many others:

Hugo/Goldmark (probably Blackfriday, too) wraps certain shortcode generated parts in <p></p>,
which should be opted out for some pages like landing pages.

Workaround:
Have wrappers with block elements like sections around those shortcodes doing that.

If someone has invested more time into that (this bug has been existing now for probably 6 years or more) and can point me to some code I would be happy if I could try helping here with the code base.

I know that discourse discourages from attaching to old discussions, but collecting all workarounds and knowledge gathered in years at one place would be more helpful, maybe voting certain answers up.

Have a look at your “certain shortcodes” how they “generate” parts. If they use markdownify then read the following link about RenderString and rework your shortcode. There is an option called inline that you want to use. Added plus: RenderString will have the content it renders show up in places like ToC.

What you ignore to mention in your list of workarounds is to just write proper markdown. There are a lot of places where one line-break is not enough to separate things. Use something like remark with preset-lint-markdown-style-guide to lint your markdown or see errors listed that you didn’t know exist.

Lastly: Hugo is developed at Github and there is a CONTRIBUTING.md available.

thanks, is there a way to disable markdown for just one page? this also might solve it here as I do not use ANY markdown (not even blank lines) at the homepage, usually just shortcodes and TOML.

Probably by having some form of if-else-construct in your layout that checks frontmatter. If your template fully uses .Content without any markdown parsing… There is always .RawContent with the unparsed content of your markdown file that you can (ab)use in your layout file.

Sure. Use a .html content file.

Both HTML and Markdown are supported content formats.

ref: Content formats | Hugo

This seems to be an approriate solution if markdown is not necessary or, as in this case, not used. thanks.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.