Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python) identifiers starting with underscore not highlighted #3221

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

Grammars:

- fix(python) identifiers starting with underscore not highlighted (#3221) [Antoine Lambert][]
- enh(clojure) added `edn` alias (#3213) [Stel Abrego][]
- enh(elixir) much improved regular expression sigil support (#3207) [Josh Goebel][]

[Stel Abrego]: https://github.com/stelcodes
[Josh Goebel]: https://github.com/joshgoebel
[Antoine Lambert]: https://github.com/anlambert

## Version 11.0.0

Expand Down
10 changes: 5 additions & 5 deletions src/languages/python.js
Original file line number Diff line number Diff line change
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
joshgoebel marked this conversation as resolved.
Show resolved Hide resolved
],
}
],
Expand Down
15 changes: 15 additions & 0 deletions test/markup/python/identifiers.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<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>

<span class="hljs-keyword">class</span> <span class="hljs-title class_">_PrivateClass</span>:
<span class="hljs-keyword">pass</span>
15 changes: 15 additions & 0 deletions test/markup/python/identifiers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def func():
pass

def _private_func():
pass

class IdentifiersTest:
def __init__(self):
pass

def method(self):
pass

class _PrivateClass:
pass