本文整理汇总了Python中pygments.formatters.html.HtmlFormatter._highlight_lines方法的典型用法代码示例。如果您正苦于以下问题:Python HtmlFormatter._highlight_lines方法的具体用法?Python HtmlFormatter._highlight_lines怎么用?Python HtmlFormatter._highlight_lines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.formatters.html.HtmlFormatter
的用法示例。
在下文中一共展示了HtmlFormatter._highlight_lines方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _highlight_lines
# 需要导入模块: from pygments.formatters.html import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.html.HtmlFormatter import _highlight_lines [as 别名]
def _highlight_lines(self, tokensource):
"""
Highlighted the lines specified in the `hl_lines` option by
post-processing the token stream coming from `_format_lines`.
"""
if not isinstance(self.hl_lines, dict):
HtmlFormatter._highlight_lines(tokensource)
else:
hl_lines = {}
for css, lines in self.hl_lines.items():
hl_lines.update(dict([(line, css) for line in lines]))
hls = hl_lines.keys()
for i, (t, value) in enumerate(tokensource):
if t != 1:
yield t, value
if i + 1 in hls: # i + 1 because Python indexes start at 0
css = hl_lines[i + 1]
if css:
yield 1, '<span class="%s">%s</span>' % (css, value)
elif self.noclasses:
style = ''
if self.style.highlight_color is not None:
style = (' style="background-color: %s"' %
(self.style.highlight_color,))
yield 1, '<span%s>%s</span>' % (style, value)
else:
yield 1, '<span class="hll">%s</span>' % value
else:
yield 1, value