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

Markdownify Not Closing A Paragraph #11698

Closed
MarkRosemaker opened this issue Nov 11, 2023 · 3 comments · Fixed by #11700
Closed

Markdownify Not Closing A Paragraph #11698

MarkRosemaker opened this issue Nov 11, 2023 · 3 comments · Fixed by #11700
Assignees

Comments

@MarkRosemaker
Copy link
Contributor

MarkRosemaker commented Nov 11, 2023

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

$ hugo version
hugo v0.120.4-f11bca5fec2ebb3a02727fb2a5cfb08da96fd9df+extended darwin/arm64 BuildDate=2023-11-08T11:18:07Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

Description

When I use markdownify on a title and paragraph, the resulting HTML leaves the paragraph unclosed.

So using .Page.RenderString or markdownify on "# My Title\nparagraph" results in:

<h1 id=\"my-title\">My Title</h1>\n<p>paragraph

Minimal example: https://github.com/MarkRosemaker/hugo-bug-markdownify

Draft PR with failing test: #11699

@jmooring
Copy link
Member

jmooring commented Nov 12, 2023

Workaround... the RenderString method on Page takes an options map, so this:

{{ $s := `
## Title

Text
`}}
{{ $.Page.RenderString (dict "display" "block") $s }}

Is rendered to:

<h2 id="title">Title</h2>
<p>Text</p>

The markdownify function is effectively aliased to .Site.Home.RenderString, but without the ability to specify inline vs. block. Another reason to use RenderString instead of markdownify is #9692.

This is the bit that does the p removal:
https://github.com/gohugoio/hugo/blob/master/helpers/content.go#L253-L267

@jmooring
Copy link
Member

jmooring commented Nov 12, 2023

Yeah, we should fix this. This works fine:

{{ $s := `
## Title

My list:

- item one
- item two
`}}
{{ .RenderString $s }}

So this should too:

{{ $s := `
## Title

Text
`}}
{{ .RenderString $s }}

It also breaks with markdown attributes.

{{ $s := `
foo
{#bar}
`}}
{{ .RenderString $s }}

Rendered to:

<p id="bar">foo

Since the user specified an attribute, they must want a paragraph. So it should be:

<p id="bar">foo</p>

Copy link

github-actions bot commented Dec 8, 2023

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 Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants