当前位置: 首页>>代码示例>>Python>>正文


Python HtmlFormatter._format_lines方法代码示例

本文整理汇总了Python中pygments.formatters.HtmlFormatter._format_lines方法的典型用法代码示例。如果您正苦于以下问题:Python HtmlFormatter._format_lines方法的具体用法?Python HtmlFormatter._format_lines怎么用?Python HtmlFormatter._format_lines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygments.formatters.HtmlFormatter的用法示例。


在下文中一共展示了HtmlFormatter._format_lines方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PygmentsHighlighter

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import _format_lines [as 别名]
class PygmentsHighlighter(object):
    """ highlight python code with a QSyntaxHighlighter,
        callable class (e.g. function with a state) to """

    def __init__(self):
        """ constructor """
        self._lexer = PythonLexer()
        self._formatter = HtmlFormatter()
        self._document = QtGui.QTextDocument()
        self._document.setDefaultStyleSheet(self._formatter.get_style_defs())
        self._format_cache = dict()

    def __call__(self, code):
        """ makes this class callable, actually do the highlightning """
        index = 0
        for token, text in self._lexer.get_tokens(code):
            length = len(text)
            char_format = self._get_format(token)
            pygmentsHighlighter._setFormat(index, length, char_format)
            index += length

    def _get_format(self, token):
        """ get the QTextCharFormat for a token """
        if token in self._format_cache:
            return self._format_cache[token]

        # get format from document
        code, html = next(self._formatter._format_lines([(token, u"dummy")]))
        self._document.setHtml(html)
        char_format = QtGui.QTextCursor(self._document).charFormat()

        # cache result
        self._format_cache[token] = char_format

        return char_format
开发者ID:knossos-project,项目名称:PythonQt,代码行数:37,代码来源:PygmentsHighlighter.py

示例2: _format_lines

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import _format_lines [as 别名]
 def _format_lines(self, tokensource):
     # resolve a bug that on oneliners we get a newline at the end that looks
     # kinda ugly...
     tuples = list(HtmlFormatter._format_lines(self, tokensource))
     last_tuple = tuples[-1]
     last_tuple = [(last_tuple[0], last_tuple[1].rstrip('\n'))]
     tuples = tuples[:-1] + last_tuple
     for tuple in tuples:
         yield tuple
开发者ID:EnTeQuAk,项目名称:inyoka-legacy,代码行数:11,代码来源:highlight.py

示例3: _format_lines

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import _format_lines [as 别名]
    def _format_lines(self, tokensource):
        buf = []
        for ttype, value in apply_filters(tokensource, [StripDocTestFilter()]):
            if ttype in Token.Sql:
                for t, v in HtmlFormatter._format_lines(self, iter(buf)):
                    yield t, v
                buf = []

                if ttype is Token.Sql:
                    yield 1, "<div class='show_sql'>%s</div>" % re.sub(r"(?:[{stop}|\n]*)$", "", value)
                elif ttype is Token.Sql.Link:
                    yield 1, "<a href='#' class='sql_link'>sql</a>"
                elif ttype is Token.Sql.Popup:
                    yield 1, "<div class='popup_sql'>%s</div>" % re.sub(r"(?:[{stop}|\n]*)$", "", value)
            else:
                buf.append((ttype, value))

        for t, v in _strip_trailing_whitespace(HtmlFormatter._format_lines(self, iter(buf))):
            yield t, v
开发者ID:GitHublong,项目名称:sqlalchemy,代码行数:21,代码来源:sqlformatter.py

示例4: _format_lines

# 需要导入模块: from pygments.formatters import HtmlFormatter [as 别名]
# 或者: from pygments.formatters.HtmlFormatter import _format_lines [as 别名]
 def _format_lines(self, tokensource):
     for tag, line in HtmlFormatter._format_lines(self, tokensource):
         if tag == 1:
             # sourcecode line
             line = '<span class=line>%s</span>' % line
         yield tag, line
开发者ID:ewdurbin,项目名称:klaus,代码行数:8,代码来源:utils.py


注:本文中的pygments.formatters.HtmlFormatter._format_lines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。