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