From 318eda317628e9d2187090809a50195aec6dfb69 Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Wed, 2 Jun 2021 18:12:58 +0200 Subject: [PATCH] fix(python) identifiers starting with underscore not highlighted 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. --- CHANGES.md | 2 ++ src/languages/python.js | 10 +++++----- test/markup/python/identifiers.expect.txt | 15 +++++++++++++++ test/markup/python/identifiers.txt | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 test/markup/python/identifiers.expect.txt create mode 100644 test/markup/python/identifiers.txt diff --git a/CHANGES.md b/CHANGES.md index 0b11c531fe..f311454d0a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/src/languages/python.js b/src/languages/python.js index 5ea0dde6bc..c2e7e7e90f 100644 --- a/src/languages/python.js +++ b/src/languages/python.js @@ -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) { @@ -379,7 +379,7 @@ export default function(hljs) { { match: [ /def/, /\s+/, - IDENT_RE + UNDERSCORE_IDENT_RE ], scope: { 1: "keyword", @@ -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 ], } ], diff --git a/test/markup/python/identifiers.expect.txt b/test/markup/python/identifiers.expect.txt new file mode 100644 index 0000000000..bef68a2857 --- /dev/null +++ b/test/markup/python/identifiers.expect.txt @@ -0,0 +1,15 @@ +def func(): + pass + +def _private_func(): + pass + +class IdentifiersTest: + def __init__(self): + pass + + def method(self): + pass + +class _PrivateClass: + pass diff --git a/test/markup/python/identifiers.txt b/test/markup/python/identifiers.txt new file mode 100644 index 0000000000..d559e489b4 --- /dev/null +++ b/test/markup/python/identifiers.txt @@ -0,0 +1,15 @@ +def func(): + pass + +def _private_func(): + pass + +class IdentifiersTest: + def __init__(self): + pass + + def method(self): + pass + +class _PrivateClass: + pass