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

Fix indentation in highlight shortcode #9955

Merged
merged 1 commit into from
May 31, 2022

Conversation

bep
Copy link
Member

@bep bep commented May 30, 2022

Fixes #4717

@bep
Copy link
Member Author

bep commented May 30, 2022

This is a rather fast and crude implementation, just wanted to "test the water" a little. Have tested it with @jmooring 's test site and it looks OK.

This:

  • Exposes a new InnerDeindented method on the shortcode context
  • This just trims all lines with the whitespace found indenting the shortcode start tag. This will not work if you indent differently inside the shortcode, but it's certainly nice to avoid any tab calculation.

@kaushalmodi @jmooring opinions?

@kaushalmodi
Copy link
Contributor

kaushalmodi commented May 30, 2022

I confirm with fix.

Test Markdown file
+++
title = "highlight shortcode in a list"
draft = false
+++

Hugo Issue # [4717](https://github.com/gohugoio/hugo/issues/4717)

-   List item 1
    {{< highlight emacs-lisp >}}
    (message "I am in list at level-1 indentation")
    {{< /highlight >}}

    -   List item 1.1
        {{< highlight emacs-lisp >}}
        (message "I am in list at level-2 indentation")
        {{< /highlight >}}

        -   List item 1.1.1
            {{< highlight emacs-lisp >}}
            (message "I am in list at level-3 indentation")
            {{< /highlight >}}
    -   List item 2.1
        {{< highlight emacs-lisp >}}
        (message "I am in list back at level-2 indentation")
        {{< /highlight >}}
-   List item 2
    {{< highlight emacs-lisp >}}
    (message "I am in list back at level-1 indentation")
    {{< /highlight >}}

<!--listend-->

{{< highlight emacs-lisp >}}
(message "And now I am at level-0 indentation")
{{< /highlight >}}

Before the fix, using hugo v0.99.1

image

https://highlight-shortcode-indentation-fix--hugo-mwe.netlify.app/posts/highlight-shortcode-in-a-list/

(This is deployed using Hugo v0.99.1 as of writing this on 2022/05/30. The same link should show the corrected highlight sc rendering if deployed using a newer Hugo version in future.)

After the fix in this PR

image

@bep bep force-pushed the fix/highlight-schortcode-indent-4717 branch from 8a82a40 to c97f749 Compare May 31, 2022 06:26
@bep bep marked this pull request as ready for review May 31, 2022 06:27
This commit adds a new `.InnerDeindent` method to the shortcode context, which is `.Inner` with any
indendation removed. This is then used in the built-in `highlight` shortcode to prevent the extra
whitespace getting hightlighted.

Fixes gohugoio#4717
@bep bep force-pushed the fix/highlight-schortcode-indent-4717 branch from c97f749 to d19525e Compare May 31, 2022 06:30
@bep
Copy link
Member Author

bep commented May 31, 2022

@kaushalmodi thanks a lot.

@bep bep merged commit 6f7bf3f into gohugoio:master May 31, 2022
@github-actions
Copy link

github-actions bot commented Jun 1, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indented highlight shortcode brings in the indentation as part of the code block
2 participants