本文整理汇总了Python中docutils.nodes.Text方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.Text方法的具体用法?Python nodes.Text怎么用?Python nodes.Text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.Text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autosummary_table_visit_html
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def autosummary_table_visit_html(self, node):
"""Make the first column of the table non-breaking."""
try:
tbody = node[0][0][-1]
for row in tbody:
col1_entry = row[0]
par = col1_entry[0]
for j, subnode in enumerate(list(par)):
if isinstance(subnode, nodes.Text):
new_text = text_type(subnode.astext())
new_text = new_text.replace(u" ", u"\u00a0")
par[j] = nodes.Text(new_text)
except IndexError:
pass
# -- autodoc integration -------------------------------------------------------
示例2: make_field_list
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def make_field_list(self, data):
field_list = nodes.field_list()
for name, text, citations in data:
field = nodes.field()
field_name = nodes.field_name(text=name)
field_body = nodes.field_body()
para = nodes.paragraph(text=text)
if citations is not None and len(citations) > 0:
para += nodes.Text(" (")
for i, citation in enumerate(citations):
text = f"{citation.author}, {citation.year}"
para += nodes.reference(
internal=False, refuri=citation.doi, text=text)
if i != len(citations)-1:
para += nodes.Text("; ")
para += nodes.Text(")")
field_body += para
field += field_name
field += field_body
field_list += field
return field_list
示例3: process
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def process(self, doctree):
for node in doctree.traverse(cfgconfig):
config = node.config
context = node.context
options = self.domain.config_options[config]
if self.builder.config.cfg_options_summary is None:
new_content = []
elif len(options) == 0:
new_content = [nodes.Text("[No options defined for this config]")]
elif self.builder.config.cfg_options_summary == "table":
new_content = self.create_summary_table(config, context, options)
elif self.builder.config.cfg_options_summary == "list":
new_content = [self.create_option_reference(o, config, context) for o in options]
if len(new_content) > 1:
listnode = nodes.bullet_list()
for entry in new_content:
listnode += nodes.list_item('', entry)
new_content = [listnode]
else:
raise ValueError("unknown value for config option `cfg_options_summary`.")
node.replace_self(new_content)
示例4: create_option_reference
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def create_option_reference(self, option, config, context):
par = nodes.paragraph()
innernode = addnodes.literal_strong(option.dispname, option.dispname)
par += self.make_refnode(option.docname, option.anchor, innernode)
if option.config != config:
par += nodes.Text(" (from ")
par += self._make_config_xref(option.config)
par += nodes.Text(")")
if option.context is not None:
opt_context = option.context
if opt_context.startswith(context):
opt_context = opt_context[len(context):]
if opt_context:
par += nodes.Text(" in ")
par += addnodes.literal_emphasis(option.context, option.context)
return par
示例5: visit_Text
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def visit_Text(self, node):
parent = node.parent
while parent:
if isinstance(parent, node_blacklist):
return
parent = parent.parent
rawtext = node.rawsource
data = rawtext.split("@@")
if len(data) == 1:
return
nodes = []
for i in range(len(data)):
text = data[i]
if i % 2 == 0:
nodes.append(Text(text))
else:
formula = eval(text, pygrim.__dict__)
latex = formula.latex()
#nodes.append(literal(text, text))
nodes.append(math(latex, Text(latex)))
#nodes.append(math_block(latex, Text(latex)))
node.parent.replace(node, nodes)
示例6: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def run(self):
if not isinstance(self.state, states.SubstitutionDef):
raise self.error(
'Invalid context: the "%s" directive can only be used within '
'a substitution definition.' % self.name)
substitution_definition = self.state_machine.node
if 'trim' in self.options:
substitution_definition.attributes['ltrim'] = 1
substitution_definition.attributes['rtrim'] = 1
if 'ltrim' in self.options:
substitution_definition.attributes['ltrim'] = 1
if 'rtrim' in self.options:
substitution_definition.attributes['rtrim'] = 1
codes = self.comment_pattern.split(self.arguments[0])[0].split()
element = nodes.Element()
for code in codes:
try:
decoded = directives.unicode_code(code)
except ValueError as error:
raise self.error('Invalid character code: %s\n%s'
% (code, ErrorString(error)))
element += nodes.Text(decoded)
return element.children
示例7: term
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def term(self, lines, lineno):
"""Return a definition_list's term and optional classifiers."""
assert len(lines) == 1
text_nodes, messages = self.inline_text(lines[0], lineno)
term_node = nodes.term()
(term_node.source,
term_node.line) = self.state_machine.get_source_and_line(lineno)
term_node.rawsource = unescape(lines[0])
node_list = [term_node]
for i in range(len(text_nodes)):
node = text_nodes[i]
if isinstance(node, nodes.Text):
parts = self.classifier_delimiter.split(node.rawsource)
if len(parts) == 1:
node_list[-1] += node
else:
node_list[-1] += nodes.Text(parts[0].rstrip())
for part in parts[1:]:
classifier_node = nodes.classifier('', part)
node_list.append(classifier_node)
else:
node_list[-1] += node
return node_list, messages
示例8: depart_citation_reference
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def depart_citation_reference(self, node):
if self._use_latex_citations:
followup_citation = False
# check for a following citation separated by a space or newline
next_siblings = node.traverse(descend=False, siblings=True,
include_self=False)
if len(next_siblings) > 1:
next = next_siblings[0]
if (isinstance(next, nodes.Text) and
next.astext() in (' ', '\n')):
if next_siblings[1].__class__ == node.__class__:
followup_citation = True
if followup_citation:
self.out.append(',')
else:
self.out.append('}')
self.inside_citation_reference_label = False
else:
self.out.append(']}')
示例9: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def run(self):
if not isinstance(self.state, states.SubstitutionDef):
raise self.error(
'Invalid context: the "%s" directive can only be used within '
'a substitution definition.' % self.name)
substitution_definition = self.state_machine.node
if 'trim' in self.options:
substitution_definition.attributes['ltrim'] = 1
substitution_definition.attributes['rtrim'] = 1
if 'ltrim' in self.options:
substitution_definition.attributes['ltrim'] = 1
if 'rtrim' in self.options:
substitution_definition.attributes['rtrim'] = 1
codes = self.comment_pattern.split(self.arguments[0])[0].split()
element = nodes.Element()
for code in codes:
try:
decoded = directives.unicode_code(code)
except ValueError, error:
raise self.error(u'Invalid character code: %s\n%s'
% (code, ErrorString(error)))
element += nodes.Text(decoded)
示例10: implicit_inline
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def implicit_inline(self, text, lineno):
"""
Check each of the patterns in `self.implicit_dispatch` for a match,
and dispatch to the stored method for the pattern. Recursively check
the text before and after the match. Return a list of `nodes.Text`
and inline element nodes.
"""
if not text:
return []
for pattern, method in self.implicit_dispatch:
match = pattern.search(text)
if match:
try:
# Must recurse on strings before *and* after the match;
# there may be multiple patterns.
return (self.implicit_inline(text[:match.start()], lineno)
+ method(match, lineno) +
self.implicit_inline(text[match.end():], lineno))
except MarkupMismatch:
pass
return [nodes.Text(unescape(text), rawsource=unescape(text, 1))]
示例11: handle_signature
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def handle_signature(self,sig,signode):
sig = sig.strip()
type_name, name, arglist = protobuf_sig_regex.match(sig).groups()
if self.prefix:
signode += addnodes.desc_annotation(self.prefix+' ', self.prefix+' ')
if type_name:
signode += addnodes.desc_type(type_name, type_name)
if name:
signode += addnodes.desc_name(name,name)
if arglist:
paramlist = addnodes.desc_parameterlist()
for arg in arglist.split(','):
argtype, argname = arg.split(None,1)
param = addnodes.desc_parameter(noemph=True)
param += nodes.Text(argtype,argtype)
param += nodes.emphasis(' '+argname,' '+argname)
paramlist += param
signode += paramlist
return name
示例12: make_field
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def make_field(self, types, domain, items, env=None):
fieldname = nodes.field_name('', self.label)
listnode = self.list_type()
for fieldarg, content in items:
par = nodes.paragraph()
par.extend(self.make_xrefs(self.rolename, domain, fieldarg,
addnodes.literal_strong, env=env))
if content and content[0].astext():
par += nodes.Text(' ')
par += content
listnode += nodes.list_item('', par)
source = env.ref_context['conda:package']
backrefs = env.domains['conda'].data['backrefs'].setdefault(fieldarg, set())
backrefs.add((env.docname, source))
fieldbody = nodes.field_body('', listnode)
fieldbody.set_class('field-list-wrapped')
return nodes.field('', fieldname, fieldbody)
示例13: make_xref
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def make_xref(self, rolename, domain, target,
innernode=d_nodes.emphasis, contnode=None, env=None):
if not rolename:
return contnode or innernode(target, target)
title = target
if domain == 'eql' and rolename == 'type':
target = EQLTypeXRef.filter_target(target)
if target in EQLTypedField.ignored_types:
return d_nodes.Text(title)
refnode = s_nodes.pending_xref('', refdomain=domain,
refexplicit=title != target,
reftype=rolename, reftarget=target)
refnode += contnode or innernode(title, title)
if env:
env.domains[domain].process_field_xref(refnode)
refnode['eql-auto-link'] = True
return refnode
示例14: make_field
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def make_field(self, types, domain, item, env=None):
fieldarg, fieldtype = item
body = d_nodes.paragraph()
if fieldarg:
body.extend(self.make_xrefs(self.rolename, domain, fieldarg,
s_nodes.literal_strong, env=env))
body += d_nodes.Text('--')
typename = u''.join(n.astext() for n in fieldtype)
body.extend(
self.make_xrefs(self.typerolename, domain, typename,
s_nodes.literal_emphasis, env=env))
fieldname = d_nodes.field_name('', self.label)
fieldbody = d_nodes.field_body('', body)
node = d_nodes.field('', fieldname, fieldbody)
node['eql-name'] = self.name
node['eql-opname'] = fieldarg
if typename:
node['eql-optype'] = typename
return node
示例15: handle_signature
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Text [as 别名]
def handle_signature(self, sig, signode):
if '::' in sig:
mod, name = sig.strip().split('::')
else:
name = sig.strip()
mod = 'std'
display = name.replace('-', ' ')
if mod != 'std':
display = f'{mod}::{display}'
signode['eql-module'] = mod
signode['eql-name'] = name
signode['eql-fullname'] = fullname = f'{mod}::{name}'
signode += s_nodes.desc_annotation('type', 'type')
signode += d_nodes.Text(' ')
signode += s_nodes.desc_name(display, display)
return fullname