Code syntax highlighting has extra newline characters

Hugo is awesome (I’m still learning) and I am using it to create a website.


  1. There is an extra line (<span></span>) at the beginning when I use code highlighting with line numbers. This problem is seen only in code blocks used with a collapsible code shortcode . Normal backtick code blocks don’t have this problem.

Link to website where you can see this.
Link to source code ( the feat/code-blocks branch).
How to run the website from source code ?

  1. Clone the repo
  2. run git submodule update --init --recursive
  3. run hugo server --buildDrafts

What I have tried

I have tried meddling with the CSS but that didn’t help.
I have tried removing new line character at the beginning of code within short code. But that didn’t help.

Any help/suggestion is much appreciated.

Change to:

{{ $code := trim .Inner "\n\r" }}

@jmooring , that worked like a charm.

Thanks a ton for that. Really appreciate your help.

1 Like

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