9

Update: I have filed a bug with highlight.js


None should be the same colour in the function signature and function body (since it's the same object being referred to), but instead it's plain in the signature and orange in the body.

Dark mode screenshot Light mode screenshot

The code itself:

def my_func(working_list=None):
    if working_list is None:
        working_list = []

    working_list.append("a")
    print(working_list)

Source

For comparison, here's what it looks like in Atom, PythonAnywhere, and gedit, which are all using different highlighting schemes:

Atom

PythonAnywhere

gedit

5
  • 5
    The highlighter recognizes the code as Python. The None in the function signature isn't enclosed in a <span class="hljs-literal"> (which the None in the code is), but is part of a straight text node child of the <span class="hljs-params"> (i.e. the list of parameters). If a string is used in the parameter list, then it's enclosed in a <span class="hljs-string">. This looks like a parsing issue, which can/should be an issue for highlight.js. That doesn't mean it's not a problem for SO, just that it will need to be fixed in the library.
    – Makyen Mod
    Commented Sep 27, 2020 at 18:52
  • 1
    @martijn why did you hammer this question to that one :D Commented Oct 4, 2020 at 20:48
  • @Makyen FWIW I've noticed that highlight.js deliberately does some really misguided stuff, like attempting to colour entire syntactic structures instead of just tokens. Commented Oct 4, 2020 at 20:50
  • @Antti That question explains where to report bugs with highlight.js. So it's not a direct duplicate, but it does answer my question.
    – wjandrea
    Commented Oct 18, 2020 at 20:52
  • [Maintainer of Highlight.js here] This is likely a quite simple grammar issue. If anyone can confirm it's still an issue with the latest Highlight.js please file an issue and we can fix it. Commented Feb 15, 2021 at 3:17

0

Browse other questions tagged .