本文整理汇总了Python中sphinx.util.ws_re.sub函数的典型用法代码示例。如果您正苦于以下问题:Python sub函数的具体用法?Python sub怎么用?Python sub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sub函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_link
def process_link(self, env, refnode, has_explicit_title, title, target):
program = env.temp_data.get("std:program")
if not has_explicit_title:
if " " in title and not (title.startswith("/") or title.startswith("-")):
program, target = re.split(" (?=-|--|/)", title, 1)
program = ws_re.sub("-", program)
target = target.strip()
elif " " in target:
program, target = re.split(" (?=-|--|/)", target, 1)
program = ws_re.sub("-", program)
refnode["refprogram"] = program
return title, target
示例2: process_link
def process_link(self, env, refnode, has_explicit_title, title, target):
program = env.temp_data.get('std:program')
if not has_explicit_title:
if ' ' in title and not (title.startswith('/') or
title.startswith('-')):
program, target = re.split(' (?=-|--|/)', title, 1)
program = ws_re.sub('-', program)
target = target.strip()
elif ' ' in target:
program, target = re.split(' (?=-|--|/)', target, 1)
program = ws_re.sub('-', program)
refnode['refprogram'] = program
return title, target
示例3: handle_signature
def handle_signature(self, sig, signode):
name = self.options["name"]
parameters = json.loads(self.options["parameters"]) if "parameters" in self.options else []
return_v = json.loads(self.options["return"]) if "return" in self.options else ("", "")
prefix = self.options["prefix"] if "prefix" in self.options else ""
if not ("parameters" in self.options) or not ("return" in self.options):
print("WARNING: No parameters or return set for '" + name + "'")
signode += nodes.Text(prefix + " ", prefix + u"\xa0")
xref = addnodes.pending_xref(
":ref:`" + return_v[1] + "`",
refdomain="std",
reftype="ref",
reftarget=ws_re.sub(" ", return_v[1].lower()),
refexplicit=False,
)
xref += nodes.Text(return_v[0], return_v[0])
signode += xref
signode += nodes.Text(" ", u"\xa0")
signode += addnodes.desc_name(name, name)
paramlist = addnodes.desc_parameterlist()
for tn in parameters:
param = addnodes.desc_parameter("", "", noemph=True)
prefix = ""
if len(tn) > 3 and tn[3] == "True":
prefix += "ref "
if len(tn) > 4 and tn[4] == "True":
prefix += "out "
if prefix != "":
param += nodes.Text(prefix + " ", prefix + u"\xa0")
xref = addnodes.pending_xref(
":ref:`" + tn[2] + "`",
refdomain="std",
reftype="ref",
reftarget=ws_re.sub(" ", tn[2].lower()),
refexplicit=False,
)
xref += nodes.Text(tn[0], tn[0])
param += xref
param += nodes.emphasis(" " + tn[1], u"\xa0" + tn[1])
paramlist += param
signode += paramlist
return name, ""
示例4: resolve_info_references
def resolve_info_references(app, _env, refnode, contnode):
"""Resolve Info references.
Process all :class:`~sphinx.addnodes.pending_xref` nodes whose ``reftype``
is ``infonode``.
Replace the pending reference with a :class:`~docutils.nodes.reference`
node, which references the corresponding web URL, as stored in the database
referred to by :data:`HTMLXREF_URL`.
"""
if refnode["reftype"] != "infonode":
return None
target = ws_re.sub(" ", refnode["reftarget"])
match = INFO_RE.match(target)
if not match:
app.env.warn(refnode.source, "Invalid info target: {0}".format(target), refnode.line)
return contnode
manual = match.group("manual")
node = match.group("node")
xrefdb = app.env.info_htmlxref
uri = xrefdb.resolve(manual, node)
if not uri:
message = "Cannot resolve info manual {0}".format(manual)
app.env.warn(refnode.source, message, refnode.line)
return contnode
else:
reference = nodes.reference("", "", internal=False, refuri=uri, reftitle=target)
reference += contnode
return reference
示例5: process_link
def process_link(self, env, refnode, has_explicit_title, title, target):
"""Called after parsing title and target text, and creating the
reference node (given in *refnode*). This method can alter the
reference node and must return a new (or the same) ``(title, target)``
tuple.
"""
return title, ws_re.sub(' ', target)
示例6: run
def run(self):
env = self.state.document.settings.env
# normalize whitespace in fullname like XRefRole does
fullname = ws_re.sub(' ', self.arguments[0].strip())
targetname = '%s-%s' % (self.ref_type, fullname)
# keep the target; this may be used to generate a BBIndex later
targets = env.domaindata['bb']['targets'].setdefault(self.ref_type, {})
targets[fullname] = env.docname, targetname
# make up the descriptor: a target and potentially an index descriptor
node = nodes.target('', '', ids=[targetname])
ret = [node]
# add the target to the document
self.state.document.note_explicit_target(node)
# append the index node if necessary
entries = []
for tpl in self.indextemplates:
colon = tpl.find(':')
if colon != -1:
indextype = tpl[:colon].strip()
indexentry = tpl[colon+1:].strip() % (fullname,)
else:
indextype = 'single'
indexentry = tpl % (fullname,)
entries.append((indextype, indexentry, targetname, targetname))
if entries:
inode = addnodes.index(entries=entries)
ret.insert(0, inode)
return ret
示例7: run
def run(self):
# type: () -> List[nodes.Node]
# normalize whitespace in fullname like XRefRole does
fullname = ws_re.sub(' ', self.arguments[0].strip())
targetname = '%s-%s' % (self.name, fullname)
node = nodes.target('', '', ids=[targetname])
self.state.document.note_explicit_target(node)
ret = [node] # type: List[nodes.Node]
if self.indextemplate:
indexentry = self.indextemplate % (fullname,)
indextype = 'single'
colon = indexentry.find(':')
if colon != -1:
indextype = indexentry[:colon].strip()
indexentry = indexentry[colon + 1:].strip()
inode = addnodes.index(entries=[(indextype, indexentry,
targetname, '', None)])
ret.insert(0, inode)
name = self.name
if ':' in self.name:
_, name = self.name.split(':', 1)
std = cast(StandardDomain, self.env.get_domain('std'))
std.add_object(name, fullname, self.env.docname, targetname)
return ret
示例8: process_link
def process_link(self, env, refnode, has_explicit_title, title, target):
paren_start = target.index("(")
dot_start = target.rindex(".", 0, paren_start)
dot_start = target.rindex(".", 0, dot_start)
refnode['refdomain']='std'
refnode['reftype']='ref'
refnode['refexplicit']=True
return (target[dot_start+1:paren_start], ws_re.sub(' ', target.lower()))
示例9: process_link
def process_link(self, env, refnode, has_explicit_title, title, target):
paren_start = target.index("(")
dot_start = target.rindex(".", 0, paren_start)
dot_start = target.rindex(".", 0, dot_start)
refnode["refdomain"] = "std"
refnode["reftype"] = "ref"
refnode["refexplicit"] = True
return (target[dot_start + 1 : paren_start], ws_re.sub(" ", target.lower()))
示例10: run
def run(self):
env = self.state.document.settings.env
program = ws_re.sub("-", self.arguments[0].strip())
if program == "None":
env.temp_data["std:program"] = None
else:
env.temp_data["std:program"] = program
return []
示例11: run
def run(self):
env = self.state.document.settings.env
program = ws_re.sub('-', self.arguments[0].strip())
if program == 'None':
env.ref_context.pop('std:program', None)
else:
env.ref_context['std:program'] = program
return []
示例12: handle_signature
def handle_signature(self, sig, signode):
directive = get_config_directive(sig)
signode.clear()
# only show the directive (not daemon and resource type)
signode += addnodes.desc_name(sig, directive['shortid'])
# normalize whitespace like XRefRole does
name = ws_re.sub('', sig)
return name
示例13: run
def run(self):
env = self.state.document.settings.env
program = ws_re.sub('-', self.arguments[0].strip())
if program == 'None':
env.currprogram = None
else:
env.currprogram = program
return []
示例14: handle_signature
def handle_signature(self, sig, signode):
name = self.options['name']
parameters = json.loads(self.options['parameters']) if 'parameters' in self.options else []
return_v = json.loads(self.options['return']) if 'return' in self.options else ("","")
prefix = self.options['prefix'] if 'prefix' in self.options else ""
if not ('parameters' in self.options) or not ('return' in self.options):
print("WARNING: No parameters or return set for '" + name + "'")
signode += nodes.Text(prefix + ' ', prefix + u'\xa0')
xref = addnodes.pending_xref(
':ref:`' + return_v[1] + '`',
refdomain='std',
reftype='ref',
reftarget=ws_re.sub(' ', return_v[1].lower()),
refexplicit=False)
xref += nodes.Text(return_v[0], return_v[0])
signode += xref
signode += nodes.Text(' ', u'\xa0')
signode += addnodes.desc_name(name, name)
paramlist = addnodes.desc_parameterlist()
for tn in parameters:
param = addnodes.desc_parameter('', '', noemph=True)
prefix = ''
if len(tn) > 3 and tn[3] == "True":
prefix += "ref "
if len(tn) > 4 and tn[4] == "True":
prefix += "out "
if prefix != "":
param += nodes.Text(prefix + ' ', prefix + u'\xa0')
xref = addnodes.pending_xref(
':ref:`' + tn[2] + '`',
refdomain='std',
reftype='ref',
reftarget=ws_re.sub(' ', tn[2].lower()),
refexplicit=False)
xref += nodes.Text(tn[0], tn[0])
param += xref
param += nodes.emphasis(' '+tn[1], u'\xa0'+tn[1])
paramlist += param
signode += paramlist
return name, ""
示例15: _split
def _split(self, text, refnode, env):
try:
program, target = re.split(" (?=-|--|/)", text, 1)
except ValueError:
env.warn_node("Malformed :option: %r, does not contain option " "marker - or -- or /" % text, refnode)
return None, text
else:
program = ws_re.sub("-", program)
return program, target