开发者

Preserving whitespace with Pygments

开发者 https://www.devze.com 2022-12-09 01:56 出处:网络
I\'m currently writing an application that uses Pygments to perform syntax highlighting.The problem I\'m having is any code I process with Pygments has the leading and trailing whitespace in the file

I'm currently writing an application that uses Pygments to perform syntax highlighting. The problem I'm having is any code I process with Pygments has the leading and trailing whitespace in the file removed, and a single line break added to t开发者_开发技巧he end. Is there a way to make Pygments preserve the whitespace?


I think you want to make your own lexer, e.g.

lexer = lexers.get_lexer_by_name("python", stripnl=False)

and explicitly pass it to pygment.highlight. See the lexers' reference here.

0

精彩评论

暂无评论...
验证码 换一张
取 消