如何在 Pygments 中使用 Dracula 主题作为样式?
How to use Dracula theme as a style in Pygments?
我无法理解关于 Pygments Styles 的文档,上面写着:
To make the style usable for Pygments, you must
- either register it as a plugin (see the plugin docs)
- or ... put it into the file mondrian.py and this file into the pygments.styles subpackage directory.
现在已经有一个Dracula theme for Pygments,我如何将它添加为一个新的pygments样式,以便我可以通过一个简单的命令行使用该样式(例如pygmentize -g xx.py
)。
要么通过注册插件,要么将 dracula.py
放入 pygements.styles subpackage directory
(它在哪里?)。我只是不知道该怎么做,而且没有一个例子。
PS:我的 OS 是 ubuntu-18.04,我通过 sudo apt-get install python-pygments python3-pygments
安装 pygments
对于我(也是Ubuntu18.04)来说,安装目录的路径是:/usr/lib/python3/dist-packages/pygments
。在那里您会找到另一个名为 styles
的目录,其中存在所有现有的颜色主题(例如 autumn.py、fruity.py)。您可以创建自己的样式(如下:https://pygments.org/docs/styles/)并将相应的样式文件存储在这里。
我希望这能部分回答您的问题。
这是我如何让它工作的(假设 pygmentize 已经安装)。
- 运行
echo hello | pygmentize -P style=does_not_exist
将输出包含 styles
目录的错误。
- 导航到
styles
目录。
- 下载 Pigments Dracula theme,解压并复制
dracula.py
到 styles
目录。
- 测试
echo "const result = 'success';" | pygmentize -P style=dracula
,希望结果是德古拉主题!
我正在使用通过自制软件安装的 MacOS 和 pygmentize。
我无法理解关于 Pygments Styles 的文档,上面写着:
To make the style usable for Pygments, you must
- either register it as a plugin (see the plugin docs)
- or ... put it into the file mondrian.py and this file into the pygments.styles subpackage directory.
现在已经有一个Dracula theme for Pygments,我如何将它添加为一个新的pygments样式,以便我可以通过一个简单的命令行使用该样式(例如pygmentize -g xx.py
)。
要么通过注册插件,要么将 dracula.py
放入 pygements.styles subpackage directory
(它在哪里?)。我只是不知道该怎么做,而且没有一个例子。
PS:我的 OS 是 ubuntu-18.04,我通过 sudo apt-get install python-pygments python3-pygments
对于我(也是Ubuntu18.04)来说,安装目录的路径是:/usr/lib/python3/dist-packages/pygments
。在那里您会找到另一个名为 styles
的目录,其中存在所有现有的颜色主题(例如 autumn.py、fruity.py)。您可以创建自己的样式(如下:https://pygments.org/docs/styles/)并将相应的样式文件存储在这里。
我希望这能部分回答您的问题。
这是我如何让它工作的(假设 pygmentize 已经安装)。
- 运行
echo hello | pygmentize -P style=does_not_exist
将输出包含styles
目录的错误。 - 导航到
styles
目录。 - 下载 Pigments Dracula theme,解压并复制
dracula.py
到styles
目录。 - 测试
echo "const result = 'success';" | pygmentize -P style=dracula
,希望结果是德古拉主题!
我正在使用通过自制软件安装的 MacOS 和 pygmentize。