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

Additional empty line in syntax-highlighted code fences when using Windows line endings #6596

Closed
frerich opened this issue Dec 10, 2019 · 2 comments · Fixed by #7205
Closed
Labels

Comments

@frerich
Copy link

frerich commented Dec 10, 2019

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.60.0/extended darwin/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes.

How to reproduce

  1. Create a new document with a code block using synatx highlighting, e.g.

        ```python
        # Launch the program.
        def main():
            pass
        ```
  2. Make sure this file is stored using Windows line endings.

  3. Generate HTML

Expected behaviour

HTML should be rendered which looks something like

# Launch the program.
def main():
    pass

Observed behaviour

When using Windows line endings, an additional empty line is printed -- but only for the comment! I.e. I see

# Launch the program

def main():
    pass

Additional notes

It appears that when using Windows line endings, any comment in syntax-highlighted code fences (at least for Python and Perl) gets an additional empty line appended.

@bep bep added the Markdown label Dec 18, 2019
@Jos512
Copy link

Jos512 commented Jan 10, 2020

To add to the above report, the issue doesn't happen with every code highlight. C# and Go, for example, work fine with CRLF and LF line endings. Unfortunately a lot of other languages are problematic.


Because the issue still happens with Hugo 0.62.2, I've made an example repository here. There are two content files in there. One intended to use LF line endings, the other CRLF.

If someone runs that example website with hugo server, he or she will see that the identical code examples in the CRLF file look different than those in the LF file. (Those lines are formatted green with CSS.) That happens solely because of the different line endings; everything else in the content files is identical.


I hope this issue can be fixed since it's confusing to the less-technical people I work with. Plus it even confuses me sometimes because the issue doesn't happen with every kind of code example.

Would perhaps a simple strings.Replace(input, "\r\n", "\n") call on the Chroma input string fix this?

@github-actions
Copy link

github-actions bot commented Feb 3, 2022

This issue 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 Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants