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

(Python) F strings not highlighting properly #3609

Closed
superadm1n opened this issue Sep 7, 2022 · 5 comments
Closed

(Python) F strings not highlighting properly #3609

superadm1n opened this issue Sep 7, 2022 · 5 comments
Labels
autoclose Flag things to future autoclose. enhancement An enhancement or new feature good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@superadm1n
Copy link

Describe the issue
When using F strings in python they do not highlight the variables embedded in curly braces differently than the string itself

Which language seems to have the issue?
Python - I am not doing auto detection, I am specifying the language

<pre class="language-python">
  <code>
    CODE HERE 
  </code>
</pre>

Are you using highlight or highlightAuto?
Not sure on what this specifically is, my call to highlight is
<script>hljs.highlightAll();</script>

Please let me know if this is not enough information or what specifically you need.

Sample Code to Reproduce

print(f'Percent Complete: {x}%', end='\r')

Renders in highlightjs like the screenshot below

image

Notice the github syntax highlighting does catch the fstring, however the colors being used are hard to easily distinguish.

Expected behavior
Below I have a screenshot from Pycharm and the main key here is it changes the color of the curly braces within the f string to orange and also changes the color of the variable to white. I'm not sure if these should be the color scheme but I do know in my opinion the orange curly braces are very easy to distinguish

image

Additional context
I do also notice that escaped characters like \r or \n within strings also do not change highlight colors which I think would be very helpful. This is demonstrated in my screenshot in expected behavior.

Also It is worth noting that all of my examples show a single quoted f string, but I have tested this behavior is consistent across single or double quoted f strings.

Lastly if it is NOT an f string (missing prepended "f") if there is an embeded variable or curly braces they should NOT be highlighted in order to best indicate that the embeded variable or function will not be processed.

@superadm1n superadm1n added bug help welcome Could use help from community language labels Sep 7, 2022
@joshgoebel
Copy link
Member

We do not consider this a bug - but a feature request. Most likely would fall as a duplication of #2500. Any chance you'd be willing to work on a PR for this enhancement?

I agree all of these improvements would be nice to haves.

@superadm1n
Copy link
Author

I understand, I apologize for entering this as a bug versus a feature request.

I don't think I would be much of help for me to commit to contributing to this PR, I do very little in javascript and wouldnt know where to begin here. If I can get some time within the next few weeks I could look through the source and see if I catch on to much but I cant commit to anything.

@joshgoebel joshgoebel added good first issue Should be easier for first time contributors enhancement An enhancement or new feature and removed bug labels Sep 7, 2022
@joshgoebel
Copy link
Member

I'll leave this open for a bit to see if anyone bites, but this might eventually get closed as a dup of #2500 as if we left issues open for every small improvement to every language we'd have 1000s of issues.

@joshgoebel joshgoebel added the autoclose Flag things to future autoclose. label Sep 7, 2022
@superadm1n
Copy link
Author

Very understandable. Thank you for the information.

@Hirse
Copy link
Contributor

Hirse commented Oct 22, 2022

@superadm1n What version and theme of highlight.js are you using?

I can see f-string working correctly:
image

It seems like support was added ~3 years ago: in #2195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autoclose Flag things to future autoclose. enhancement An enhancement or new feature good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

3 participants