本文整理匯總了Python中docutils.utils.code_analyzer.NumberLines方法的典型用法代碼示例。如果您正苦於以下問題:Python code_analyzer.NumberLines方法的具體用法?Python code_analyzer.NumberLines怎麽用?Python code_analyzer.NumberLines使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類docutils.utils.code_analyzer
的用法示例。
在下文中一共展示了code_analyzer.NumberLines方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from docutils.utils import code_analyzer [as 別名]
# 或者: from docutils.utils.code_analyzer import NumberLines [as 別名]
def run(self):
self.assert_has_content()
if self.arguments:
language = self.arguments[0]
else:
language = ''
set_classes(self.options)
classes = ['code']
if language:
classes.append(language)
if 'classes' in self.options:
classes.extend(self.options['classes'])
# set up lexical analyzer
try:
tokens = Lexer('\n'.join(self.content), language,
self.state.document.settings.syntax_highlight)
except LexerError as error:
raise self.warning(error)
if 'number-lines' in self.options:
# optional argument `startline`, defaults to 1
try:
startline = int(self.options['number-lines'] or 1)
except ValueError:
raise self.error(':number-lines: with non-integer start value')
endline = startline + len(self.content)
# add linenumber filter:
tokens = NumberLines(tokens, startline, endline)
node = nodes.literal_block('\n'.join(self.content), classes=classes)
self.add_name(node)
# if called from "include", set the source
if 'source' in self.options:
node.attributes['source'] = self.options['source']
# analyze content and add nodes for every token
for classes, value in tokens:
# print (classes, value)
if classes:
node += nodes.inline(value, value, classes=classes)
else:
# insert as Text to decrease the verbosity of the output
node += nodes.Text(value, value)
return [node]