def run(self): lineno = self.state_machine.abs_line_number() target = nodes.target() section = nodes.section(classes=["detail-control"]) # env = self.state.document.settings.env # env.app.info("Parent %s" % self.state.parent.attributes) node = rest_method() # TODO(sdague): this is a super simplistic parser, should be # more robust. method, sep, url = self.content[0].partition(' ') node['method'] = method node['url'] = url node['target'] = self.state.parent.attributes['ids'][0] # We need to build a temporary target that we can replace # later in the processing to get the TOC to resolve correctly. temp_target = "%s-selector" % node['target'] target = nodes.target(ids=[temp_target]) self.state.add_target(temp_target, '', target, lineno) section += node return [target, section]
def index_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): # create new reference target env = inliner.document.settings.env targetid = 'index-%s' % env.new_serialno('index') targetnode = nodes.target('', '', ids=[targetid]) # split text and target in role content has_explicit_title, title, target = split_explicit_title(text) title = utils.unescape(title) target = utils.unescape(target) # if an explicit target is given, we can process it as a full entry if has_explicit_title: entries = process_index_entry(target, targetid) # otherwise we just create a "single" entry else: # but allow giving main entry main = '' if target.startswith('!'): target = target[1:] title = title[1:] main = 'main' entries = [('single', target, targetid, main)] indexnode = addnodes.index() indexnode['entries'] = entries set_role_source_info(inliner, lineno, indexnode) textnode = nodes.Text(title, title) return [indexnode, targetnode, textnode], []
def run(self): # type: () -> List[nodes.Node] modname = self.arguments[0].strip() noindex = 'noindex' in self.options self.env.ref_context['py:module'] = modname ret = [] if not noindex: self.env.domaindata['py']['modules'][modname] = (self.env.docname, self.options.get('synopsis', ''), self.options.get('platform', ''), 'deprecated' in self.options) # make a duplicate entry in 'objects' to facilitate searching for # the module in PythonDomain.find_obj() self.env.domaindata['py']['objects'][modname] = (self.env.docname, 'module') targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True) self.state.document.note_explicit_target(targetnode) # the platform and synopsis aren't printed; in fact, they are only # used in the modindex currently ret.append(targetnode) indextext = _('%s (module)') % modname inode = addnodes.index(entries=[('single', indextext, 'module-' + modname, '', None)]) ret.append(inode) return ret
def run(self): # filename *or* python code content, but not both if self.arguments and self.content: raise RuntimeError("bokeh-plot:: directive can't have both args and content") env = self.state.document.settings.env app = env.app if not hasattr(env, 'bokeh_plot_tmpdir'): env.bokeh_plot_tmpdir = mkdtemp() app.verbose("creating new temp dir for bokeh-plot cache: %s" % env.bokeh_plot_tmpdir) else: tmpdir = env.bokeh_plot_tmpdir if not exists(tmpdir) or not isdir(tmpdir): app.verbose("creating new temp dir for bokeh-plot cache: %s" % env.bokeh_plot_tmpdir) env.bokeh_plot_tmpdir = mkdtemp() else: app.verbose("using existing temp dir for bokeh-plot cache: %s" % env.bokeh_plot_tmpdir) # TODO (bev) verify that this is always the correct thing rst_source = self.state_machine.node.document['source'] rst_dir = dirname(rst_source) rst_filename = basename(rst_source) target_id = "%s.bokeh-plot-%d" % (rst_filename, env.new_serialno('bokeh-plot')) target_node = nodes.target('', '', ids=[target_id]) result = [target_node] try: source = self._get_source() except Exception: node = nodes.error(None, nodes.paragraph(text="Unable to generate Bokeh plot at %s:%d:" % (basename(rst_source), self.lineno)), nodes.paragraph(text=str(sys.exc_info()[1]))) return [node] source_position = self.options.get('source-position', 'below') if source_position == 'above': result += self._get_source_nodes(source) node = bokeh_plot() node['target_id'] = target_id node['source'] = source node['relpath'] = relpath(rst_dir, env.srcdir) node['rst_source'] = rst_source node['rst_lineno'] = self.lineno if 'alt' in self.options: node['alt'] = self.options['alt'] if self.arguments: node['path'] = self.arguments[0] env.note_dependency(node['path']) if len(self.arguments) == 2: node['symbol'] = self.arguments[1] result += [node] if source_position == 'below': result += self._get_source_nodes(source) return result
def indexmarkup_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): """Role for PEP/RFC references that generate an index entry.""" env = inliner.document.settings.env if not typ: typ = env.config.default_role else: typ = typ.lower() has_explicit_title, title, target = split_explicit_title(text) # type: bool, unicode, unicode # NOQA title = utils.unescape(title) target = utils.unescape(target) targetid = 'index-%s' % env.new_serialno('index') indexnode = addnodes.index() targetnode = nodes.target('', '', ids=[targetid]) inliner.document.note_explicit_target(targetnode) if typ == 'pep': indexnode['entries'] = [ ('single', _('Python Enhancement Proposals; PEP %s') % target, targetid, '', None)] anchor = '' # type: unicode anchorindex = target.find('#') if anchorindex > 0: target, anchor = target[:anchorindex], target[anchorindex:] if not has_explicit_title: title = "PEP " + utils.unescape(title) try: pepnum = int(target) except ValueError: msg = inliner.reporter.error('invalid PEP number %s' % target, line=lineno) prb = inliner.problematic(rawtext, rawtext, msg) return [prb], [msg] ref = inliner.document.settings.pep_base_url + 'pep-%04d' % pepnum sn = nodes.strong(title, title) rn = nodes.reference('', '', internal=False, refuri=ref+anchor, classes=[typ]) rn += sn return [indexnode, targetnode, rn], [] elif typ == 'rfc': indexnode['entries'] = [ ('single', 'RFC; RFC %s' % target, targetid, '', None)] anchor = '' anchorindex = target.find('#') if anchorindex > 0: target, anchor = target[:anchorindex], target[anchorindex:] if not has_explicit_title: title = "RFC " + utils.unescape(title) try: rfcnum = int(target) except ValueError: msg = inliner.reporter.error('invalid RFC number %s' % target, line=lineno) prb = inliner.problematic(rawtext, rawtext, msg) return [prb], [msg] ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum sn = nodes.strong(title, title) rn = nodes.reference('', '', internal=False, refuri=ref+anchor, classes=[typ]) rn += sn return [indexnode, targetnode, rn], []
def run(self): env = self.state.document.settings.env targetid = "tag-%d" % env.new_serialno('tag') targetnode = nodes.target('', '', ids=[targetid]) #the tags fetched from the custom directive are one piece of text #sitting in self.content[0] taggs = self.content[0].split(", ") links = [] for tagg in taggs: #create rst hyperlinks of format `Python <http://www.python.org/>`_. link = "`" + tagg +" <../tags/" + tagg + ".html>`_ " links.append(link) #put links back in a single comma-separated string together linkjoin = ", ".join(links) #replace content[0] with hyperlinks to display in admonition self.content[0] = linkjoin ad = make_admonition(tag, self.name, [_('Tags')], self.options, self.content, self.lineno, self.content_offset, self.block_text, self.state, self.state_machine) return [targetnode] + ad
def run(self): env = self.state.document.settings.env modname = self.arguments[0].strip() noindex = 'noindex' in self.options env.temp_data['lua:module'] = modname ret = [] if not noindex: env.domaindata['lua']['modules'][modname] = \ (env.docname, self.options.get('synopsis', ''), self.options.get('platform', ''), 'deprecated' in self.options) ids = "lua-module.%s" % (modname) # make a duplicate entry in 'objects' to facilitate searching for # the module in LuaDomain.find_obj() env.domaindata['lua']['objects'][modname] = (env.docname, 'module', ids) targetnode = nodes.target('', '', ids=[ids], ismod=True) self.state.document.note_explicit_target(targetnode) # the platform and synopsis aren't printed; in fact, they are only # used in the modindex currently ret.append(targetnode) indextext = _('%s (module)') % modname inode = addnodes.index(entries=[('single', indextext, ids, '')]) ret.append(inode) return ret
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
def run(self): self.env = self.state.document.settings.env modname = self.arguments[0].strip() # TODO: cache/memoize modules & symbols? if not modules: read_js(app, modules) mods = [ (name, mod) for name, mod in modules.items() if fnmatch.fnmatch(name, modname) ] ret = [] for name, mod in mods: if mod.is_private: continue if name != modname and not (mod.doc or mod.exports): # this module has no documentation, no exports and was # not specifically requested through automodule -> skip # unless requested if not self.options.get('undoc-matches'): continue modsource = mod['sourcefile'] if modsource: self.env.note_dependency(modsource) # not sure what that's used for as normal xrefs are resolved using the id directly target = nodes.target('', '', ids=['module-' + name], ismod=True) self.state.document.note_explicit_target(target) documenter = ModuleDocumenter(self, mod) ret.append(target) ret.extend(documenter.generate()) return ret
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
def add_target(self, ret): node = ret[0] env = self.state.document.settings.env # assign label automatically if math_number_all enabled if node['label'] == '' or (env.config.math_number_all and not node['label']): seq = env.new_serialno('sphinx.ext.math#equations') node['label'] = "%s:%d" % (env.docname, seq) # no targets and numbers are needed if not node['label']: return # register label to domain domain = env.get_domain('math') try: eqno = domain.add_equation(env, env.docname, node['label']) node['number'] = eqno # add target node target = nodes.target('', '', ids=['equation-' + node['label']]) self.state.document.note_explicit_target(target) ret.insert(0, target) except UserWarning as exc: self.state_machine.reporter.warning(exc.args[0], line=self.lineno)
def run(self): if len(self.content) == 0: # TODO: raise nice error that something is missing return string_vars = { 'uid': self.content[0], 'width': 480, 'height': 300, 'allowscriptaccess': 'allways', 'allowfullscreen': 'true', } # TODO: need to redo this #for item in self.content[1:]: # item = item.split('=') # if len(item) == 2: # key, value = item[0].strip(), item[1].strip() # if key in string_vars.keys(): # string_vars[key] = value env = self.state.document.settings.env targetid = "bliptv-%d" % env.new_serialno('embed') targetnode = nodes.target('', '', ids=[targetid]) ad = make_admonition(embed, self.name, ['Todo'], self.options, self.content, self.lineno, self.content_offset, self.block_text, self.state, self.state_machine) return [targetnode] + ad
def run(self): env = self.state.document.settings.env targetid = "taglist-%d" % env.new_serialno('taglist') targetnode = nodes.target('', '', ids=[targetid]) status = self.options.get('tag', '') if not status and self.content and self.content[0]: x = self.content[0].strip() res=re.match(r'^\[(.*?)\](.*)$',x) if res: status = res.group(1) self.content[0]=res.group(2).strip() taglist = get_tags(status) taglist_text = ' '.join([':tag:`%s`'% t for t in taglist]) self.content[0] = taglist_text +' '+ self.content[0] ad = [ tag_node() ] tag = tag_node() tag.line = self.lineno tag.tags = taglist self.state.nested_parse(self.content,self.content_offset,tag) return [targetnode, tag]
def role(name, rawtext, text, lineno, inliner, options={}, content=[]): env = inliner.document.settings.env # Generic index entries indexnode = addnodes.index() indexnode['entries'] = [] try: platform, version = text.split(' ', 1) targetid = 'os-{}-{}-{}'.format(platform, version, env.new_serialno('os')) indexnode['entries'].append([ 'single', 'Platform; {}; {}'.format(platform, version), targetid, '', None ]) except ValueError: platform = text version = '' targetid = 'os-{}-{}-{}'.format(platform, version, env.new_serialno('os')) indexnode['entries'].append([ 'single', 'Platform; {}'.format(platform), targetid, '', None ]) targetnode = nodes.target('', '', ids=[targetid]) text_node = nodes.strong(text='{}'.format(text)) return [targetnode, text_node, indexnode], []
def role(name, rawtext, text, lineno, inliner, options={}, content=[]): #version = self.arguments[0] #summary = self.arguments[1] version, summary = text.split(':', 1) summary = summary.strip() indexstring = 'bareos-{}; {}'.format(version, summary) idstring = 'bareos-{}-{}'.format(version, summary) _id = nodes.make_id(idstring) # Generic index entries indexnode = addnodes.index() indexnode['entries'] = [] indexnode['entries'].append([ 'pair', indexstring, _id, '', None ]) targetnode = nodes.target('', '', ids=[_id]) #text_node = nodes.Text(text='Version >= {}'.format(version)) #text_node = nodes.strong(text='Version >= {}'.format(version)) text_node = nodes.emphasis(text='Version >= {}'.format(version)) # target does not work with generated. #text_node = nodes.generated(text='Version >= {}'.format(version)) return [targetnode, text_node, indexnode], []
def role(name, rawtext, text, lineno, inliner, options={}, content=[]): env = inliner.document.settings.env try: command, parameter = text.split(' ', 1) except ValueError: command = text parameter = '' indexstring = 'Console; Command; {}'.format(command) targetid = 'bcommand-{}-{}'.format(command, env.new_serialno('bcommand')) # Generic index entries indexnode = addnodes.index() indexnode['entries'] = [] indexnode['entries'].append([ 'single', indexstring, targetid, '', None ]) targetnode = nodes.target('', '', ids=[targetid]) text_node = nodes.strong(text='{}'.format(text)) return [targetnode, text_node, indexnode], []
def run(self): latex = '\n'.join(self.content) if self.arguments and self.arguments[0]: latex = self.arguments[0] + '\n\n' + latex node = displaymath() node['latex'] = latex node['label'] = self.options.get('name', None) if node['label'] is None: node['label'] = self.options.get('label', None) node['nowrap'] = 'nowrap' in self.options node['image_format'] = self.options.get('image_format', default_image_format) try: node['docname'] = self.state.document.settings.env.docname except: pass ret = [node] set_source_info(self, node) if hasattr(self, 'src'): node.source = self.src if node['label']: tnode = nodes.target('', '', ids=['equation-' + node['label']]) self.state.document.note_explicit_target(tnode) ret.insert(0, tnode) return ret
def run(self): language = self.arguments[0] indexed_languages = self.options.get('index_as') or language index_specs = ['pair: {}; language'.format(l) for l in indexed_languages.splitlines()] name = nodes.fully_normalize_name(language) target = 'language-{}'.format(name) targetnode = nodes.target('', '', ids=[target]) self.state.document.note_explicit_target(targetnode) indexnode = addnodes.index() indexnode['entries'] = [] indexnode['inline'] = False set_source_info(self, indexnode) for spec in index_specs: indexnode['entries'].extend(process_index_entry(spec, target)) sectionnode = nodes.section() sectionnode['names'].append(name) title, messages = self.state.inline_text(language, self.lineno) titlenode = nodes.title(language, '', *title) sectionnode += titlenode sectionnode += messages self.state.document.note_implicit_target(sectionnode, sectionnode) self.state.nested_parse(self.content, self.content_offset, sectionnode) return [indexnode, targetnode, sectionnode]
def run(self): env = self.state.document.settings.env modname = self.arguments[0].strip() noindex = "noindex" in self.options env.ref_context["py:module"] = modname ret = [] if not noindex: env.domaindata["py"]["modules"][modname] = ( env.docname, self.options.get("synopsis", ""), self.options.get("platform", ""), "deprecated" in self.options, ) # make a duplicate entry in 'objects' to facilitate searching for # the module in PythonDomain.find_obj() env.domaindata["py"]["objects"][modname] = (env.docname, "module") targetnode = nodes.target("", "", ids=["module-" + modname], ismod=True) self.state.document.note_explicit_target(targetnode) # the platform and synopsis aren't printed; in fact, they are only # used in the modindex currently ret.append(targetnode) indextext = _("%s (module)") % modname inode = addnodes.index(entries=[("single", indextext, "module-" + modname, "", None)]) ret.append(inode) return ret
def run(self): modname = self.arguments[0].strip() env = self.state.document.settings.env env.temp_data['cf3:namespace'] = modname ret = [] if 'noindex' in self.options: return ret env.domaindata['cf3']['namespaces'][modname] = ( env.docname, self.options.get('synopsis', ''), 'deprecated' in self.options, ) targetnode = nodes.target( '', '', ids=['namespace-' + modname], ismod=True ) self.state.document.note_explicit_target(targetnode) ret.append(targetnode) indextext = _('%s (namespace)') % modname ret.append( addnodes.index(entries=[ ('single', indextext, 'namespace-' + modname, modname) ]) ) return ret
def run(self): pkgname = self.arguments[0].strip() env = self.state.document.settings.env env.ref_context['qbs:package'] = pkgname if 'noindex' in self.options: return [] sdkname = self.options.get('sdk', env.ref_context.get('qbs:sdk', None)) if sdkname: pkgname = sdkname + '.' + pkgname env.domaindata['qbs']['packages'][pkgname] = (env.docname, self.options.get('synopsis', '')) env.domaindata['qbs']['objects'][pkgname] = (env.docname, 'package') # target targetname = 'package-' + pkgname targetnode = nodes.target('', '', ids=[targetname], ismod=True) self.state.document.note_explicit_target(targetnode) # index if sdkname: itext = _('%s (Qbs Package in %s)') % (pkgname[len(sdkname) + 1:], sdkname) else: itext = _('%s (Qbs Package') % (pkgname[len(sdkname) + 1:]) inode = addnodes.index(entries=[('single', itext, targetname, '', None)]) return [targetnode, inode]
def add_target(self, ret): # type: (List[nodes.Node]) -> None node = cast(nodes.math_block, ret[0]) # assign label automatically if math_number_all enabled if node['label'] == '' or (self.config.math_number_all and not node['label']): seq = self.env.new_serialno('sphinx.ext.math#equations') node['label'] = "%s:%d" % (self.env.docname, seq) # no targets and numbers are needed if not node['label']: return # register label to domain domain = self.env.get_domain('math') try: eqno = domain.add_equation(self.env, self.env.docname, node['label']) # type: ignore # NOQA node['number'] = eqno # add target node node_id = make_id('equation-%s' % node['label']) target = nodes.target('', '', ids=[node_id]) self.state.document.note_explicit_target(target) ret.insert(0, target) except UserWarning as exc: self.state_machine.reporter.warning(exc, line=self.lineno)
def run(self): env = self.state.document.settings.env targetid = "altair-plot-{0}".format(env.new_serialno('altair-plot')) targetnode = nodes.target('', '', ids=[targetid]) code = '\n'.join(self.content) # Here we cache the code for use in later setup if not hasattr(env, 'altair_plot_setup'): env.altair_plot_setup = [] env.altair_plot_setup.append({ 'docname': env.docname, 'lineno': self.lineno, 'code': code, 'target': targetnode, }) result = [targetnode] if 'show' in self.options: source_literal = nodes.literal_block(code, code) source_literal['language'] = 'python' result.append(source_literal) return result
def run(self): label = self.options.get('label', None) spec = self.options.get('spec', None) caption = self.options.get('caption', None) alt = self.options.get('alt', None) nofig = 'nofig' in self.options loc = self.options.get('loc', None) figtable_node = figtable('', ids=[label] if label is not None else []) figtable_node['nofig'] = nofig if spec is not None: table_spec_node = addnodes.tabular_col_spec() table_spec_node['spec'] = spec figtable_node.append(table_spec_node) node = nodes.Element() self.state.nested_parse(self.content, self.content_offset, node) tablenode = node[0] if alt is not None: tablenode['alt'] = alt figtable_node.append(tablenode) if caption is not None: caption_node = nodes.caption('', '', nodes.Text(caption)) figtable_node.append(caption_node) if label is not None: targetnode = nodes.target('', '', ids=[label]) figtable_node.append(targetnode) if loc is not None: figtable_node['loc'] = '[' + loc + ']' return [figtable_node]
def run(self): env = self.state.document.settings.env targetid = "sphinxreportwarning-%s" % env.new_serialno( 'sphinxreportwarning' ) # env.index_num += 1 targetnode = nodes.target('', '', ids=[targetid]) # this sets the formatting self.options["class"] = "critical" if len(self.arguments) > 0: warningclass = self.arguments[0] else: warningclass = "generic" ad = make_admonition(sphinxreportwarning_node, self.name, [_('SphinxreportWarning')], self.options, self.content, self.lineno, self.content_offset, self.block_text, self.state, self.state_machine) # Attach a list of all sphinxreportwarnings to the environment, # the sphinxreportwarninglist works with the collected sphinxreportwarning nodes if not hasattr(env, 'sphinxreportwarning_all_sphinxreportwarnings'): env.sphinxreportwarning_all_sphinxreportwarnings = [] env.sphinxreportwarning_all_sphinxreportwarnings.append({ 'docname': env.docname, 'lineno': self.lineno, 'sphinxreportwarning': ad[0].deepcopy(), 'warningclass' : warningclass, 'target': targetnode, }) return [targetnode] + ad
def run(self): arguments = self.arguments[0].split('\n') env = self.state.document.settings.env targetid = 'index-%s' % env.new_serialno('index') targetnode = nodes.target('', '', ids=[targetid]) self.state.document.note_explicit_target(targetnode) indexnode = addnodes.index() indexnode['entries'] = ne = [] for entry in arguments: entry = entry.strip() for type in pairindextypes: if entry.startswith(type+':'): value = entry[len(type)+1:].strip() value = pairindextypes[type] + '; ' + value ne.append(('pair', value, targetid, value)) break else: for type in self.indextypes: if entry.startswith(type+':'): value = entry[len(type)+1:].strip() if type == 'double': type = 'pair' ne.append((type, value, targetid, value)) break # shorthand notation for single entries else: for value in entry.split(','): value = value.strip() if not value: continue ne.append(('single', value, targetid, value)) return [indexnode, targetnode]
def run(self): env = self.state.document.settings.env app = env.app # filename *or* python code content, but not both if self.arguments and self.content: raise SphinxError("bokeh-plot:: directive can't have both args and content") # process inline examples here if self.content: app.debug("[bokeh-plot] handling inline example in %r", env.docname) source = '\n'.join(self.content) # need docname not to look like a path docname = env.docname.replace("/", "-") serialno = env.new_serialno(env.docname) js_name = "bokeh-plot-%s-inline-%d.js" % (docname, serialno) # the code runner just needs a real path to cd to, this will do path = join(env.bokeh_plot_auxdir, js_name) (script, js, js_path, source) = _process_script(source, path, env.bokeh_plot_auxdir, js_name) env.bokeh_plot_files[js_name] = (script, js, js_path, source) # process example files here else: example_path = self.arguments[0][:-3] # remove the ".py" # if it's an "internal" example, the python parser has already handled it if example_path in env.bokeh_plot_files: app.debug("[bokeh-plot] handling internal example in %r: %s", env.docname, self.arguments[0]) (script, js, js_path, source) = env.bokeh_plot_files[example_path] # handle examples external to the docs source, e.g. gallery examples else: app.debug("[bokeh-plot] handling external example in %r: %s", env.docname, self.arguments[0]) source = open(self.arguments[0]).read() source = decode_utf8(source) docname = env.docname.replace("/", "-") serialno = env.new_serialno(env.docname) js_name = "bokeh-plot-%s-external-%d.js" % (docname, serialno) (script, js, js_path, source) = _process_script(source, self.arguments[0], env.bokeh_plot_auxdir, js_name) env.bokeh_plot_files[js_name] = (script, js, js_path, source) # use the source file name to construct a friendly target_id target_id = "%s.%s" % (env.docname, basename(js_path)) target = nodes.target('', '', ids=[target_id]) result = [target] code = nodes.literal_block(source, source, language="python", linenos=False, classes=[]) set_source_info(self, code) source_position = self.options.get('source-position', 'below') if source_position == "above": result += [code] result += [nodes.raw('', script, format="html")] if source_position == "below": result += [code] return result
def run(self): label = self.options.get('label', None) width = self.options.get('width', None) alt = self.options.get('alt', None) node = subfigend('', ids=[label] if label is not None else []) if width is not None: node['width'] = width if alt is not None: node['alt'] = alt if self.content: anon = nodes.Element() self.state.nested_parse(self.content, self.content_offset, anon) first_node = anon[0] if isinstance(first_node, nodes.paragraph): caption = nodes.caption(first_node.rawsource, '', *first_node.children) node += caption if label is not None: targetnode = nodes.target('', '', ids=[label]) node.append(targetnode) return [node]
def run(self): env = self.state.document.settings.env # create a new target node for linking to targetid = "todo-%d" % env.new_serialno("todo") targetnode = nodes.target("", "", ids=[targetid]) # make the admonition node ad = make_admonition( Todo, self.name, [("Todo")], self.options, self.content, self.lineno, self.content_offset, self.block_text, self.state, self.state_machine, ) # store a handle in a global list of all todos if not hasattr(env, "todo_all_todos"): env.todo_all_todos = [] env.todo_all_todos.append( {"docname": env.docname, "lineno": self.lineno, "todo": ad[0].deepcopy(), "target": targetnode} ) # return both the linking target and the node itself return [targetnode] + ad
def run(self): env = self.state.document.settings.env modname = self.arguments[0].strip() noindex = 'noindex' in self.options env.temp_data['tcpip:module'] = modname env.domaindata['tcpip']['modules'][modname] = \ (env.docname, self.options.get('synopsis', ''), self.options.get('platform', ''), 'deprecated' in self.options) targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True) self.state.document.note_explicit_target(targetnode) ret = [targetnode] # XXX this behavior of the module directive is a mess... if 'platform' in self.options: platform = self.options['platform'] node = nodes.paragraph() node += nodes.emphasis('', _('Platforms: ')) node += nodes.Text(platform, platform) ret.append(node) # the synopsis isn't printed; in fact, it is only used in the # modindex currently if not noindex: indextext = _('%s (module)') % modname inode = addnodes.index(entries=[('single', indextext, 'module-' + modname, modname)]) ret.append(inode) return ret
def run(self): env = self.state.document.settings.env show_code = 'hide-code' not in self.options code_below = 'code-below' in self.options setupcode = '\n'.join(item['code'] for item in getattr(env, 'ipywidgets_setup', []) if item['docname'] == env.docname) code = '\n'.join(self.content) if show_code: source_literal = nodes.literal_block(code, code) source_literal['language'] = 'python' # get the name of the source file we are currently processing rst_source = self.state_machine.document['source'] rst_dir = os.path.dirname(rst_source) # use the source file name to construct a friendly target_id serialno = env.new_serialno('jupyter-widget') target_id = "jupyter-widget-%d" % serialno target_node = nodes.target('', '', ids=[target_id]) # create the node in which the widget will appear; # this will be processed by html_visit_widget widget_node = widget() widget_node['code'] = code widget_node['setupcode'] = setupcode widget_node['relpath'] = os.path.relpath(rst_dir, env.srcdir) widget_node['rst_source'] = rst_source widget_node['rst_lineno'] = self.lineno if 'alt' in self.options: widget_node['alt'] = self.options['alt'] result = [target_node] if code_below: result += [widget_node] if show_code: result += [source_literal] if not code_below: result += [widget_node] return result
def run(self): # type: () -> Tuple[List[nodes.Node], List[nodes.system_message]] # NOQA target_id = "index-%s" % self.env.new_serialno("index") self.http_type = self.name.lower()[4:] if self.http_type not in HTTPRole.NAME_MAP: msg = self.inliner.reporter.error("invalid HTTP reference %s" % self.name, line=self.lineno) prb = self.inliner.problematic(self.rawtext, self.rawtext, msg) return [prb], [msg] entries = [( "single", "HTTP; HTTP %s %s" % (self.http_type, self.target), target_id, "", None, )] index = addnodes.index(entries=entries) target = nodes.target("", "", ids=[target_id]) self.inliner.document.note_explicit_target(target) try: refuri = self.build_uri() reference = nodes.reference("", "", internal=False, refuri=refuri, classes=["rfc"]) if self.has_explicit_title: reference += nodes.strong(self.title, self.title) else: title = "HTTP %s %s " % (self.http_type, self.target) if _is_status(self): title += " " + httpclient.responses[int(self.target)] reference += nodes.strong(title, title) except ValueError: msg = self.inliner.reporter.error( "invalid HTTP mozilla reference %s" % self.target, line=self.lineno) prb = self.inliner.problematic(self.rawtext, self.rawtext, msg) return [prb], [msg] return [index, target, reference], []
def _wrap_in_section(self, schema, table): result = list() if '$$target' in schema: # Wrap section and table in a target (anchor) node so # that it can be referenced from other sections. labels = self.app.env.domaindata['std']['labels'] anonlabels = self.app.env.domaindata['std']['anonlabels'] docname = self.app.env.docname targets = schema['$$target'] if not isinstance(targets, list): targets = [targets] targetnode = nodes.target() for target in targets: anchor = normalize_name(target) targetnode['ids'].append(anchor) targetnode['names'].append(anchor) anonlabels[anchor] = docname, targetnode['ids'][0] labels[anchor] = docname, targetnode['ids'][0], ( schema['title'] if 'title' in schema else anchor) targetnode.line = self.lineno result.append(targetnode) if 'title' in schema: # Wrap the resulting table in a section giving it a caption and an # entry in the table of contents. memo = self.state.memo mylevel = memo.section_level memo.section_level += 1 section_node = nodes.section() textnodes, title_messages = self.state.inline_text( schema['title'], self.lineno) titlenode = nodes.title(schema['title'], '', *textnodes) name = normalize_name(titlenode.astext()) section_node['names'].append(name) section_node += titlenode section_node += title_messages self.state.document.note_implicit_target(section_node, section_node) section_node += table memo.section_level = mylevel result.append(section_node) else: result.append(table) return result
def run(self): env = self.state.document.settings.env directory = normalized_directory_name(self.arguments[0].strip()) env.temp_data['snip:directory'] = directory if 'noindex' not in self.options: # create an index entry directories = env.domaindata['snip']['directories'] directories[directory] = DirectoryEntry(env.docname) target = nodes.target('', '', ids=[directory]) self.state.document.note_explicit_target(target) indextext = '{0} (snippet directory)'.format(directory) index = addnodes.index( entries=[('single', indextext, directory, '')]) return [target, index] else: return []
def run(self): rst_source = self.state_machine.node.document["source"] rst_filename = basename(rst_source) serial_no = self.env.new_serialno("ccb") target_id = f"{rst_filename}.ccb-{serial_no}".replace(".", "-") target = nodes.target("", "", ids=[target_id]) block = collapsible_code_block(target_id=target_id, heading=self.options.get( "heading", "Code")) cb = CodeBlock.run(self) block.setup_child(cb[0]) block.children.append(cb[0]) return [target, block]
def run(self): text = ''.join(self.content) # Create the admonition node, to be populated by `nested_parse`. index_node = index(rawsource=text) # Parse the directive contents. self.state.nested_parse(self.content, self.content_offset, index_node) targetid = 'index-%s' % Index.count Index.count += 1 target_node = nodes.target('', '', ids=[targetid]) index_node['entries'] = ne = [] index_node['inline'] = False if self.arguments: arguments = self.arguments[0].split('\n') for entry in arguments: ne.extend(process_index_entry(entry, targetid)) return [index_node, target_node]
def run(self): env = self.state.document.settings.env if not hasattr(env, 'need_all_needtables'): env.need_all_needtables = {} # be sure, global var is available. If not, create it if not hasattr(env, 'needs_all_needs'): env.needs_all_needs = {} targetid = "needtable-{docname}-{id}".format( docname=env.docname, id=env.new_serialno('needtable')) targetnode = nodes.target('', '', ids=[targetid]) columns = str(self.options.get("columns", "")) if len(columns) == 0: columns = env.app.config.needs_table_columns if isinstance(columns, str): columns = [col.strip() for col in re.split(";|,", columns)] columns = [col.upper() for col in columns] style = self.options.get("style", "").upper() # Add the need and all needed information env.need_all_needtables[targetid] = { 'docname': env.docname, 'lineno': self.lineno, 'target_node': targetnode, 'columns': columns, 'style': style, # As the following options are flags, the content is None, if set. # If not set, the options.get() method returns False 'show_filters': True if self.options.get("show_filters", False) is None else False, 'show_parts': True if self.options.get("show_parts", False) is None else False } env.need_all_needtables[targetid].update( self.collect_filter_attributes()) return [targetnode] + [Needtable('')]
def _section(self, title): """Generate section node for given title. title: title: String title to use when creating a section. Returns: Tuple (nodes.target, nodes.section) section nodes. """ target = nodes.target() section = nodes.section() section_text_nodes, _ = self.state.inline_text(title, self.lineno) section_title = nodes.title(title, '', *section_text_nodes) section += section_title self.state.add_target(title, '', target, self.lineno) return (target, section)
def run(self): env = self.state.document.settings.env modname = self.arguments[0].strip() noindex = 'noindex' in self.options env.temp_data['nscp:module'] = modname env.domaindata['nscp']['modules'][modname] = (env.docname, self.options.get('synopsis', ''), 'deprecated' in self.options) ret = [] if not noindex: targetnode = nodes.target('', '', ids=['module-' + modname], ismod=True) self.state.document.note_explicit_target(targetnode) # the platform and synopsis aren't printed; in fact, they are only # used in the modindex currently ret.append(targetnode) indextext = _('%s (module)') % modname inode = addnodes.index(entries=[('single', indextext, modname, '')]) ret.append(inode) return ret
def run(self): self.assert_has_content() title = self.arguments[0] content = '\n'.join(self.content) latex = self.prepare_latex(content) math_node = self.make_math_node(latex) tid = nodes.make_id(title) target = nodes.target('', '', ids=['inference-' + tid]) self.state.document.note_explicit_target(target) term, desc = nodes.term('', title), nodes.description('', math_node) dli = nodes.definition_list_item('', term, desc) dl = nodes.definition_list(content, target, dli) set_source_info(self, dl) return [dl]
def run(self): targetid = 'lkqldocclass-%d' % self.env.new_serialno('lkqldocclass') targetnode = nodes.target('', '', ids=[targetid]) cls_name = self.arguments[0] if not hasattr(self.env, 'documented_classes'): self.env.documented_classes = [] try: lkql_class = getattr(liblkqllang, cls_name) self.env.documented_classes.append(lkql_class) lkql_class.documented = True except AttributeError as e: raise ExtensionError(f"LKQL class not found: {cls_name}", e) return []
def run(self): # type: () -> List[nodes.Node] if not self.options.get('class'): self.options['class'] = ['admonition-todo'] (todo, ) = super(Todo, self).run() if isinstance(todo, nodes.system_message): return [todo] todo.insert(0, nodes.title(text=_('Todo'))) set_source_info(self, todo) targetid = 'index-%s' % self.env.new_serialno('index') # Stash the target to be retrieved later in latex_visit_todo_node. todo['targetref'] = '%s:%s' % (self.env.docname, targetid) targetnode = nodes.target('', '', ids=[targetid]) return [targetnode, todo]
def run(self): """ Build the rst document node from the directive content. """ env = self.state.document.settings.env if not hasattr(env, "gmt_namespaces"): env.gmt_namespaces = {} namespace = env.gmt_namespaces.setdefault(env.docname, {}).setdefault( self.options.get("namespace", "default"), {}) code = "\n".join(self.content) # Get the name of the source file we are currently processing rst_source = self.state_machine.document["source"] rst_dir = os.path.dirname(rst_source) rst_filename = os.path.basename(rst_source) # Use the source file name to construct a friendly target_id rst_base = rst_filename.replace(".", "-") serialno = env.new_serialno("gmt-plot") div_id = "{0}-gmt-plot-{1}".format(rst_base, serialno) target_id = "{0}-gmt-source-{1}".format(rst_base, serialno) # Create the node in which the plot will appear. This will be processed by # html_visit_gmt_plot plot_node = GMTPlotNode() plot_node["target_id"] = target_id plot_node["div_id"] = div_id plot_node["code"] = code plot_node["namespace"] = namespace plot_node["relpath"] = os.path.relpath(rst_dir, env.srcdir) plot_node["rst_source"] = rst_source plot_node["rst_lineno"] = self.lineno plot_node["width"] = self.options.get("width", "") plot_node["center"] = "center" in self.options if "alt" in self.options: plot_node["alt"] = self.options["alt"] result = [nodes.target("", "", ids=[target_id])] if "hide-code" not in self.options: source_literal = nodes.literal_block(code, code) source_literal["language"] = "python" result.append(source_literal) result.append(plot_node) return result
def row(self, prop, tbody): row = nodes.row() anchor = '{},{},{}'.format( self.arguments[0].split('/')[-1], self.options.get('pointer', ''), prop.name) target = nodes.target(ids=[anchor], names=[anchor.lower()]) if 'addtargets' in self.options: self.state.document.note_explicit_target(target) cell = nodes.entry('', target, nodes.literal('', nodes.Text(prop.name)), morecols=1) row += cell row += self.cell(prop.type) row += self.cell(prop.format or '') row += self.cell('Required' if prop.required else '') tbody += row row = nodes.row() row += self.cell(prop.title) if prop.description: cell = self.cell(prop.description or '', morecols=3) if prop.name in self.external_links: reference = nodes.reference( '', '', nodes.Text(self.external_links[prop.name]['text']), internal=False, refuri=self.external_links[prop.name]['url'], anchorname='') cell += nodes.paragraph('', nodes.Text('\n\nSee '), reference) elif 'nocrossref' not in self.options: ref = None if hasattr(prop.attributes, '__reference__'): ref = prop.attributes.__reference__['$ref'] elif hasattr(prop.items, '__reference__'): ref = prop.items.__reference__['$ref'] if ref: # just use the name at the end of the ref ref = ref.split('/')[-1] reference = nodes.reference('', '', nodes.Text(ref), internal=False, refuri='#' + ref.lower(), anchorname='') cell += nodes.paragraph('', nodes.Text('\n\nSee '), reference) if prop.deprecated: cell += nodes.paragraph('', nodes.Text('This property was deprecated in version {}' .format(prop.deprecated['deprecatedVersion']))) cell += nodes.paragraph('', nodes.Text(prop.deprecated['description'])) row += cell tbody += row
def run(self): env = self.state.document.settings.env section = self.arguments[0].strip() if ':' in self.name: self.domain, self.objtype = self.name.split(':', 1) else: self.domain, self.objtype = '', self.name if section == 'None': env.ref_context.pop(self.section_key, None) return [] env.ref_context[self.section_key] = section targetname = self.target_prefix + section node = nodes.target('', '', ids=[targetname]) self.state.document.note_explicit_target(node) indexentry = self.get_index_entry(section) inode = addnodes.index( entries = [ (self.indextype, indexentry, targetname, '', None)]) # find title of parent section node title = find_section_title(self.state.parent) data_key = CabalDomain.types[self.objtype] # find how many sections in this document were added num = env.domaindata['cabal']['index-num'].get(env.docname, 0) env.domaindata['cabal']['index-num'][env.docname] = num + 1 meta = Meta(since=self.options.get('since'), deprecated=self.options.get('deprecated'), removed=self.options.get('removed'), synopsis=self.options.get('synopsis'), index = num, title = title) store = env.domaindata['cabal'][data_key] if not section in store: store[section] = env.docname, targetname, meta return [inode, node]
def run(self): self.signatures = [] indexnode = super().run()[0] # makes calls to handle_signature table = nodes.inline(classes=['prodn-table']) tgroup = nodes.inline(classes=['prodn-column-group']) for i in range(3): tgroup += nodes.inline(classes=['prodn-column']) table += tgroup tbody = nodes.inline(classes=['prodn-row-group']) table += tbody # create rows for signature in self.signatures: lhs, op, rhs = signature position = self.state_machine.get_source_and_line(self.lineno) row = nodes.inline(classes=['prodn-row']) entry = nodes.inline(classes=['prodn-cell-nonterminal']) if lhs != "": target_name = 'grammar-token-' + lhs target = nodes.target('', '', ids=[target_name], names=[target_name]) # putting prodn-target on the target node won't appear in the tex file inline = nodes.inline(classes=['prodn-target']) inline += target entry += inline entry += notation_to_sphinx('@' + lhs, *position) else: entry += nodes.literal('', '') row += entry entry = nodes.inline(classes=['prodn-cell-op']) entry += nodes.literal(op, op) row += entry entry = nodes.inline(classes=['prodn-cell-production']) entry += notation_to_sphinx(rhs, *position) row += entry tbody += row return [indexnode, table] # only this node goes into the doc
def run(self): env = self.state.document.settings.env workspace_name = self.arguments[0].strip() workspace_path = self.options.get('path', '') env.ref_context['bazel:workspace'] = workspace_name ret = [] env.domaindata['bazel']['workspaces'][workspace_name] = (env.docname, workspace_path) # make a duplicate entry in 'objects' to facilitate searching for # the module in PythonDomain.find_obj() env.domaindata['bazel']['objects'][workspace_name] = (env.docname, 'workspace') targetnode = nodes.target('', '', ids=['workspace-' + workspace_name], ismod=True) self.state.document.note_explicit_target(targetnode) # the platform and synopsis aren't printed; in fact, they are only # used in the modindex currently ret.append(targetnode) indextext = _('%s (workspace)') % workspace_name inode = addnodes.index(entries=[('single', indextext, 'module-' + workspace_name, '', None)]) ret.append(inode) if self.options.get('hide', False) is None: # No output is wanted return ret workspace_string = workspace_name if self.options.get('show_type', False) is None: sig_type_string = 'workspace: ' ret.append(addnodes.desc_name(sig_type_string, sig_type_string, classes=['bazel', 'type', 'workspace'])) if workspace_path: workspace_string += ' ({})'.format(workspace_path) workspace_name_node = addnodes.desc_name(workspace_string, workspace_string) ret.append(workspace_name_node) contentnode = addnodes.desc_content() ret.append(contentnode) self.state.nested_parse(self.content, self.content_offset, contentnode) # DocFieldTransformer(self).transform_all(contentnode) return ret
def __call__(self, name, rawtext, text, lineno, inliner, options={}, content=[]): targetnode = nodes.target('', '') inliner.document.note_explicit_target(targetnode) targetid = targetnode['ids'][0] indexnode = addnodes.index() indexnode['entries'] = ne = [] indexnode['inline'] = True indexnode.source, indexnode.line = inliner.document.current_source, lineno ne.extend(process_index_entry(text, targetid)) textnode = self.node_class(text, text) return ([textnode, indexnode, targetnode], [])
def run(self): env = self.state.document.settings.env statename = self.arguments[0].strip() if "noindex" in self.options: return [] targetnode = nodes.target("", "", ids=["module-" + statename], ismod=True) self.state.document.note_explicit_target(targetnode) formula = env.temp_data.get("salt:formula") indextext = "{1} ({0}-formula)".format(formula, statename) inode = addnodes.index( entries=[("single", indextext, "module-{}".format(statename), "")] ) return [targetnode, inode]
def run(self): # type: () -> List[nodes.Node] if not self.options.get('class'): self.options['class'] = ['deprecated'] (deprecated, ) = super(Deprecated, self).run() if isinstance(deprecated, nodes.system_message): return [deprecated] deprecated.insert(0, nodes.title(text=_('Deprecated'))) set_source_info(self, deprecated) env = self.state.document.settings.env targetid = 'index-%s' % env.new_serialno('index') # Stash the target to be retrieved later in latex_visit_deprecated_node. deprecated['targetref'] = '%s:%s' % (env.docname, targetid) targetnode = nodes.target('', '', ids=[targetid]) return [targetnode, deprecated]
def index_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): arguments = arguments[0].split('\n') env = state.document.settings.env targetid = 'index-%s' % env.index_num env.index_num += 1 targetnode = nodes.target('', '', ids=[targetid]) state.document.note_explicit_target(targetnode) indexnode = addnodes.index() indexnode['entries'] = arguments for entry in arguments: try: type, string = entry.split(':', 1) env.note_index_entry(type.strip(), string.strip(), targetid, string.strip()) except ValueError: continue return [indexnode, targetnode]
def create_target_node(raw_text, text, target, language, lineno, document, extra_classes=[]): node = nodes.target(raw_text, '') node['names'] += [target] node['classes'] += extra_classes node.line = lineno if text: if language: node += HighlightedText(text, text, language=language) else: node += nodes.Text(text, text) document.note_explicit_target(node) return node
def run(self): # type: () -> List[nodes.Node] if not self.options.get('class'): self.options['class'] = ['experimental'] (experimental, ) = super(Experimental, self).run() if isinstance(experimental, nodes.system_message): return [experimental] experimental.insert(0, nodes.title(text=_('Experimental'))) set_source_info(self, experimental) env = self.state.document.settings.env targetid = 'index-%s' % env.new_serialno('index') # Stash the target to be retrieved later in latex_visit_experimental_node. experimental['targetref'] = '%s:%s' % (env.docname, targetid) targetnode = nodes.target('', '', ids=[targetid]) return [targetnode, experimental]
def run(self): latex = '\n'.join(self.content) if self.arguments and self.arguments[0]: latex = self.arguments[0] + '\n\n' + latex node = displaymath() node['latex'] = latex node['label'] = self.options.get('label', None) node['nowrap'] = 'nowrap' in self.options node['docname'] = self.state.document.settings.env.docname ret = [node] node.line = self.lineno if hasattr(self, 'src'): node.source = self.src if node['label']: tnode = nodes.target('', '', ids=['equation-' + node['label']]) self.state.document.note_explicit_target(tnode) ret.insert(0, tnode) return ret
def apply(self): env = self.document.settings.env # Treat some documents as ecm domain objects. objtype, sep, tail = env.docname.rpartition('/') make_index_entry = _ecm_index_objs.get(objtype) if make_index_entry: title = self.parse_title(env.docname) # Insert the object link target. targetid = '%s:%s' % (objtype, title) targetnode = nodes.target('', '', ids=[targetid]) self.document.insert(0, targetnode) # Insert the object index entry. indexnode = addnodes.index() indexnode['entries'] = [make_index_entry(title, targetid)] self.document.insert(0, indexnode) # Add to ecm domain object inventory _ecm_object_inventory(env, self.document, 1, objtype, targetid)
def run(self): env = self.state.document.settings.env cppmethod = CppMethod() cppmethod['name'] = self.arguments[0] # TODO: parse name targetname = '%s-%s' % ('cppmethod', cppmethod['name']) targetnode = nodes.target('', '', ids=[targetname]) self.state.document.note_explicit_target(targetnode) indextext = _('%s (C++ method)') % cppmethod['name'] inode = addnodes.index(entries=[('single', indextext, 'cppmethod-' + cppmethod['name'], cppmethod['name'])]) self.state.nested_parse(self.content, self.content_offset, cppmethod) return [inode, targetnode, cppmethod]
def run(self): name = self.options.get('name') env = self.state.document.settings.env targetid = "indigo-option-%d" % env.new_serialno('indigo-option') targetnode = nodes.target('', '', ids=[targetid]) section_node = OptionInfo() section_node['names'].append(normalize_name(name)) section_node['ids'].append(normalize_name(name)) #titlenode = nodes.title('', name + ' = ' + self.options.get('default')) titlenode = nodes.title('', name) section_node += titlenode new_list = nodes.field_list() new_list += self.make_field('type', nodes.Text(self.options.get('type'))) new_list += self.make_field('default', nodes.Text(self.options.get('default'))) new_list += self.make_field('description', nodes.Text(self.options.get('short'))) section_node += new_list text = '\n'.join(self.content) if text: self.state.nested_parse(self.content, self.content_offset, section_node) if not hasattr(env, 'indigo_options'): env.indigo_options = [] env.indigo_options.append({ 'docname': env.docname, 'lineno': self.lineno, 'name': name, 'type': self.options.get('type'), 'default': self.options.get('default'), 'short': self.options.get('short'), 'target': targetnode }) return [targetnode, section_node]
def list_entry(self, name, data): "Build an entry for the list of parameters." p1 = nodes.paragraph() p1 += nodes.target('', '', ids=[make_id(name)]) p1 += nodes.literal("", name) fl = nodes.field_list() if True: f = nodes.field() f += [nodes.field_name("", "Type"), nodes.field_body("", nodes.Text(" " + data["type"]))] fl += f f = nodes.field() value = nodes.paragraph() value += self.format_value(data["value"], data["type"]) if "units" in data: value += nodes.emphasis("", " ({})".format(data["units"])) f += [nodes.field_name("", "Default value"), nodes.field_body("", value)] fl += f if "choices" in data: choices = self.format_value(data["choices"], "keyword") f = nodes.field() f += [nodes.field_name("", "Choices"), nodes.field_body("", nodes.paragraph("", "", choices))] fl += f if "option" in data: option = self.format_value("-" + data["option"], "keyword") f = nodes.field() f += [nodes.field_name("", "Option"), nodes.field_body("", nodes.paragraph("", "", option))] fl += f p2 = nodes.paragraph() doc, _ = self.state.inline_text(data["doc"], self.lineno) p2 += doc p2 += fl return [p1, p2]
def toNodes(self, jsobj): targetid = INTERFACE_REF_ID % jsobj['id'] targetnode = nodes.target('', '', ids=[targetid]) defineList = nodes.definition_list() defineList += self.toDefItem('接口名称', value=jsobj['name']) defineList += self.toDefItem('接口ID', value=jsobj['id']) para = nodes.paragraph('', '') ref = ComponentInlineRefNode( componentCodeName=jsobj['Component']['codeName']) para += ref defineList += self.toDefItem('组件名称', Paragraph=para) para = nodes.paragraph('', '') invokingList = self.toInvolingList(jsobj['InvokingComponentList']) para += invokingList defineList += self.toDefItem('被以下组件调用', Paragraph=para) return [targetnode, defineList]
def finish_directive(_self, directive, node): env = _self.state.document.settings.env targetid = "%s-%d" % (directive, env.new_serialno(directive)) targetnode = nodes.target('', '', ids=[targetid]) _self.state.nested_parse(_self.content, _self.content_offset, node) if not hasattr(env, 'all_' + directive): setattr(env, 'all_' + directive, []) getattr(env, 'all_' + directive).append({ 'docname': env.docname, 'lineno': _self.lineno, directive: node.deepcopy(), 'target': targetnode, }) return [targetnode, node]