Question about Highlight Function

Quick question sorry, how do I output a frontmatter as highlighted syntax?

When I do the following inside my markdown file and output the {{ .Content }}

{{< highlight html  "linenos=table" >}}
<button class="btn">Default Button</button>
{{< / highlight >}}

I get the correct syntax highlighted output of content.

However when I try to highlight a frontmatter code in the following way:

+++
code = '''
<button class="btn btn-success">Success</button>
<button class="btn btn-warning">Warning</button>
<button class="btn btn-danger">Danger</button>
'''
+++

{{ highlight .Params.code html "linenos=table" }}

The frontmatter content gets outputted inside a <pre><code> ... </code></pre> but it is not wrapped in the .highlight class with syntax highlighting like you would usually expect.

Am I outputting it in the wrong way? The documentation on the highlight function is limited and I am struggling to correctly highlight this.

Thanks!

When using the highlight shortcode, you do not need to encapsulate the language code in quotation marks.

When using the highlight function, you do.

{{ highlight .Params.code "html" "linenos=table" }}
1 Like

This was super helpful, thank you heaps @jmooring!

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