【问题标题】:How to use Dracula theme as a style in Pygments?如何在 Pygments 中使用 Dracula 主题作为样式?
【发布时间】:2020-06-24 01:55:02
【问题描述】:

我无法理解关于Pygments Styles 的文件,上面写着:

要使样式可用于 Pygments,您必须

  1. 要么将其注册为插件(参见plugin docs
  2. 或...将其放入文件 mondrian.py 并将此文件放入 pygments.styles 子包目录。

现在已经有了Dracula theme for Pygments,如何将其添加为新的pygments样式,以便我可以通过简单的命令行使用该样式(例如pygmentize -g xx.py)。

通过注册插件,或将dracula.py 放入pygements.styles subpackage directory(它在哪里?)。我就是不知道怎么做,也没有一个例子。

PS:我的操作系统是ubuntu-18.04,我通过sudo apt-get install python-pygments python3-pygments安装pygments

【问题讨论】:

    标签: pygments


    【解决方案1】:

    对于我来说(也是Ubuntu 18.04),安装目录的路径是:/usr/lib/python3/dist-packages/pygments。在那里,您会找到另一个名为 styles 的目录,其中存在所有现有的颜色主题(例如,fall.py、fruity.py)。您可以创建自己的样式(如下:https://pygments.org/docs/styles/)并将相应的样式文件存储在这里。

    我希望这部分回答了您的问题。

    【讨论】:

    • 非常感谢。我通过“sudo pip3 install pygments”安装了 pygments,我的目录是“/usr/local/lib/python3.6/dist-packages/pygments/styles”。我将“dracula.py”复制到这个文件夹并修改了__init__.py,然后通过“pygmentize -P style=dracula -g”得到新的样式
    【解决方案2】:

    这是我如何让它工作的(假设已经安装了 pygmentize)。

    1. 运行echo hello | pygmentize -P style=does_not_exist,将输出包含styles 目录的错误。
    2. 导航到styles 目录。
    3. 下载Pigments Dracula theme,解压并复制dracula.pystyles目录。
    4. 测试echo "const result = 'success';" | pygmentize -P style=dracula,希望结果是德古拉主题!

    我正在使用通过 homebrew 安装的 MacOS 和 pygmentize。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 2011-04-16
      • 2016-12-13
      • 2019-03-15
      • 1970-01-01
      • 2021-03-01
      相关资源
      最近更新 更多