Skip to content

Commit

Permalink
fix(python) fix or conflicts with string highlighting (#3897)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Goebel <me@joshgoebel.com>
  • Loading branch information
MohamedAli00949 and joshgoebel committed Nov 8, 2023
1 parent 3270ef9 commit 5bb7114
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Core Grammars:
- fix(rust) fix escaped double quotes in string [Mohamed Ali][]
- fix(yaml) fix for yaml with keys having brackets highlighted incorrectly [Aneesh Kulkarni][]
- fix(bash) fix # within token being detected as the start of a comment [Felix Uhl][]
- fix(python) fix `or` conflicts with string highlighting [Mohamed Ali][]

New Grammars:

Expand Down
1 change: 1 addition & 0 deletions src/languages/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ export default function(hljs) {
beginKeywords: "if",
relevance: 0
},
{ match: /\bor\b/, scope: "keyword" },
STRING,
COMMENT_TYPE,
hljs.HASH_COMMENT_MODE,
Expand Down
23 changes: 23 additions & 0 deletions test/markup/python/f-strings.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@
<span class="hljs-string">f&quot;{{ }}&quot;</span>
<span class="hljs-keyword">if</span><span class="hljs-string">&quot;text&quot;</span>==<span class="hljs-string">&quot;text&quot;</span>:
<span class="hljs-string">&quot;good&quot;</span>
<span class="hljs-string">rf&quot;https://www.<span class="hljs-subst">{domain}</span>.com&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-string">fr&quot;&quot;&quot;
<span class="hljs-meta">... </span>https://www.example.com/{{age}/360}
...
&quot;&quot;&quot;</span>
<span class="hljs-string">br&quot;https://&quot;</span>
<span class="hljs-keyword">or</span> <span class="hljs-string">br&quot;https://&quot;</span>
<span class="hljs-string">rb&quot;https://&quot;</span>
<span class="hljs-keyword">or</span> <span class="hljs-string">rb&quot;https://&quot;</span>
test()<span class="hljs-keyword">or</span><span class="hljs-string">&quot;&quot;</span>

<span class="hljs-string">&quot;my ...
... name&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-string">&quot;my ...
... name&quot;</span>

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;kkds&quot;</span>+<span class="hljs-string">&quot;kdjsa&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;kkds&quot;</span>+<span class="hljs-string">b&quot;kdjsa&quot;</span>)
<span class="hljs-built_in">print</span>(test()<span class="hljs-keyword">or</span><span class="hljs-string">&quot;kdjs&quot;</span>)
<span class="hljs-built_in">print</span>(test()<span class="hljs-keyword">or</span> <span class="hljs-string">&quot;kdjs&quot;</span>)
<span class="hljs-built_in">print</span>(test()<span class="hljs-keyword">or</span> <span class="hljs-string">f&quot;kdjs&quot;</span>)
test()<span class="hljs-keyword">or</span><span class="hljs-string">&quot;me&quot;</span>
<span class="hljs-built_in">print</span>(test()<span class="hljs-keyword">or</span><span class="hljs-string">&quot;me&quot;</span>)
23 changes: 23 additions & 0 deletions test/markup/python/f-strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@ f"{name + f'{name}'}"
f"{{ }}"
if"text"=="text":
"good"
rf"https://www.{domain}.com"
>>> fr"""
... https://www.example.com/{{age}/360}
...
"""
br"https://"
or br"https://"
rb"https://"
or rb"https://"
test()or""

"my ...
... name"
>>> "my ...
... name"

print("kkds"+"kdjsa")
print("kkds"+b"kdjsa")
print(test()or"kdjs")
print(test()or "kdjs")
print(test()or f"kdjs")
test()or"me"
print(test()or"me")

0 comments on commit 5bb7114

Please sign in to comment.