Skip to content

Commit

Permalink
fix(python) identifiers starting with underscore not highlighted
Browse files Browse the repository at this point in the history
Since hljs version 11, python identifiers starting with an underscore
character were no longer highlighted (regression introduced in 952fa0a).

Add new python markup test related to identifiers highlighting.
  • Loading branch information
anlambert committed Jun 2, 2021
1 parent 3e87daa commit 791f1f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/languages/python.js
Expand Up @@ -5,7 +5,7 @@ Website: https://www.python.org
Category: common
*/

import { IDENT_RE } from '../lib/modes.js';
import { UNDERSCORE_IDENT_RE } from '../lib/modes.js';
import * as regex from '../lib/regex.js';

export default function(hljs) {
Expand Down Expand Up @@ -379,7 +379,7 @@ export default function(hljs) {
{
match: [
/def/, /\s+/,
IDENT_RE
UNDERSCORE_IDENT_RE
],
scope: {
1: "keyword",
Expand All @@ -392,14 +392,14 @@ export default function(hljs) {
{
match: [
/class/, /\s+/,
IDENT_RE, /\s*/,
/\(\s*/, IDENT_RE,/\s*\)/
UNDERSCORE_IDENT_RE, /\s*/,
/\(\s*/, UNDERSCORE_IDENT_RE,/\s*\)/
],
},
{
match: [
/class/, /\s+/,
IDENT_RE
UNDERSCORE_IDENT_RE
],
}
],
Expand Down
12 changes: 12 additions & 0 deletions test/markup/python/identifiers.expect.txt
@@ -0,0 +1,12 @@
<span class="hljs-keyword">def</span> <span class="hljs-title function_">func</span>():
<span class="hljs-keyword">pass</span>

<span class="hljs-keyword">def</span> <span class="hljs-title function_">_private_func</span>():
<span class="hljs-keyword">pass</span>

<span class="hljs-keyword">class</span> <span class="hljs-title class_">IdentifiersTest</span>:
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>):
<span class="hljs-keyword">pass</span>

<span class="hljs-keyword">def</span> <span class="hljs-title function_">method</span>(<span class="hljs-params">self</span>):
<span class="hljs-keyword">pass</span>
13 changes: 13 additions & 0 deletions test/markup/python/identifiers.txt
@@ -0,0 +1,13 @@
def func():
pass

def _private_func():
pass

class IdentifiersTest:
def __init__(self):
pass

def method(self):
pass

0 comments on commit 791f1f6

Please sign in to comment.