dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
21.34k stars 359 forks source link

🐛 Incorrect syntax-highlight with comment tag "#" #1668

Open louis-hsu opened 3 months ago

louis-hsu commented 3 months ago

Environment

Test steps

  1. Prepare test.py as below:
    
    num = 407

To take input from the user

num = int(input("Enter a number: "))

if num == 1: print(num, "is not a prime number") elif num > 1:

check for factors

for i in range(2,num): if (num % i) == 0: print(num,"is not a prime number") print(i,"times",num//i,"is",num) break else: print(num,"is a prime number")

if input number is less than

or equal to 1, it is not prime

else: print(num,"is not a prime number")

2. Run command:

command rg --no-config -C 2 print ./test.py --json | delta --syntax-theme="Nord"



**Expected result**
1. Keyword 'print' should be highlighted
2. Python syntax should be identified and highlighted correctly

**Actual result**
Syntax highlighting is not correct:
<img width="373" alt="ScreenShot 2024-04-01 at 13 27 02 " src="https://github.com/dandavison/delta/assets/7710361/977c2d70-7122-48f1-97e5-3acba4c2483c">

The code after comment tag "#" is treated as comment as well

***Others***
1. It seems shell script which uses "#" for comment as Python has the same issue
2. As for other comment tag ("//", e.g.), works correctly

Please let me know if more verifications required and thanks for the assistance.