Why use the embedded highlight shortcode instead of markdown code fences?

With v0.60 and later, is there any benefit to doing this:

{{< highlight go >}}
// ... code
{{< / highlight >}}

instead of this?

```go
// ... code
```

Just curious if the shortcode approach is still widely used, and if so, why?

I think the shortcode is good if you are changing up options between uses. Like custom line numbers (from to) and such:

{{< highlight go "linenos=table,hl_lines=8 15-17,linenostart=199" >}}
// ... code
{{< / highlight >}}

That won’t work with the three ticks if I don’t miss anything.

With attributes you can do the same thing with backticks.

```go {linenos=table,hl_lines=[8,"15-17"],linenostart=199}
// ... code
```

See https://gohugo.io/content-management/syntax-highlighting/#highlighting-in-code-fences.

3 Likes

It was more useful before we improved the highlight support in Markdown (code fences, attributes), but it is still useful in HTML file, Asciidoc files etc.

3 Likes

Yeah, I just realized that there’s a lot of non-md content out there. Thanks.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.