Inconsistent behavior with .Summary tag


#1

Hugo Static Site Generator v0.51/extended darwin/amd64

I notice that the behavior for .Summary is different depending on how it is initiated. If the user adds a <!--more--> tag to their content, the .Summary is generated in HTML, but if it is automatically generated (by virtue of the fact that the .Summary tag is used) it is generated in plain text.

Because we can’t then add the HTML back into the .Summary tag, this causes inconsistent results on the front-end and makes certain things (like creating a .Content without .Summary tag) impossible unless one just wants all of their content unformatted.

I’m curious to know if this is a technical limitation or a design decision. I couldn’t find any history on this behavior.

I’ve put an example repo up.


Summary Views Not Rendering Syntax Highlighting
#2

It’s been like this since the dawn of day, so you would have to ask Steve about the “why”.


#3

Thank you


#4

To get consistent summary paragraph behavior, try:

{{ if in .RawContent "<!--more-->" }}
  {{ .Summary | safeHTML }}
{{ else }}
  <p>{{ .Summary | safeHTML }}</p>
{{ end }}

Summary Views Not Rendering Syntax Highlighting
#5

But I can speculate: It makes some sense to remove “some HTML” to make the summary listing consistent (possibly images, at least headline tags). With “manual summary” you can control this yourself.

There is the truncate func, which I guess is “smarter”, but I don’t think there is an easy way to check if you have manual summary or not.

I have some plans to revisit this problem at some point not very far into the future. I have talked about “content sections” in some other places.


#6

I’ve tried various iterations and hacks and have found none that I think are satisfactory (particularly in conjunction with displaying “content without summary,” which has been brought up in the forums before). I posted this more from the perspective that I think Hugo “should” handle this in the big picture, rather than solving my immediate problem. To that end—though it’s way outside of my league—I’ve been contemplating how I might be able to contribute to a fix on this, which may be more of a torment than a help, but I would like to try.


#7

Thanks. That does not output HTML.


#8

Ah, I see now that it only adds the surrounding <p> tags, but does nothing to inner HTML.