Empty lines in C++ syntax highlight blocks

Hugo v0.64.1-C327E75D/extended. My syntax highlight settings in config.toml:

    codeFences = false
    guessSyntax = false
    hl_Lines = ""
    lineNoStart = 1
    lineNos = false
    lineNumbersInTable = true
    noClasses = true
    style = "abap"
    tabWidth = 4

When I write articles, the following code:

{{< highlight cpp >}}
#pragma once
#include <API.h>
#include <some.h>
#include <vector>

int x = 5;
x = x + 2;

{{< /highlight >}}

produces the following result:

As you can see, redundant empty lines are added (marked with red on the screenshot). Here’s what gets generated in HTML:

And if I change syntax highlight language from cpp to something else:

{{< highlight csharp>}}

Then result is the following:


So no redundant empty lines. And here’s what gets generated in HTML:

So why the difference, why there are redundant empty lines in C++ highlighted code? Is it something that Huge can control somehow?


I’m using the same Hugo version and I couldn’t reproduce the behaviour you described above. There’s a very good chance that the issue you’re highlighting is a styling quirk


1 Like

What platform have you tested it on?

My original problem is on Windows/Linux mix: I ran hugo server from WSL Ubuntu and viewed the website on the host Windows in Firefox (and Edge).

But now I have now tested it on Mac OS (same version of Hugo), ran hugo server from Mac OS terminal and viewed website also on Mac OS in Firefox (and Safari) - the problem isn’t there, I get the same result as on your screenshot.

It’s likely an issue of Windows newlines vs Unix newlines. See this previous thread [SOLVED] Built-in `highlight` function adds whitespace (new lines)

Definitely looks like it, although it is still weird why the same lines with the same endings get rendered differently with just a different syntax highlighting language (csharp instead of cpp, for example).