gohugoio / hugo

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

Shortcodes do not get evaluated in HTML content files with manual summary splitting #6513

Open danmharris opened 4 years ago

danmharris commented 4 years ago

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

$ hugo version
Hugo Static Site Generator v0.58.3 linux/amd64 BuildDate: 2019-09-20T07:23:07Z

Does this issue reproduce with the latest release?

Yes

Issue Details

When rendering an HTML content files which uses manual summary splitting shortcodes do not get evaluated and instead get displayed as raw text. This does not occur when using automatic summary splitting or manual summary splitting in markdown files.

I've produced a reproduction of this issue at https://github.com/danmharris/hugo-html-bug-demo. This contains two files, posts/withsplit.html and posts/nosplit.html which use manual and automatic splitting respectively.

When visiting /posts/nosplit the content renders as expected: image

However when visiting /posts/withsplit, the shortcode is not evaluated: image

jonisbell commented 4 years ago

Maybe this is related to the second part of #6451 because it happens under very similar conditions.

Dieterbe commented 4 years ago

I can confirm this. This breaks all my syntax highlighting because I have html posts with manual <!--more--> markers

Here's how you can reproduce with latest master:

mkdir hugo-test
cd hugo-test
hugo new site quickstart && cd quickstart
mkdir themes && cd themes && git clone https://github.com/yanlinlin82/simple-style.git && cd ..
echo 'theme = "simple-style"' >> config.toml
mkdir content/post
cat <<EOF > content/post/mdpost.md
---
title: "Mdpost"
date: 2019-12-30T15:21:57+01:00
draft: false
---
summary
<!--more-->
content
{{< highlight bash "style=default" >}}
echo $hostname
{{< / highlight >}}
end.
EOF
cat <<EOF > content/post/htmlpost.html
---
title: "HTMLpost"
date: 2019-12-30T15:21:57+01:00
draft: false
---
content
{{< highlight bash "style=default" >}}
echo $hostname
{{< / highlight >}}
end.
EOF
cat <<EOF > content/post/htmlpostwithsummary.html
---
title: "HTMLpost with summary"
date: 2019-12-30T15:21:57+01:00
draft: false
---
summary
<!--more-->
content
{{< highlight bash "style=default" >}}
echo $hostname
{{< / highlight >}}
end.
EOF

"HTMLpost with summary" does not render properly (all the highlight commands and code are shown as is), whereas the other two work fine

ptgott commented 2 years ago

@bep I've found a solution to this, and it will be straightforward to combine this fix with a fix to #6686. The fix would include the pre-divider summary of HTML content files in .Content, just as Hugo does with MD files.

I just wanted to check, though, why Hugo currently does not include the pre-divider summary in the .Content of HTML files. It does seem like this is the intention, since there's a test assertion for this, and the corresponding assertion for MD files includes the summary along with the content.

If we want to keep the existing HTML .Content logic, I can modify my fix to interpret shortcodes in the .Content of HTML content files with manual summary dividers but without including the summary in .Content.

ptgott commented 2 years ago

I've created a PR that fixes the bug while preserving the current HTML summary/content behavior.

artch commented 9 months ago

I can confirm that this is still an issue in 0.120.4 for .html content files.

Dieterbe commented 7 months ago

updating reproduction steps for the latest quickstart instructions using hugo 0.122, to confirm that still "HTMLpost with summary" does not render properly (all the highlight commands and code are shown as is), whereas the other two work fine

you can execute all the code below in a terminal in a temp directory:

hugo new site quickstart && cd quickstart
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo "theme = 'ananke'" >> hugo.toml
mkdir -p content/posts
cat <<EOF > content/posts/mdpost.md
---
title: "Mdpost"
date: 2019-12-30T15:21:57+01:00
draft: false
---
summary
<!--more-->
content
{{< highlight bash "style=default" >}}
echo $hostname
{{< / highlight >}}
end.
EOF
cat <<EOF > content/posts/htmlpost.html
---
title: "HTMLpost"
date: 2019-12-30T15:21:57+01:00
draft: false
---
content
{{< highlight bash "style=default" >}}
echo $hostname
{{< / highlight >}}
end.
EOF
cat <<EOF > content/posts/htmlpostwithsummary.html
---
title: "HTMLpost with summary"
date: 2019-12-30T15:21:57+01:00
draft: false
---
summary
<!--more-->
content
{{< highlight bash "style=default" >}}
echo $hostname
{{< / highlight >}}
end.
EOF
hugo server