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

Code blocks using highlight shortcode in lists have extra indentation #161

Open
kaushalmodi opened this Issue May 12, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@kaushalmodi
Copy link
Owner

kaushalmodi commented May 12, 2018

The highlight shortcode based code blocks in lists get extra indentation.

The same does not happen when using code fences.

https://scripter.co/accessing-devdocs-from-emacs/#christopher-wellon-s-devdocs-lookup

gohugoio/hugo#4717

@kaushalmodi

This comment has been minimized.

Copy link
Owner Author

kaushalmodi commented Dec 21, 2018

As I summarize in gohugoio/hugo#4717 (comment), this issue will be fixed once Hugo accepts the fixed highlight shortcode definition shown below:

{{- $code := (trim .Inner "\n\r") -}}
{{- $lang := .Get 0 -}}
{{- $options := .Get 1 | default "" -}}
{{- $code_ending_in_line_with_spaces := (findRE "[\\r\\n][[:blank:]]+$" $code) -}}
{{/* Ref: https://github.com/gohugoio/hugo/issues/4717#issuecomment-449375012 */}}
{{- with $code_ending_in_line_with_spaces -}}
    {{- $code = (replace $code "\r" "") -}} {{/* Windows -> Unix style line endings for ease in further parsing */}}
    {{- $offset := (trim (index . 0) "\n") -}}
    {{- $lines := (split $code "\n") -}}
    {{- $num_lines := (len $lines) -}}
    {{- $scratch := newScratch -}}
    {{- $scratch.Add "lines_minus_offset" (slice) -}}
    {{- range $i, $line := $lines -}}
        {{- $line_minus_offset := (strings.TrimPrefix $offset $line) -}}
        {{- if (lt $i (sub $num_lines 1)) -}} {{/* Do not add the last blank line */}}
            {{- $scratch.Add "lines_minus_offset" (slice $line_minus_offset) -}}
        {{- end -}}
    {{- end -}}
    {{- $code = (delimit ($scratch.Get "lines_minus_offset") "\n") -}}
    {{- $scratch.Delete "lines_minus_offset" -}}
{{- end -}}
{{- highlight $code $lang $options -}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment