【问题标题】:Pygments style not found找不到 Pygments 样式
【发布时间】:2014-08-18 16:50:16
【问题描述】:

我创建了一个pygments样式,使用了和xcode一样的颜色,命名为xcode.py

from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
     Number, Operator, Generic

class xcodeStyle(Style):
    default_style = ""
    styles = {
        Text:           '#000000',
        Comment:        '#008426',
        String:         '#D92823',
        Number:         '#2F2ECF',
        Keyword:        '#C22A9C',
        Name.Class:     '#753EA3'
    }

我尝试将它放在/Library/Python/2.7/site-packages/pygments/styles 中,但是当我列出可用样式时,

from pygments.styles import get_all_styles
styles = list(get_all_styles())
print styles

我的风格没有得到认可。任何想法为什么?

【问题讨论】:

  • 您解决了这个问题吗?我也遇到了同样的问题。
  • 是和不是。我最终浏览了 BitBucket 上的源代码,并找到了内置的 xcode 样式。所以我简单地安装了源代码(v2.0 Beta),就是这样。我刚刚检查过,在终端中运行pygmentize -L 时,甚至没有列出新样式。所以我猜 pygmentize 不知道它存在,但是当我使用它的风格时。我在带有 minted 包的 LaTex 中使用它,它就像一个魅力
  • 我意识到我已经用 Python 2 安装了 Pygments,所以我在 Python 3 目录中安装的样式自然会被忽略,因为 Python 2 pygmentize 首先出现在 PATH 中。

标签: xcode pygments


【解决方案1】:

确实,如何从他们的官方文档中添加自定义 pygments 样式还不是很清楚。但我在一段时间后想通了。

Sphinx 有一个 conf.py 参数https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-pygments_style 这可能是fully-qualified name of a custom Pygments style class。这是我们应该使用的。

好的,步骤:

  • 创建一个 python 模块,例如my_fancy_style.py 和你的风格课 MyFancyStyle

  • my_fancy_style.py 放在您的conf.py 所在的同一目录中。

  • conf.py 行中取消注释/写入,以便 sphinx 能够找到您的班级

import os
import sys
sys.path.insert(0, os.path.abspath('.'))
# ...
pygments_style = 'my_fancy_style.MyFancyStyle'

就是这样!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2011-10-01
    • 2020-08-06
    • 2018-07-14
    相关资源
    最近更新 更多