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:
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:
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:
Most other syntax highlighters simply don't highlight anything.
Per this answer, I'm submitting this as a feature request instead of a bug.