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

nested shortcode with codeblock rendering issue #7848

Open
davidejones opened this issue Oct 16, 2020 · 3 comments
Open

nested shortcode with codeblock rendering issue #7848

davidejones opened this issue Oct 16, 2020 · 3 comments
Labels
Milestone

Comments

@davidejones
Copy link
Contributor

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

$ hugo version
Hugo Static Site Generator v0.71.1-A301F6B2 darwin/amd64 BuildDate: 2020-05-25T09:09:07Z

Does this issue reproduce with the latest release?

Yes

What is the issue?

Nesting a markdown shortcode within a markdown shortcode can in some cases cause a codefence to render some of its contents as markdown.

This doesn't appear to happen if there is just one shortcode surrounding the markdown. e.g removing {{< first >}} and {{< /first >}} from the test example below.

Appears to happen with both methods of specifying markdown:

  • {{% ... %}}
    OR
  • {{< ... >}} with .Inner | markdownify

Screenshot of issue

image

Test

Bit of a messy test but you get the point
I added this to hugolib/shortcode_test.go and the line saying # This declares a view into HAProxy statistics, on port 3833 gets rendered as a h1 even though its inside a code block.

func TestNestedShortCodeWithCodeFence(t *testing.T) {
	t.Parallel()
	c := qt.New(t)

	builder := newTestSitesBuilder(t)
	builder.WithConfigFile("yaml",
		`
pygmentsuseclasses: true
pygmentsCodeFences: true

markup:
  goldmark:
    renderer:
      unsafe: true
  highlight:
    guessSyntax: true
`)

	builder.WithContent("page.md", `---
title: "Hugo Rocks!"
---

{{< first >}}

# This is first markdown

{{< second >}}

# This is second markdown

`+"```"+`
# Basic configuration
timeout client 5s
timeout server 5s
timeout connect 5s

# This declares a view into HAProxy statistics, on port 3833
mode http
stats enable
`+"```"+`
{{< /second >}}
{{< /first >}}
`)
	builder.WithTemplatesAdded("layouts/shortcodes/first.html", `<div>{{- .Inner | markdownify -}}</div>`)
	builder.WithTemplatesAdded("layouts/shortcodes/second.html", `<div>{{ .Inner | markdownify }}</div>`)
	builder.Build(BuildCfg{})

	s := builder.H.Sites[0]
	c.Assert(len(s.RegularPages()), qt.Equals, 1)

	builder.AssertFileContent("public/page/index.html", `<div><h1 id="this-is-first-markdown">This is first markdown</h1>
<div><h1 id="this-is-second-markdown">This is second markdown</h1>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback"># Basic configuration
timeout client 5s
timeout server 5s
timeout connect 5s

# This declares a view into HAProxy statistics, on port 3833
mode http
stats enable
</code></pre></div></div></p>
</div>`)
}
@moorereason
Copy link
Contributor

Confirmed. The test content can be reduced to:

---
title: "Hugo Rocks!"
---
{{< first >}}
# This is first markdown
{{< second >}}
# This is second markdown
```
# COMMENT 1

# COMMENT 2
```
{{< /second >}}
{{< /first >}}

The key is to have a blank line in the code section.

@davidejones
Copy link
Contributor Author

Thank you, much more concise! and yes we actually removed the spacing as a workaround to stop the issue.

@bep bep added this to the v0.77 milestone Oct 17, 2020
@bep bep modified the milestones: v0.77, v0.78 Oct 30, 2020
@bep bep modified the milestones: v0.78, v0.83 Apr 23, 2021
@bep bep modified the milestones: v0.83, v0.84 May 3, 2021
@satotake
Copy link
Contributor

s1 := `{{< first >}}
# This is first markdown

{{< second >}}

# This is second markdown

`+"```"+`
# Comment 1

# Comment 2
`+"```"+`
{{< /second >}}
{{< /first >}}
`

After inner markdownify, s1 is transformed like this as we expect

# This is first markdown

<div><h1 id="this-is-second-markdown">This is second markdown</h1>
<pre><code># Comment 1

# Comment 2
</code></pre></div>

According to commonmark, the above results in <h1> inside <pre>

Although this is a little surprise, it might not be a bug.

@davidejones
Is it fine for you to remove inner markdownify?
I mean

	builder.WithTemplatesAdded("layouts/shortcodes/first.html", `<div>{{- .Inner | markdownify -}}</div>`)
	builder.WithTemplatesAdded("layouts/shortcodes/second.html", `<div>{{ .Inner }}</div>`)

This is the easiest way to fix this, I think.

@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep removed this from the v0.93.0 milestone Mar 1, 2022
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
@bep bep modified the milestones: v0.129.0, v0.131.0 Jul 22, 2024
@bep bep modified the milestones: v0.131.0, v0.133.0 Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants