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

python3: a # in an f-string breaks syntax highlighting #225

Closed
Spectre5 opened this issue Nov 12, 2020 · 6 comments · Fixed by #226
Closed

python3: a # in an f-string breaks syntax highlighting #225

Spectre5 opened this issue Nov 12, 2020 · 6 comments · Fixed by #226

Comments

@Spectre5
Copy link

Spectre5 commented Nov 12, 2020

See the code below. Since my issue exists on github, I can simply demonstrate my exact issue with the example code block below. Basically, when a # is used within an f-string, then it appears to break the syntax highlighting. It looks like the "#" in the f-string gets interpreted as the start of a comment, even though this is correctly handled for non-f-srings. The # in the format string is used to get the alternate form for the hex conversion. Here is an example of what the "#" does in a format string as well as demonstrate the bug:

>>> # syntax highlighting works here...
>>> i = 5
>>> '{:#04x}'.format(i)   # <-- not using an f-string is fine
'0x05'
>>> f'{i:04x}'
'0005'
>>> f'{i:#04x}'           # <---- this line breaks the syntax highlighting
'0x05'
>>> f'{i:04x}'            # <-- syntax highlighting is broken!
'0005'
>>> '{:#04x}'.format(i)   # <-- syntax highlighting is broken!
'0x05'
>>> 

Here is a screenshot to demonstrate the issue (for future reference) since, after this bug is fixed, the code above will presumably have the correct highlighting:

Screenshot from 2020-11-26 01-22-51

Edit: corrected the 4th output from 0x05 to 0005

elprans added a commit that referenced this issue Nov 12, 2020
MagicPython is still used by Linguist, but the actual syntax
hightlighting seems to be driven by something else now.  Thus, remove
the outdated statement from the README.

Closes: #225
@elprans
Copy link
Member

elprans commented Nov 12, 2020

MagicPython highlights this snippet just fine:

image

The problem is that Github is now using something else for Python highlighting :-/ (I opened a PR to remove the outdated statement from the README).

@Spectre5
Copy link
Author

ah, bummer. I couldn't find anywhere to post an issue for github itself, so I thought I tracked down that this library is what they use, but apparently not! Back to searching for what they use then...

@1st1 1st1 closed this as completed in #226 Nov 12, 2020
1st1 pushed a commit that referenced this issue Nov 12, 2020
MagicPython is still used by Linguist, but the actual syntax
hightlighting seems to be driven by something else now.  Thus, remove
the outdated statement from the README.

Closes: #225
@Spectre5
Copy link
Author

Huh, do you have any idea what library they do use, then? Per this github documentation link, they use linguist, but linguist indicates that they use MagicPython in their grammar index.

@Spectre5
Copy link
Author

Could they just be using an old version, or are you sure they don't use MagicPython anymore?

@elprans
Copy link
Member

elprans commented Nov 12, 2020

Linguist is definitely using a fairly recent version of MagicPython. You might try asking on the community forum at https://github.community/

@verhovsky
Copy link

verhovsky commented Sep 19, 2021

For reference: https://github.community/t/what-library-does-github-use-for-python-syntax-highlighting/145558

No one responded

Edit: turns out Linguist uses tree-sitter for syntax highlighting of some languages, including Python.

QuentiumYT pushed a commit to Quentium-Forks/MagicPython that referenced this issue May 13, 2022
MagicPython is still used by Linguist, but the actual syntax
hightlighting seems to be driven by something else now.  Thus, remove
the outdated statement from the README.

Closes: MagicStack#225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@elprans @verhovsky @Spectre5 and others