alecthomas / chroma

A general purpose syntax highlighter in pure Go
MIT License
4.34k stars 396 forks source link

Inconsistent syntax highlighting in bash #357

Open esoreq opened 4 years ago

esoreq commented 4 years ago

Hi I get weird results for specific commands in bash rendering

For example the following code when rendered using (https://swapoff.org/chroma/playground/) vim style will identify some commands but not all.

echo Some text to print out 
cat file
a=10
b=$a
let a+=10
ls
mkdir dir  
mkdir -p dir_root/{dir_b}/{dir_l1,dir_l2} 
cd dir_root
cd "dir name"
cd ~
cp file $output

image

alecthomas commented 4 years ago

Have you tried the different themes with chroma --json?

esoreq commented 4 years ago

So I think this is a problem in how you parse specific tags internally - vim was just used as an example here is dracula

image

alecthomas commented 4 years ago

I'm honestly not sure what the actual complaint is? If you're saying some themes highlight different things, that's correct. It depends on if the theme has assignments for those classes of tokens.

alecthomas commented 4 years ago

If you're referring to eg. "mkdir" and "cp" not being highlighted, that's because they are not counted as builtins. See this line for details.

esoreq commented 4 years ago

That is exactly what I was referring to - is there a workaround - i.e. explicitly adding them ?

kolappannathan commented 3 years ago

@alecthomas

For reference, you can look into Rogue used in Jekyll.

Implementation of Rogue: https://github.com/rouge-ruby/rouge/blob/442c8f430277889afc6ce0ccbbdbdaec687abc0f/lib/rouge/lexers/shell.rb

Ref: Screenshot Screenshot 2021-06-08 184210

braoult commented 2 years ago

@alecthomas

  • In addition to "mkdir" and "cp", we could also highlight commands like "sudo" & "ls".
  • We could also highlight configuration variables(the one that start with --) in different colour. Example: "dotnet --version".

It could be interesting, for bash, to separate :

dedounet commented 8 months ago

Hi everyone, i'm bumping this thread in the hope of a future modification!