[markup.highlight] codeFences = false in front matter is ignored

Hi there

I’ve been a non-expert Hugo user for a few years now. I use it to maintain a documentation site (choco-solver) on which I also upload presentations generated using reveal_hugo.

The config.toml contains:

[markup.highlight]
codeFences = true

The documentation part is organized as a branch bundle.
The presentation is also organized as branch bundle and I set the front matter in the _index.md file as:

title = "My title"
outputs = ["Reveal"]

[reveal_hugo]
theme = "league"
slide_number = true
highlight_theme = "github"

[markup.highlight]
codeFences = false

I was expecting the default codeFences option to be overridden, because I want to highlights some lines of code like:

```python{1|2-3|4-5|6-7|8-9|1-9}
# some lines of code

But it seems to be ignored.

Is there a way round this problem?

Thank you for your help
CP

These are the fields/keys you can set/override in front matter:
https://gohugo.io/content-management/front-matter/

The markup (config) key is not on the list; you cannot set/override these settings at the page level. The markup key in front matter is for something different.

I do not understand your goal, so I cannot suggest an approach.

First, thank you for the quick reply.
I’ve probably described what I wanted to do but not why, and there’s probably a better solution.

When I run the presentation, the following content:

```python{1|2-4}
class LessThan:
    def __init__(self, v1, v2):
        self.v1 = v1
        self.v2 = v2
.```

should first highlight the first line then lines 2 to 4.
This works when I set codeFences=false in config.toml and does not work otherwise.
But, in the documentation part, when I set codeFences=false the rendering is not what I want (syntactic colouring is off).

Uh, that’s every line.

Assuming your site config has:

[markup.highlight]
lineNos = true

Then your markdown should be:

```python {hl_lines="2 4-5"}
class LessThan:
    def __init__(self, v1, v2):
        self.v1 = v1
        self.v2 = v2
        self.v3 = v3
        self.v4 = v4
```

That will highlight lines 2, 4, and 5.

Here is the expected behavior (when codeFences = false):
expected

Here is what I get (when codeFences = true):

(sorry, I can only post one media file at a time)

When I set lineNos = true I get:

But I’ve done a bit of tinkering and I don’t have complete control over what I’ve done.

I don’t understand how this setting is relevant to your goal.

Style aside, I thought you wanted something like this:

image

That’s because I want step-by-step highlights, provided by the theme.
But I suppose I need to write it directly in html (which works by the way):

<pre><code data-line-numbers="1|2-4">class LessThan:
    def __init__(self, v1, v2):
        self.v1 = v1
        self.v2 = v2
</code></pre>

Hugo’s Chroma highlighter isn’t even used in this context, so I suggest you do one of:

  1. Create a shortcode
  2. Create a code block render hook
  3. Mix the raw HTML with your markdown

I’ll try that, thanks for the help

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