【问题标题】:Python pygmentize ignores style optionsPython pygmentize 忽略样式选项
【发布时间】:2019-03-05 20:53:59
【问题描述】:

我正在尝试使用 pygments pygmentize 命令行程序来语法高亮 Python 3 代码,但它只是忽略了所有样式选项。我尝试了以下方法:

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

它要么返回帮助文本,要么返回默认样式。这是在 Windows 10 上。有人知道我做错了什么吗?

在尝试使用以下方法写出 html 文件时,它还会返回帮助:

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

【问题讨论】:

  • pygmentize -O style=colorful -l python3 e:\work\Python\repl.py 应该可以工作。运行 pygmentize -L styles 时是否列出了 colorful ?全部小写?

标签: python-3.7 pygmentize


【解决方案1】:

使用 Pygments 2.11 版,pygmentize --help 声明如下:

  -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"`.

这对我来说并不明显,但我使用了style 作为一个选项,它同时适用于-O-P

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

提醒:要列出可用样式,请运行pygmentize -L styles

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2014-01-01
    • 1970-01-01
    相关资源
    最近更新 更多