我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用sphinx.addnodes.desc_addname()。
def handle_signature(self, sig, signode): ret = super().handle_signature(sig, signode) # Add the "@" prefix if ("decorator" in self.options or self.objtype in ["decorator", "decoratormethod"]): signode.insert(0, addnodes.desc_addname("@", "@")) # Now that the "@" has been taken care of, we can add in the regular # prefix. prefix = self._get_signature_prefix() if prefix: signode.insert(0, addnodes.desc_annotation(prefix, prefix)) # And here's the suffix: for optname in ["with", "async-with"]: if self.options.get(optname, "").strip(): # for some reason a regular space here gets stripped, so we # use U+00A0 NO-BREAK SPACE s = "\u00A0as {}".format(self.options[optname]) signode += addnodes.desc_annotation(s, s) return ret
def handle_signature(self, sig, signode): if sig != 'Configuration': # Add "component" to the beginning if it's a specific component signode.clear() # Add "component" which is the type of this thing signode += addnodes.desc_annotation('component ', 'component ') if '.' in sig: modname, clsname = sig.rsplit('.', 1) else: modname, clsname = '', sig # If there's a module name, then we add the module if modname: signode += addnodes.desc_addname(modname + '.', modname + '.') # Add the class name signode += addnodes.desc_name(clsname, clsname) else: # Add just "Configuration" signode += addnodes.desc_name(sig, sig) return sig
def handle_signature(self, sig, signode): path = self.get_display_path() signode['is_multiline'] = True line = addnodes.desc_signature_line() line['add_permalink'] = True for x in path: line += addnodes.desc_addname(x + '.', x + '.') line += addnodes.desc_name(sig, sig) if 'required' in self.options: line += addnodes.desc_annotation(' (required)', ' (required)') signode += line if 'default' in self.options: line = addnodes.desc_signature_line() line += addnodes.desc_type('Default: ', 'Default: ') line += nodes.literal(self.options['default'], self.options['default']) signode += line return sig
def handle_signature(self, sig, signode): if 'hidden' in self.options: return sig path = self.get_display_path() signode['is_multiline'] = True line = addnodes.desc_signature_line() line['add_permalink'] = True for x in path: line += addnodes.desc_addname(x + '.', x + '.') line += addnodes.desc_name(sig, sig) if 'required' in self.options: line += addnodes.desc_annotation(' (required)', ' (required)') signode += line if 'default' in self.options: line = addnodes.desc_signature_line() line += addnodes.desc_type('Default: ', 'Default: ') line += nodes.literal(self.options['default'], self.options['default']) signode += line return sig
def handle_signature(self, sig, signode): if 'hidden' in self.options: return sig path = self.get_display_path() for x in path: signode += addnodes.desc_addname(x + '.', x + '.') signode += addnodes.desc_name(sig, sig) if 'type' in self.options: t = ' (%s)' % self.options['type'] signode += addnodes.desc_annotation(t, t) return sig ###################################################################### # # Autodoc directives #
def handle_signature(self, sig, signode): ret = super(PyDecoratorMixin, self).handle_signature(sig, signode) signode.insert(0, addnodes.desc_addname('@', '@')) return ret
def parse_pdb_command(env, sig, signode): """Transform a pdb command signature into RST nodes.""" m = pdbcmd_sig_re.match(sig) if m is None: raise ValueError name, args = m.groups() fullname = name.replace('(', '').replace(')', '') signode += addnodes.desc_name(name, name) if args: signode += addnodes.desc_addname(' '+args, ' '+args) return fullname
def handle_signature(self, sig, signode): container_class_name = self.env.temp_data.get('swift:class') enum_case = None assoc_value = None raw_value = None # split on ( -> first part is case name parts = [x.strip() for x in sig.split('(', maxsplit=1)] enum_case = parts[0].strip() if len(parts) > 1: parts = parts[1].rsplit('=', maxsplit=1) assoc_value = parts[0].strip() if len(parts) > 1: raw_value = parts[1].strip() if assoc_value == "": assoc_value = None else: assoc_value = "(" + assoc_value else: parts = [x.strip() for x in sig.split('=', maxsplit=1)] enum_case = parts[0].strip() if len(parts) > 1: raw_value = parts[1].strip() # Add class name signode += addnodes.desc_name(enum_case, enum_case) if assoc_value: signode += addnodes.desc_type(assoc_value, assoc_value) if raw_value: signode += addnodes.desc_addname(raw_value, " = " + raw_value) if container_class_name: enum_case = container_class_name + '.' + enum_case return enum_case, enum_case, True
def handle_signature(self, sig, signode): """Transform an option description into RST nodes.""" count = 0 firstname = '' for potential_option in sig.split(', '): potential_option = potential_option.strip() m = option_desc_re.match(potential_option) if not m: self.env.warn( self.env.docname, 'Malformed option description %r, should ' 'look like "opt", "-opt args", "--opt args", ' '"/opt args" or "+opt args"' % potential_option, self.lineno) continue optname, args = m.groups() if count: signode += addnodes.desc_addname(', ', ', ') signode += addnodes.desc_name(optname, optname) signode += addnodes.desc_addname(args, args) if not count: firstname = optname signode['allnames'] = [optname] else: signode['allnames'].append(optname) count += 1 if not firstname: raise ValueError return firstname
def handle_signature(self, sig, signode): name, args = parse_directive(sig) desc_name = '.. %s::' % name signode += addnodes.desc_name(desc_name, desc_name) if len(args) > 0: signode += addnodes.desc_addname(args, args) return name
def describe_signature(self, signode, mode, env, prefix, parentScope): _verify_description_mode(mode) identifier = text_type(self) if mode == 'lastIsName': signode += addnodes.desc_name(identifier, identifier) else: signode += addnodes.desc_addname(identifier, identifier)
def handle_signature(self, sig, signode): signode += addnodes.desc_addname(sig, sig) return sig
def parse_directive(env, sig, signode): if not sig.startswith('.'): dec_sig = '.. %s::' % sig signode += addnodes.desc_name(dec_sig, dec_sig) return sig m = dir_sig_re.match(sig) if not m: signode += addnodes.desc_name(sig, sig) return sig name, args = m.groups() dec_name = '.. %s::' % name signode += addnodes.desc_name(dec_name, dec_name) signode += addnodes.desc_addname(args, args) return name
def handle_signature(self, sig, signode): container_class_name = self.env.temp_data.get('swift:class') match = var_sig.match(sig) if not match: self.env.warn( self.env.docname, 'invalid variable/constant documentation string "%s", ' % sig, self.lineno) return match = match.groupdict() if self.objtype == 'static_var': signode += addnodes.desc_addname("static var", "static var ") elif self.objtype == 'static_let': signode += addnodes.desc_addname("static let", "static let ") elif self.objtype == 'var': signode += addnodes.desc_addname("var", "var ") elif self.objtype == 'let': signode += addnodes.desc_addname("let", "let ") name = match['name'].strip() signature = name signode += addnodes.desc_name(name, name) if match['type']: typ = match['type'].strip() #signature += '-' + typ signode += addnodes.desc_type(typ, " : " + typ) if match['value'] and len(match['value']) > 0: value = match['value'].strip() signode += addnodes.desc_addname(value, " = " + value) elif match['value']: signode += addnodes.desc_addname('{ ... }', ' = { ... }') #signature += "-" + self.objtype if container_class_name: name = container_class_name + '.' + name signature = container_class_name + '.' + signature return name, signature, True
def handle_signature(self, sig, signode): sig = sig.strip() if '(' in sig and sig[-1:] == ')': prefix, arglist = sig.split('(', 1) prefix = prefix.strip() arglist = arglist[:-1].strip() else: prefix = sig arglist = None if '.' in prefix: nameprefix, name = prefix.rsplit('.', 1) else: nameprefix = None name = prefix objectname = self.env.ref_context.get('js:object') if nameprefix: if objectname: # someone documenting the method of an attribute of the current # object? shouldn't happen but who knows... nameprefix = objectname + '.' + nameprefix fullname = nameprefix + '.' + name elif objectname: fullname = objectname + '.' + name else: # just a function or constructor objectname = '' fullname = name signode['object'] = objectname signode['fullname'] = fullname if self.display_prefix: signode += addnodes.desc_annotation(self.display_prefix, self.display_prefix) if nameprefix: signode += addnodes.desc_addname(nameprefix + '.', nameprefix + '.') signode += addnodes.desc_name(name, name) if self.has_arguments: if not arglist: signode += addnodes.desc_parameterlist() else: _pseudo_parse_arglist(signode, arglist) return fullname, nameprefix