highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.3k stars 3.52k forks source link

Highlighting the self variable in Python #4024

Closed lfalin closed 3 months ago

lfalin commented 3 months ago

Describe the issue Many syntax highlighters identify self in python as a distinct identifier, similar to $this in PHP. Highlight.js does not currently do this.

Which language seems to have the issue? python

Are you using highlight or highlightAuto? Both

Sample Code to Reproduce

class SelfTest:
    def __init__(self):
        self.text = True

    def method(self):
        pass

Expected behavior (From Sublime Text)

image

Actual behavior

image

Additional context While the python grammar definition recognizes self, it does not assign it a scope. In contrast, the PHP definition assigns the variable.language scope to $this.