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


Python HTMLTranslator.visit_literal_block方法代码示例

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


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

示例1: visit_literal_block

# 需要导入模块: from docutils.writers.html5_polyglot import HTMLTranslator [as 别名]
# 或者: from docutils.writers.html5_polyglot.HTMLTranslator import visit_literal_block [as 别名]
    def visit_literal_block(self, node):
        # type: (nodes.Node) -> None
        if node.rawsource != node.astext():
            # most probably a parsed-literal block -- don't highlight
            return BaseTranslator.visit_literal_block(self, node)
        lang = self.highlightlang
        linenos = node.rawsource.count('\n') >= \
            self.highlightlinenothreshold - 1
        highlight_args = node.get('highlight_args', {})
        if 'language' in node:
            # code-block directives
            lang = node['language']
            highlight_args['force'] = True
        if 'linenos' in node:
            linenos = node['linenos']
        if lang is self.highlightlang_base:
            # only pass highlighter options for original language
            opts = self.highlightopts
        else:
            opts = {}

        highlighted = self.highlighter.highlight_block(
            node.rawsource, lang, opts=opts, linenos=linenos,
            location=(self.builder.current_docname, node.line), **highlight_args
        )
        starttag = self.starttag(node, 'div', suffix='',
                                 CLASS='highlight-%s' % lang)
        self.body.append(starttag + highlighted + '</div>\n')
        raise nodes.SkipNode
开发者ID:atodorov,项目名称:sphinx,代码行数:31,代码来源:html5.py

示例2: visit_literal_block

# 需要导入模块: from docutils.writers.html5_polyglot import HTMLTranslator [as 别名]
# 或者: from docutils.writers.html5_polyglot.HTMLTranslator import visit_literal_block [as 别名]
    def visit_literal_block(self, node):
        # type: (nodes.Node) -> None
        if node.rawsource != node.astext():
            # most probably a parsed-literal block -- don't highlight
            return BaseTranslator.visit_literal_block(self, node)

        lang = node.get('language', 'default')
        linenos = node.get('linenos', False)
        highlight_args = node.get('highlight_args', {})
        highlight_args['force'] = node.get('force_highlighting', False)
        if lang is self.builder.config.highlight_language:
            # only pass highlighter options for original language
            opts = self.builder.config.highlight_options
        else:
            opts = {}

        highlighted = self.highlighter.highlight_block(
            node.rawsource, lang, opts=opts, linenos=linenos,
            location=(self.builder.current_docname, node.line), **highlight_args
        )
        starttag = self.starttag(node, 'div', suffix='',
                                 CLASS='highlight-%s notranslate' % lang)
        self.body.append(starttag + highlighted + '</div>\n')
        raise nodes.SkipNode
开发者ID:willingc,项目名称:sphinx,代码行数:26,代码来源:html5.py


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