HtmlFormatterのclassprefixオプションの例
初回公開:2018/10/14
最終更新:未
サンプルコード
from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter code = 'print("Hello World")' lexer = get_lexer_by_name("python") with open("noclassprefix.html", 'w') as outfile: highlight(code, lexer, HtmlFormatter(),outfile) with open("classprefix.html", 'w') as outfile: highlight(code, lexer, HtmlFormatter(classprefix="xxx_"),outfile)
実行結果
noclassprefix.html
<div class="highlight"><pre><span></span><span class="k">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span> </pre></div>
classprefix.html
<div class="highlight"><pre><span></span><span class="xxx_k">print</span><span class="xxx_p">(</span><span class="xxx_s2">"Hello World"</span><span class="xxx_p">)</span> </pre></div>