Summary Stripping Tags

If I use the automatically generated {{ .Summary }} all of the HTML is stripped from the output. Is there any way to retain the HTML associated with the file being summarised? For example, with a post markdown file with content like this at the beginning:

## First header 
This is a first sentence _for example_. 
This is a second sentence, new paragraph. 

If I use the automatic {{ .Summary }} for this page, it renders as:

First header This is a first sentence for example. This is a second sentence, new paragraph. 

(note: this also happens with {{ .Summary | safeHTML }}.

What I would expect to render is the HTML also:

<h2>First header</h2> 
<p>This is a first sentence for example.</p> 
<p>This is a second sentence, new paragraph.</p> 

As a small work-around I’m using: {{ .Content | safeHTML | truncate 500 }}.

Where I truncate the full post by N characters (but this is not as nice as the autosummary - sometimes the break is in the middle of a sentence with ellipses).

If the automatic summary would pass the full HTML, we could still plainify the output to get similar results as now.


That is supposed to work as expected; do you have a repo that reproduces this behavior?


$ ./hugo.exe version
Hugo Static Site Generator v0.58.3/extended windows/amd64 BuildDate: unknown

The repo is here:

It’s bare with a single post.
The homepage shows the use of {{ .Summary | safeHTML }}.
There is no <!--more--> being used, just auto-summary.

I would expect it to render the HTML, but it appears the auto-summary strips it.

1 Like

I don’t think that is a small workaround, I think that is the preferred way to do it, from reading posts about this.

Methods aside, there is a note in the docs that imply this behavior:

You can customize how HTML tags in the summary are loaded using functions such as plainify and safeHTML .

I’ve never used summaries so I can’t tell when or if this was changed. @alexandros or @zwbetz, ya’ll know about this?

1 Like

It’s a shame if that’s the preferred method as I rather like the auto generated summary. It does a good job on its own.

I’d just prefer if the behavior was consistent between using auto, or manual (ie: they both produce HTML output be default). This way we can consistently plainify the output if that’s what’s desired.

(note: the presence of a <!--more--> tag will allow the .Summary to output HTML)

As @patdavid mentioned, when using <!--more--> the summary’s HTML is untouched. It has always been this way as far as I know.

Also see: Inconsistent behavior with .Summary tag