9

Update: This is actually a bug with highlight.js, but I was testing with an older version that didn't have the problem. I submitted a bug report.


Syntax highlighting changes halfway through a Python identifier _undef to look like the def keyword.

Screenshot:

screenshot of code showing the problem

The code itself:

foo = _undef
bar

I can't reproduce the issue in a highlight.js fiddle (forked from the official fiddle), so it seems like Stack Exchange needs to update. Screenshot:

screenshot of the fiddle without the problem

More info

  • I noticed the problem "in the wild" on this answer.

  • The HTML output:

    <pre class="lang-py s-code-block"><code class="hljs language-python">foo = _un<span class="hljs-keyword">def</span>
    <span class="hljs-title function_">bar</span>
    </code></pre>
    
  • The issue doesn't occur when the identifier is followed by a different token, like a literal:

    foo = _undef
    []
    
  • For comparison, here's GitHub:

    screenshot of GitHub without the issue

    Most other syntax highlighters simply don't highlight anything.

  • Per this answer, I'm submitting this as a feature request instead of a bug.

5

0

Browse other questions tagged .