1

I can not understand documents about Pygments Styles, which says:

To make the style usable for Pygments, you must

  1. either register it as a plugin (see the plugin docs)
  2. or ... put it into the file mondrian.py and this file into the pygments.styles subpackage directory.

Now there is already a Dracula theme for Pygments, how can I add it as a new pygments style, so that I can use the style by a simple command line (E.g. pygmentize -g xx.py).

Either by registering a plugin, or puting dracula.py in to the pygements.styles subpackage directory (where it is?). I just don't know how to do this, and there is not a single example.

PS: My OS is ubuntu-18.04 and I install pygments by sudo apt-get install python-pygments python3-pygments

Hao Liu
  • 115
  • 6

2 Answers2

1

Here's how I got it working (assuming pygmentize already installed).

  1. Run echo hello | pygmentize -P style=does_not_exist which will output an error which includes the styles directory.
  2. Navigate to the styles directory.
  3. Download the Pigments Dracula theme, unzip and copy dracula.py into the styles directory.
  4. test echo "const result = 'success';" | pygmentize -P style=dracula, hopefully the result was Dracula themed!

I'm using MacOS & pygmentize installed through homebrew.

Andrew
  • 5,525
  • 5
  • 36
  • 40
0

For me (also Ubuntu 18.04), the path of the installation directory is: /usr/lib/python3/dist-packages/pygments. There you will find another directory named styles where all the existing color themes are present (e.g. autumn.py, fruity.py). You may create your own style (following: https://pygments.org/docs/styles/) and store the corresponding style file here.

I hope this partially answers your query.

Doi
  • 137
  • 1
  • 5
  • Thanks very much. I installed pygments by "sudo pip3 install pygments" and my directory is "/usr/local/lib/python3.6/dist-packages/pygments/styles". I copied "dracula.py" to this folder and modified \_\_init\_\_.py, then the new style is available by "pygmentize -P style=dracula -g" – Hao Liu Jul 15 '20 at 07:33