本文整理汇总了Python中pygments.lexers.Python3Lexer方法的典型用法代码示例。如果您正苦于以下问题:Python lexers.Python3Lexer方法的具体用法?Python lexers.Python3Lexer怎么用?Python lexers.Python3Lexer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.lexers
的用法示例。
在下文中一共展示了lexers.Python3Lexer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printargs
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def printargs():
"""Prints out all command-line parameters."""
switch = {BGColor.LIGHT: 'xcode',
BGColor.DARK: 'vim',
BGColor.UNKNOWN: 'default'}
style = switch[terminal_bg()]
pprint = print
try:
import pygments
from pygments.lexers import Python3Lexer
from pygments.formatters import Terminal256Formatter
pprint = partial(pygments.highlight, lexer=Python3Lexer(),
formatter=Terminal256Formatter(style=style),
outfile=sys.stdout)
except ImportError:
pass
print('Parameters:')
for key in sorted(ARGS):
v = repr(getattr(ARGS, key))
print('% 16s: ' % key, end='')
pprint(v)
print()
示例2: __init__
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def __init__(self, data):
# Logger
self.logger = Log()
# Max ID
self.max_id = 10 * 10 * 10
# Get tokens
self.logger.log('Getting tokens from file...')
self._tokens = list(Python3Lexer().get_tokens(data))
# Tokenize
self._tokenize()
# Get token by id
示例3: __init__
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def __init__(self, parent, lexer=None):
super(PygmentsHighlighter, self).__init__(parent)
self._document = self.document()
self._formatter = HtmlFormatter(nowrap=True)
self.set_style('default')
if lexer is not None:
self._lexer = lexer
else:
if PY3:
self._lexer = Python3Lexer()
else:
self._lexer = PythonLexer()
示例4: lexer3
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def lexer3():
yield Python3Lexer()
示例5: test_others_work
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def test_others_work():
"""Check other formatters don't crash."""
highlight(CODE, Python3Lexer(), LatexFormatter(style=MyStyle))
highlight(CODE, Python3Lexer(), HtmlFormatter(style=MyStyle))
示例6: test_256esc_seq
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def test_256esc_seq():
"""
Test that a few escape sequences are actually used when using ansi<> color
codes.
"""
def termtest(x):
return highlight(x, Python3Lexer(),
Terminal256Formatter(style=MyStyle))
assert '32;101' in termtest('0x123')
assert '92;42' in termtest('123')
assert '90' in termtest('#comment')
assert '94;41' in termtest('"String"')
示例7: render
# 需要导入模块: from pygments import lexers [as 别名]
# 或者: from pygments.lexers import Python3Lexer [as 别名]
def render(self, *args, **kwargs):
from pygments import highlight
from pygments.lexers import Python3Lexer
from pygments.formatters import HtmlFormatter
code = render_output(self.item, self.pprint.pformat)
formatter = HtmlFormatter(noclasses=True)
formatter.style.background_color = 'transparent'
return _format_output(highlight(code, Python3Lexer(), formatter))