Skip to content
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

Closed
kaushalmodi opened this issue May 12, 2018 · 2 comments
Closed

Comments

@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
Copy link
Owner Author

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 -}}

kaushalmodi added a commit that referenced this issue Jan 4, 2022
Ref:
- #499
- #305

This update also "fixes"
#161.

The code fenced block don't have the same issue as the `highlight`
shortcode does. As we now export line numbered code blocks as fenced
code blocks by default and are moving away from the buggy `highlight`
shortcode, we are bypassing issue
#161.

If you don't like the change in behavior of src block exports in this
commit, customize `org-hugo-goldmark`. See
#485.
kaushalmodi added a commit that referenced this issue Jan 4, 2022
Ref:
- #499
- #305

This update also "fixes"
#161.

The code fenced block don't have the same issue as the `highlight`
shortcode does. As we now export line numbered code blocks as fenced
code blocks by default and are moving away from the buggy `highlight`
shortcode, we are bypassing issue
#161.

If you don't like the change in behavior of src block exports in this
commit, customize `org-hugo-goldmark`. See
#485.
@kaushalmodi
Copy link
Owner Author

Fixed by #499, by actually preventing the use of the highlight shortcode. Using code fences prevents the issue described above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant