HtmlFormatterのprestylesオプションの例
初回公開: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("default.html", 'w') as outfile: highlight(code, lexer, HtmlFormatter(),outfile) with open("prestyles.html", 'w') as outfile: highlight(code, lexer, HtmlFormatter(prestyles="xxx"),outfile)
実行結果
default.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>
prestyles.html
<div class="highlight"><pre style="xxx"><span></span><span class="k">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span> </pre></div>