Any way to override linenos in syntax highlighting?

I have lots of posts which require line numbering in code snippets, therefore I have set linenos=table in my config.toml. What I’m wondering now is how to override this setting for a particular markdown code block so that it doesn’t get numbered. Any way to do this? I read the documentation and it doesn’t state anything for doing so.

You can use the highlight shortcode and override the config ones. See here:

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

Your example tells me how to enable line numbering. I am asking how to disable line numbering.

Yes, you are right. I did not understand correctly.

Seems like it’s not possible, at least according to the docs:

For Chroma, any value in this setting will print line numbers.
Pygments has some more fine grained control.

Ah, that doesn’t sound good. Anyways I’m still leaving this issue open.

This isn’t an issue. Those have a queue. :slight_smile:

You think I should open an issue for this?

No. But if you were a user that thought this was an issue queue, we are beholden to explain it is not. :slight_smile:

1 Like

I had some trouble with the included syntax highlighting ~3 yrs ago, so I decided to use
You have to roll your own, but it’s a good library.

1 Like

From how I read the syntax highlight doc page, the linenos setting in the configuration file affects code we highlight with {{< highlight >}}. But if you don’t set the pygmentsCodeFences setting to true, then code fences are not affected by the syntax highlight settings.

So you could try:



Instead of:

{{< highlight go>}}

{{< /highlight >}}

At least, that’s how I do it on my website: if I want line numbers I use highlight, and if I don’t want line numbers I use ~~~. Hope this helps.

1 Like

It’s a good suggestion but I don’t prefer JS to static files.

I did already think of doing that but I don’t like the way shotcodes look in a file that’s why I’m looking for an overriding method instead since I want the Markdown code blocks to be numbered by default. Numbering should be implicit for my ease.

The following works for me.

{{< highlight go "linenos=" >}}

{{< /highlight >}}

I have linenos=table in my global config and the above is sufficient to override it in specific cases.