Pygments in {{ .Summary }}

So, pygments syntax formatting isn’t working on my index.html file, while they do work on the single.html

Any ideas on how to get this working?

I have something like this in my index.html

<content>
   {{ range (.Paginate ( first 10 .Data.Pages )).Pages }}
    <article class="preview">
      <h2 class="single_title"><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
      <time class="single_date">{{ .Date.Format "Mon, Jan 2 2006" }}</time>
      <main class="single_main">{{ .Summary }}</main>
    </article>
  {{ end }}
</content>

and this is a sample post

console.log('hello there')

and the following in my config.toml

PygmentsCodeFences = true
pygmentsCodeFencesGuessSyntax = true
pygmentsStyle = "default"
1 Like

@joeshub did you solve this issue? I have the same problem.

@sarchak @joeshub Same issue for me. Would be interested to know whether this is possible.

Actually found out how to fix it

Automatic summary

Pros: Automatic, no additional work on your part.
Cons: All HTML tags are stripped from the summary, and the first 70 words, whether they belong to a heading or to different paragraphs, are all put into one paragraph.

So I fixed it by using manual divider .
User-defined: Manual Summary Splitting
Alternatively, you may add the summary divider where you want to split the article. For org content, use # more where you want to split the article. Content that comes before the summary divider will be used as that content’s summary and stored in the .Summary page variable with all HTML formatting intact.

1 Like