filenameオプションの例
初回公開: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("filename.html", 'w') as outfile: highlight(code, lexer, HtmlFormatter(filename="xxx.py"),outfile)
実行結果
filename.html
<div class="highlight"><span class="filename">xxx.py</span><pre><span></span><span class="k">print</span><span class="p">(</span><span class="s2">"Hello World"</span><span class="p">)</span> </pre></div>
html表示イメージ
xxx.py
print("Hello World")