Python pygmentize ignores style options

357 Views Asked by At

I'm trying to syntax highlight Python 3 code with the pygments pygmentize command line program, but it just ignores all the style options. I have tried the following:

pygmentize -S colorful -l python3 e:\work\Python\repl.py pygmentize -O style=colorful -l python3 e:\work\Python\repl.py

It either gives back the help text or the default styling. This is on Windows 10. Anybody know what I'm doing wrong?

It also returns the help when trying to write out an html file using:

pygmentize -f html -S colorful -l python3 -o a.html e:\work\Python\repl.py

1

There are 1 best solutions below

0
On BEST ANSWER

Using Pygments version 2.11, pygmentize --help states the following:

  -O OPTION=value[,OPTION=value,...]
                Give options to the lexer and formatter as a comma-separated list of key-value pairs. Example: `-O bg=light,python=cool`.
  -P OPTION=value
                Give a single option to the lexer and formatter - with this you can pass options whose value contains commas and equal signs. Example: `-P "heading=Pygments, the Python highlighter"`.

It was not obvious to me, but I've used style as an option and it worked with both -O and -P :

pygmentize -O style=colorful -g /etc/hosts
pygmentize -P style=friendly -g /etc/hosts

Reminder : to list available styles, run pygmentize -L styles