本文整理匯總了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))