From 58f0a23364685b92ac4a6ef08184ee70204a04d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sat, 11 Apr 2020 16:39:00 +0200 Subject: [PATCH 1/4] Doesn't include parens in Python functions params. --- src/languages/python.js | 2 +- test/markup/python-repl/sample.expect.txt | 2 +- test/markup/python/function-header-comments.expect.txt | 10 +++++----- test/markup/python/function-header.expect.txt | 2 +- test/markup/python/matrix-multiplication.expect.txt | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/languages/python.js b/src/languages/python.js index e7ae1bf222..7c58b551e7 100644 --- a/src/languages/python.js +++ b/src/languages/python.js @@ -86,7 +86,7 @@ export default function(hljs) { }; var PARAMS = { className: 'params', - begin: /\(/, end: /\)/, + begin: /\(/, end: /\)/, excludeBegin: true, excludeEnd: true, contains: ['self', PROMPT, NUMBER, STRING, hljs.HASH_COMMENT_MODE] }; SUBST.contains = [STRING, NUMBER, PROMPT]; diff --git a/test/markup/python-repl/sample.expect.txt b/test/markup/python-repl/sample.expect.txt index d5695847b8..0e11f71f36 100644 --- a/test/markup/python-repl/sample.expect.txt +++ b/test/markup/python-repl/sample.expect.txt @@ -11,7 +11,7 @@ foo = 42" >>> """ ... abc ... """ ->>> def test(): +>>> def test(): ... pass >>> >>> diff --git a/test/markup/python/function-header-comments.expect.txt b/test/markup/python/function-header-comments.expect.txt index b8530371f2..4ebe4aaad6 100644 --- a/test/markup/python/function-header-comments.expect.txt +++ b/test/markup/python/function-header-comments.expect.txt @@ -1,10 +1,10 @@ -def foo( +def foo( bar, # commment -): +): pass -class Foo(collections.namedtuple('Test'), ( +class Foo(collections.namedtuple('Test'), ( 'name', # comment -)): - pass \ No newline at end of file +)): + pass diff --git a/test/markup/python/function-header.expect.txt b/test/markup/python/function-header.expect.txt index cf3c8e5ef9..eb249617df 100644 --- a/test/markup/python/function-header.expect.txt +++ b/test/markup/python/function-header.expect.txt @@ -1,2 +1,2 @@ -def f(x: int) -> None: +def f(x: int) -> None: pass diff --git a/test/markup/python/matrix-multiplication.expect.txt b/test/markup/python/matrix-multiplication.expect.txt index 97323a195b..256895b24e 100644 --- a/test/markup/python/matrix-multiplication.expect.txt +++ b/test/markup/python/matrix-multiplication.expect.txt @@ -2,6 +2,6 @@ class C: @decorator - def f(self, H, V, beta, r): + def f(self, H, V, beta, r): S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r) return S From 3db3b70881f1ea3e020427172e43511ef1a92f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sat, 11 Apr 2020 16:59:35 +0200 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b6fdef3eff..74a8cdaf72 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ Parser Engine Changes: Language Improvements: +- enh(python) Exclude parens from functions params (#2490) [Álvaro Mondéjar][] - enh(swift) Add `compactMap` to keywords as built_in (#2478) [Omid Golparvar][] - enh(nim) adds `func` keyword (#2468) [Adnan Yaqoob][] - enh(xml) deprecate ActionScript inside script tags (#2444) [Josh Goebel][] @@ -2148,4 +2149,3 @@ your comments and question to [highlight.js forum][forum]. And don't be afraid if you find there some fancy Cyrillic letters -- it's for Russian users too :-) [forum]: http://softwaremaniacs.org/forum/viewforum.php?id=6 - From 145a98f7c25317d87d05008c3ceff0e206db3f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sat, 11 Apr 2020 17:07:04 +0200 Subject: [PATCH 3/4] Doesn't include params for functions without params. --- src/languages/python.js | 10 ++++++++-- test/markup/python-repl/sample.expect.txt | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/languages/python.js b/src/languages/python.js index 7c58b551e7..86e5d32066 100644 --- a/src/languages/python.js +++ b/src/languages/python.js @@ -86,8 +86,14 @@ export default function(hljs) { }; var PARAMS = { className: 'params', - begin: /\(/, end: /\)/, excludeBegin: true, excludeEnd: true, - contains: ['self', PROMPT, NUMBER, STRING, hljs.HASH_COMMENT_MODE] + variants: [ + // Exclude params at functions without params + {begin: /\(\s*\)/, skip: true, className: null }, + { + begin: /\(/, end: /\)/, excludeBegin: true, excludeEnd: true, + contains: ['self', PROMPT, NUMBER, STRING, hljs.HASH_COMMENT_MODE], + }, + ], }; SUBST.contains = [STRING, NUMBER, PROMPT]; return { diff --git a/test/markup/python-repl/sample.expect.txt b/test/markup/python-repl/sample.expect.txt index 0e11f71f36..6693b43cf9 100644 --- a/test/markup/python-repl/sample.expect.txt +++ b/test/markup/python-repl/sample.expect.txt @@ -11,7 +11,7 @@ foo = 42" >>> """ ... abc ... """ ->>> def test(): +>>> def test(): ... pass >>> >>> From 804d172993bc5e6cc11fe5493e353916b5916665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sat, 11 Apr 2020 17:09:50 +0200 Subject: [PATCH 4/4] Add author link --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 74a8cdaf72..5947bb45c1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -71,6 +71,7 @@ Developer Tools: [Josh Goebel]: https://github.com/yyyc514 [Sean Williams]: https://github.com/hmmwhatsthisdo [Adnan Yaqoob]: https://github.com/adnanyaqoobvirk +[Álvaro Mondéjar]: https://github.com/mondeja ## Version 9.18.1