Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 of 4 tasks
tajmone opened this issue Oct 20, 2019 · 2 comments
Open
2 of 4 tasks

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

tajmone opened this issue Oct 20, 2019 · 2 comments
Labels
💡 enhancement A new feature or enhancement request 👑 HTML Issues with conversion to HTML format 🔨 Highlight Tool: Highlight (syntax highlighter) 🔬 research Issue requires further researching 💀 bug Something isn't working ⭐ css Topic: Custom stylesheets ⭐ syntax highlighting Topic: Syntax Highlighting ⚠️ important Priority: High
Milestone

Comments

@tajmone
Copy link
Owner

tajmone commented Oct 20, 2019

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.

  • Fix all occurrences in current sources using the {wj} workaround (see below).
  • Try to find a real solution to this problem:
    • Update the Haml listing template with v1.1.0 used in the Alan-Docs project: alan-if/alan-docs@aa8fb65
    • Remove all the {wj} previously added for the temporary workaround.

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 tajmone added 💀 bug Something isn't working ⚠️ important Priority: High ⭐ syntax highlighting Topic: Syntax Highlighting 👑 HTML Issues with conversion to HTML format 🔨 Highlight Tool: Highlight (syntax highlighter) 🕑 pending task Approved changes waiting to be implemented ⭐ css Topic: Custom stylesheets labels Oct 20, 2019
@tajmone
Copy link
Owner Author

tajmone commented Oct 20, 2019

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 added a commit that referenced this issue Oct 20, 2019
Enforce preservation of indentation in the first line of Hugo code
blocks by adding a word joiner character (`{wj}`) at the beginning
of the line (See #15).
@tajmone tajmone added 💡 enhancement A new feature or enhancement request 🔬 research Issue requires further researching and removed 🕑 pending task Approved changes waiting to be implemented labels Oct 20, 2019
tajmone added a commit that referenced this issue Nov 1, 2019
* Fix all cross references to the following sections (See #25):
    * 3.5. Classes
    * 15.2. Data Types

In "§15.2. Data Types", add a custom ID (`[#15-2_data_types]`) to
prevent conflicts with "§2.3. Data Types".
@tajmone tajmone added this to the hugo code milestone Nov 13, 2019
@tajmone tajmone modified the milestones: hugo code, plus ultra Dec 1, 2019
@tajmone
Copy link
Owner Author

tajmone commented Oct 12, 2020

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:

tajmone added a commit to AnssiR66/AlanStdLib that referenced this issue Oct 12, 2020
Fix `block_listing.html.haml`, the Haml HTML listing template used for
integrating Highlight into the Asciidoctor toolchain.

The original template was chewing up indentation of the first line in
code blocks that began with an indented line. This commit fixes the
problem by using the `:preserve` filter to ensure that indentation is
never affected.

For more info on the problem, see:

- tajmone/hugo-book#15
- alan-if/alan-docs#70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 enhancement A new feature or enhancement request 👑 HTML Issues with conversion to HTML format 🔨 Highlight Tool: Highlight (syntax highlighter) 🔬 research Issue requires further researching 💀 bug Something isn't working ⭐ css Topic: Custom stylesheets ⭐ syntax highlighting Topic: Syntax Highlighting ⚠️ important Priority: High
Projects
None yet
Development

No branches or pull requests

1 participant