tajmone / hugo-book

AsciiDoc reprint of "The HUGO Book"
https://git.io/hugo-book
Other
9 stars 1 forks source link

Hugo Code: Indentation on First Line Is Lost With Highlight #15

Open tajmone opened 4 years ago

tajmone commented 4 years ago

POSTPONEDThis fix is postponed after the 1st release of the book. (the current workaround works fine for the HTML book)

After a Hugo code block starting with an indentation is processed by Highlight, the indentation on the first line is lost.

Since this happens only in the first line of code, it could be either:

  1. A problem with the Haml template.
  2. A problem with the Sass/CSS stylesheet.

For an example, see:

tajmone commented 4 years ago

The {wj} Workaround

RIght now, the only workaround solution is to add a word joiner character (⁠) at the beginning of the first indented line using its predefined attribute for character replacement ({wj}):

[source,hugo, subs="+attributes"]
---------------------------------
{wj}        counter = -1
---------------------------------

This works fine, although it's far from being an ideal solution (but, at least, it shouldn't create any problems for other Asciidoctor backends and output formats).

Notes

I've looked into the issue and studied both the Haml template, the Highlight extensions and the SCSS stylesheet.

Form what I've gathered, the problem is that during the highlighting process the leading whitespace of the first code line is lost somewhere in the various passages between Asciidoctor, Haml and the Highlight extension.

The leading whitespace is not included in the HTML output (whereas without Highlight it is), so it's not a CSS issue.

I wasn't able to pin down the exact nature of the problem, but I'm afraid there's no immediate nor easy solution to this.

tajmone commented 3 years ago

Fix Found!

The problem was finally fixed by editing the Haml template and using the :preserve filter.

For more info on the solution and its implementation, see the Alan-Docs project: