hugo: Add "block" option/action to markdownify
As @robsonsobral commented in the original issue #1025 that added this “functionality”, this is really non-standard, confusing behaviour. Why was it added in? More importantly, can it be removed, or put behind a config option?
For context, refer to this commit be627fa718d23278aeb53da5651a8a4a1be14c27. Hugo manually strips the leading and trailing paragraph tags, thereby rendering the markdownify
function useless for any string that contains block level markdown.
This can cause major bugs! For example, if your yaml frontmatter looks like this:
somekey: |
This is a **valid** markdown paragraph.
This is another **valid** markdown paragraph. And it's *still valid yaml!*
someotherkey: 2
markdownify
will output the following, incorrect HTML, where the opening tag for the first paragraph, and closing tag for the last paragraph are missing!
This is a <strong>valid</strong> markdown paragraph.</p>
<p>This is another <strong>valid</strong> markdown paragraph. And it's <em>still valid yaml!</em>
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 20 (7 by maintainers)
Links to this issue
Commits related to this issue
- tpl: Add strings.Blocks To mark som text as one or more blocks. Note that the `block` keyword is reserved in Go templates, hence this plural. See #3040 — committed to bep/hugo by bep 7 years ago
- tpl/transform: Avoid removing p tags in markdownify when marked as blocks As in the example below: ``` {{ "Blocks of *text*." | blocks | markdownify}} ``` Fixes #3040 — committed to bep/hugo by bep 7 years ago
- tpl: Add strings.Blocks To mark som text as one or more blocks. Note that the `block` keyword is reserved in Go templates, hence this plural. See #3040 — committed to bep/hugo by bep 7 years ago
- tpl/transform: Avoid removing p tags in markdownify when marked as blocks As in the example below: ``` {{ "Blocks of *text*." | blocks | markdownify}} ``` Fixes #3040 — committed to bep/hugo by bep 7 years ago
- tpl/transform: Only strip p tag in markdownify if only one paragraph Fixes #3040 — committed to bep/hugo by bep 7 years ago
- tpl/transform: Only strip p tag in markdownify if only one paragraph Fixes #3040 — committed to gohugoio/hugo by bep 7 years ago
I am not sure if I understand you correctly @noonat, but @bep posted something similar somewhere else, and I used that in order to always wrap my text in either a single
<p>
tag or multiple:Just replace
.intro
with your own.Perhaps
markdownifyBlock
&markdownifyInline
functions? As mentioned, I see the use-case for inline markdown styles in headers, but calling the functionmarkdown
and then producing non-standard output is highly confusing.It’s actually a lot harder. Especially when you have non-
<p>
elements that begin or end the string.I’m also going to chip in, as it feels like a very odd decision to strip the
<p>
(or simply don’t add it) when the input for the Hugo pipemarkdownify
.Currently:
Expected:
I hope it is something that will reconsider for you to reopen the issue, and implement a fix or add an option to enable the expected behavior 😃
Dropping some links aswell: https://discourse.gohugo.io/t/markdownify-dosnt-add-paragraph-html-tag-on-string-input/18592 https://discourse.gohugo.io/t/markdownify-and-paragraphs/15883 https://discourse.gohugo.io/t/first-paragraph-with-markdownify-not-being-wrapped-with-p-tag/6259/2
Here’s an improved version of @imjasonmiller’s code - it will add missing
<p>
tags if there’s no<p>
or<hx>
tags but will ignore other tags such as<span>
or<em>
:(Copying my solution from the forum, I hope that’s OK.)