Markdown content renders as regular text in summary


#1

hi all,
i’m probably doing something stupid but i’m just not seeing it…

my index.html includes a partial template summary.html and said summary template uses {{ .Summary }} to show a preview of the post.

this has always worked fine with my html content.
However now I made a post in markdown format, which successfully renders as html when viewed in full, but doesn’t show properly in the summary in index.html, the markdown list syntax is ignored, it’s basically just “straight” plaintext.

see it in action on http://dieter.plaetinck.be/, the post with title "Moved blog to hugo, fastly and comma"
note when you click on the title and go to http://dieter.plaetinck.be/post/moved-blog-to-hugo-fastly-comma/ it renders fine.

the source of that post is here https://github.com/Dieterbe/dieterblog/blob/master/content/post/moved-blog-to-hugo-fastly-comma.md
the theme is at https://github.com/Dieterbe/hugo-theme-blog

thanks!


#2

This is as designed.

If you want to keep the formatting you have to manually insert the split after the summary (i have this in all my archetypes so I do not have to remember the syntax):

<!--more-->

#3

On a blog I’m working on now, I did not like either the auto-rendered summary or the result of putting <!--more--> after what I want for the summary, so I specify the summary in a frontmatter tag and display that instead.

FWIW.


#4

Yea, and then you can use the markdownify template func.


#5

Good point @bep


#6

you’re right. the <!--more--> works fine. i can insert it at arbitrary points within the list and the markdown will render properly in the summary as a valid list (i thought perhaps the </ul> would be missing, breaking the layout of the content below but that’s not the case.).

Reading the summaries docs again it makes a lot more sense now. thanks


#7

beautiful. I like how toml seamlessly supports newlines, so the summary specified in the front matter can be multiple lines.

for completeness, this is the approach you and @bep meant right?

+               {{ if .Params.summary }}
+               {{ .Params.summary | markdownify }}
+               {{ else }}
                {{ .Summary }}
+               {{ end}}


#8

Yeah, that should work basically, but summary is probably a special or blessed word within Hugo, so you might use another string for the arbitrary one, like postsummary or whatever.

{{ if .Params.postsummary }}
  {{ .Params.postsummary | markdownify }}
{{ else }}
  {{ .Summary }}
{{ end}}

#9

Looks good. Here is a related little trick I use:

 {{ with .Params.title_lead }}<h3 class="post-title-lead">{{ .  | markdownify }}</h3>{{ end }}        
<h1 class="post-title">{{ with .Params.title_main}}{{ . | markdownify }}{{ else }}{{ title .Title  }}{{end}}</h1>      

This is the title section of my _default/single.html on one of my sites.

Here I fall back to the builtin .Title, but sometimes I want a title that spans multiple lines or with special formatting (make one word italic …) etc. And in some articles I add what I call a title_lead to prefix the title.


#10

Is there a way to still use markdownify, but filter out a specific tag, for example “a” tags as they break things!


#11

Sure, it’s called editing. If you do not want “a” tags in your custom summary, don’t put it there.


#12

Markdown support looks to be slightly broken in the context of summaries. It appears that if you have any links in your summary that make use of a reference section at the bottom of the post, then those links aren’t populated.


#13

I had the same problem, it seems that Hugo first splits the markdown content by helpers.SummaryDivider or <!--more-->, applies shortcodes and then finally renders it with helpers.BytesToHTML. So the reference links at the bottom of the page are not part of the summary when it is converted.

Function setSummary: https://github.com/spf13/hugo/blob/master/hugolib/page.go#L194-L234

I don’t know if this is by design but for now I just a copy of the link references before the SummaryDivider.


#14

Hello,

just wanted to say, that I have also the “problem”. The author from my favorite theme (mainroad), told me the same, that it is for now not possible to have a summary with styles. I have often only two or three sentences with a link or a short command.
It did not find it usefull, to put every the<!--more-->, also to add it to my imported Wordpress posts. So it would be great to have summary but with CSS/Mardown enabled :slight_smile: