當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。