-
Notifications
You must be signed in to change notification settings - Fork 744
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
Golang syntax highlighting ignores newlines #1097
Comments
@calini Our sample file is rendering without a problem and I can't reproduce this problem. Do you have more details? |
Not really, since I have not tinkered with the configuration, especially nothing related to code highlighting/rendering. I can provide links to places where it shows up: link on my website, link to .md source |
Thanks! That's helpful. Will have an investigate! |
Hmmm, it looks fine in this snippet. And it worked fine when I used I noticed that the symbol used for the code fences differs between Go and the other languages. If you use |
Hmmm. I cloned the Git repo and the problem seems to be the way in which the HTML is being output. The default rendering puts all tokens in their own Not sure how to fix it yet but I think we're getting closer. |
It just occurred to me that newlines are significant in Go in a way they aren't in Java and C. The fact the lexer is matching these newlines explicitly is probably what's causing the difference. |
Line 152 in e957c74
The 'problem' is here. Other lexers tokenise whitespace as This becomes an issue when it's being rendered as I'm not sure which is correct; arguably a newline at the end of a statement isn't really 'text'. Plus the problem is in many ways the CSS rule; you can 'fix' the rendering problem by just changing how it works. What do you think? |
I could just fix it in my fork but that means whoever is pulling a theme that uses Rouge will deal with the same thing. Should I fix it and do a pull request on it? |
As discussed in rouge-ruby#1097, the Go lexer tokenises whitespace using the `Other` token. This causes issues when rendering in HTML the code parsed by Rouge because: 1. the use of `Other` will result in the whitespace being wrapped in separate HTML tags, which in turn causes 2. all newlines to be collapsed (due to CSS rules that expect newlines not to be wrapped in seperate HTML tags). The `Other` token's intended use is described as follows: > Token for data not matched by a parser (e.g. HTML markup in PHP code) This is not a correct characterisation of whitespace in Go and is not consistent with other lexers. This commit changes the token to `Text`, the token generally used by other lexers. It fixes rouge-ruby#1097.
I had a look at the description of the tokens in the wiki and
Pygments has the same description. To my mind, that's not an accurate description of whitespace in Go. That makes me feel confident that changing the token to I'll update and submit a PR. |
As discussed in #1097, the Go lexer tokenises whitespace using the `Other` token. This causes issues when rendering in HTML the code parsed by Rouge because the use of `Other` will result in the whitespace being wrapped in separate HTML tags, which in turn causes all newlines are collapsed (due to CSS rules that expect newlines not to be wrapped in seperate HTML tags). The `Other` token's intended use is described as follows: > Token for data not matched by a parser (e.g. HTML markup in PHP code) This is not a correct characterisation of whitespace in Go and is not consistent with other lexers. This commit changes the token to `Text`, the token generally used by other lexers. It fixes #1097.
Hello! I wanted to post some Go snippets on my Jekyll powered website, but I see the syntax highlighter just ignores the newlines and renders the code on one line.
This does not reproduce for other programming languages, or when not mentioning the programming language after the opening
~~~
.(Fun fact, Go is rendered in a decent fashion if marked as C)
The text was updated successfully, but these errors were encountered: