def generate_breadcrumb(self): "Generate ordered and linked 'breadcrumb' path list. " #sep = self.document.settings.breadcrumb_path_separator sep = '/' path = getattr(self.document.settings, 'breadcrumb_path') if not path: path = self.document['source'] breadcrumb = nodes.enumerated_list(classes=['breadcrumb']) # TODO: much more customization, what about domain, etc? s,h,path,para,q,f = urlparse.urlparse(path) dirs = path.split(sep) or [] _p = [] while dirs: dn = dirs.pop(0) _p.append(dn) if dirs: href = sep.join(_p) or sep # XXX: fix the path to be absolute if not href.startswith(sep): href = sep+href dn += sep ref = nodes.reference('', nodes.Text(dn), refuri=href) else: ref = nodes.Text(dn) p = nodes.paragraph('', '', ref) item = nodes.list_item() item.append(p) breadcrumb.append(item) return breadcrumb
def process_validators(self, field): validators = nodes.enumerated_list() for v in field.validators: vp_key = '%s.%s' % (v.__class__.__module__, v.__class__.__name__) vp = validator_processors.get(vp_key, None) if vp: validators.append(nodes.list_item('', nodes.paragraph(text=vp(v)))) return validators
def enumerator(self, match, context, next_state): format, sequence, text, ordinal = self.parse_enumerator(match) if not self.is_enumerated_list_item(ordinal, sequence, format): raise statemachine.TransitionCorrection('text') enumlist = nodes.enumerated_list() self.parent += enumlist if sequence == '#': enumlist['enumtype'] = 'arabic' else: enumlist['enumtype'] = sequence enumlist['prefix'] = self.enum.formatinfo[format].prefix enumlist['suffix'] = self.enum.formatinfo[format].suffix if ordinal != 1: enumlist['start'] = ordinal msg = self.reporter.info( 'Enumerated list start value not ordinal-1: "%s" (ordinal %s)' % (text, ordinal)) self.parent += msg listitem, blank_finish = self.list_item(match.end()) enumlist += listitem offset = self.state_machine.line_offset + 1 # next line newline_offset, blank_finish = self.nested_list_parse( self.state_machine.input_lines[offset:], input_offset=self.state_machine.abs_line_offset() + 1, node=enumlist, initial_state='EnumeratedList', blank_finish=blank_finish, extra_settings={'lastordinal': ordinal, 'format': format, 'auto': sequence == '#'}) raw = [] indent = ' ' def _indent(line): if line == '': return '' return indent + line index = 1 for child in enumlist.children: if enumlist['enumtype'] == 'arabic': prefix = '# ' else: prefix = '%s. ' % int2enum(index, enumlist['enumtype']) index += 1 lines = child.rawsource.split('\n') lines = [_indent(line) for line in lines] raw.append(prefix + '\n'.join(lines).lstrip()) enumlist.rawsource = '\n'.join(raw) if enumlist.rawsource.endswith('\n'): enumlist.rawsource = enumlist.rawsource[:-1] self.goto_line(newline_offset) if not blank_finish: self.parent += self.unindent_warning('Enumerated list') return [], next_state, []
def _parse(self, tree): if isinstance(tree, minidom.Document): return self._parse(tree.childNodes[0]) if isinstance(tree, minidom.Text): return nodes.Text(tree.data) # Get children. children = [self._parse(c) for c in tree.childNodes] if tree.tagName == 'epytext': return children if tree.tagName == 'para': return nodes.paragraph('','', *children) if tree.tagName == 'section': return nodes.section('', *children) if tree.tagName == 'heading': return nodes.title('','', *children) if tree.tagName == 'fieldlist': return nodes.field_list('', *children) if tree.tagName == 'field': return nodes.field('', *self._parse_field(tree, children)) if tree.tagName == 'literalblock': return nodes.literal_block('','', *children) if tree.tagName == 'doctestblock': return nodes.doctest_block('','', *children) if tree.tagName == 'ulist': return nodes.bullet_list('', *children) if tree.tagName == 'olist': return nodes.enumerated_list('', *children) if tree.tagName == 'li': return nodes.list_item('', *children) if tree.tagName == 'link': # [XX] discards link target. name, target = children return nodes.title_reference('','', name) if tree.tagName == 'uri': name, target = children return nodes.reference('','', name, refuid=target.astext()) if tree.tagName == 'code': return nodes.literal('','', *children) if tree.tagName == 'math': return nodes.emphasis('','', *children) if tree.tagName == 'italic': return nodes.emphasis('','', *children) if tree.tagName == 'bold': return nodes.strong('','', *children) if tree.tagName == 'indexed': # [XX] doesn't mark the fact that it's indexedd return nodes.emphasis('','', *children) if tree.tagName == 'symbol': # use substitutions. # [XX] this needs to be fixed! return nodes.Text(children[0]) elif tree.tagName in ('tag', 'arg', 'name', 'target'): return children[0] else: raise ValueError, ('unknown %s' % tree.tagName)
def list_block(self, block): list_node = None if (block.list_data['type'] == "Bullet"): list_node = nodes.bullet_list() else: list_node = nodes.enumerated_list() list_node.line = block.start_line with self._temp_current_node(list_node): self.convert_blocks(block.children) self.current_node.append(list_node)
def listNode(node): """ A list (numbered or not) For numbered lists, the suffix is only rendered as . in html """ if node.list_data['type'] == u'bullet': o = nodes.bullet_list(bullet=node.list_data['bullet_char']) else: o = nodes.enumerated_list(suffix=node.list_data['delimiter'], enumtype='arabic', start=node.list_data['start']) for n in MarkDown(node): o += n return o
def run(self): try: lines = self.parse_lit(self.parse_file(self.arguments[0])) except IOError as exc: document = self.state.document return [document.reporter.warning(str(exc), line=self.lineno)] node = nodes.container() node['classes'] = ['lit-container'] node.document = self.state.document enum = nodes.enumerated_list() enum['classes'] = ['lit-docs'] node.append(enum) # make first list item list_item = nodes.list_item() list_item['classes'] = ['lit-item'] for is_doc, line in lines: if is_doc and line == ['']: continue section = nodes.section() if is_doc: section['classes'] = ['lit-annotation'] nested_parse_with_titles(self.state, ViewList(line), section) else: section['classes'] = ['lit-content'] code = '\n'.join(line) literal = nodes.literal_block(code, code) literal['language'] = 'yaml' set_source_info(self, literal) section.append(literal) list_item.append(section) # If we have a pair of annotation/content items, append the list # item and create a new list item if len(list_item.children) == 2: enum.append(list_item) list_item = nodes.list_item() list_item['classes'] = ['lit-item'] # Non-semantic div for styling bg = nodes.container() bg['classes'] = ['lit-background'] node.append(bg) return [node]
def _doc_chain(self, widgetname, chainidx): ol = nodes.enumerated_list() chain = factory._blueprints[widgetname][chainidx] exist = False for el in chain: exist = True li = nodes.list_item() if hasattr(el, 'func_name'): # function li.append(nodes.paragraph(text=el.func_name)) else: # class li.append(nodes.paragraph(text=el.__class__.__name__)) ol.append(li) if exist: return ol return nodes.paragraph(text="-/-")
def run(self): with open(self.config["image_test_json"], "r") as fh: imagerepo = json.load(fh) enum_list = nodes.enumerated_list() nodelist = [] nodelist.append(enum_list) for test in sorted(imagerepo): link_node = nodes.raw( "", f'<a href="{self.config["html_baseurl"]}/generated/image_test/{test}.html" />{test}</a>', format="html", ) li_node = nodes.list_item("") li_node += link_node enum_list += li_node return nodelist
def _make_lists(node): if not isinstance(node, nodes.Element): return i = node.first_child_matching_class(make_list_from_sections) if i is not None: ol = nodes.enumerated_list('') ol += _items_from_sections(node[i + 1:]) node.children = node[:i] node += ol else: for child in node.children: _make_lists(child)
def make_checker_chaining(self): symbol = self.lookup_auto_symbol() if not symbol: return next_checkers = symbol.properties.get('flycheck-next-checkers') if not next_checkers: return title = nodes.title('', 'Chained syntax checkers') intro = nodes.paragraph() intro += nodes.Text('The following syntax checkers are ') chained = addnodes.pending_xref( 'chained', reftype='term', refdomain='std', reftarget='chaining', refwarn=True, refexplicit=True, reftitle='chaining', refdoc=self.env.docname) chained += nodes.emphasis('', 'chained') intro += chained intro += nodes.Text(' after this syntax checker:') checker_list = nodes.enumerated_list() para = nodes.paragraph() para += checker_list outro = nodes.paragraph() outro += nodes.Text('The ') outro += nodes.strong('', 'first') outro += nodes.Text(' suitable syntax checker is used.') chaining = nodes.admonition( '', title, intro, para, outro, classes=['note', 'el-flycheck-checker-chaining']) for next_checker in next_checkers: xref = addnodes.pending_xref( next_checker.checker, reftype='flyc-checker', refdomain='el', refexplicit=False, reftarget=next_checker.checker, refwarn=False, refdoc=self.env.docname) set_role_source_info(self.state.inliner, self.lineno, xref) xref += nodes.literal('', next_checker.checker, classes=['xref', 'el', 'el-flyc-checker']) para = nodes.paragraph() para += xref if next_checker.warnings_only: para += nodes.Text(', if there are only warnings') if next_checker.no_errors: para += nodes.Text(', if there are no errors') checker_list += nodes.list_item('', para) return chaining
def make_checker_chaining(self): symbol = self.lookup_auto_symbol() if not symbol: return next_checkers = symbol.properties.get('flycheck-next-checkers') if not next_checkers: return title = nodes.title('', 'Chained syntax checkers') intro = nodes.paragraph() intro += nodes.Text('The following syntax checkers are ') chained = addnodes.pending_xref( 'chained', reftype='term', refdomain='std', reftarget='chaining', refwarn=True, refexplicit=True, reftitle='chaining', refdoc=self.env.docname) chained += nodes.emphasis('', 'chained') intro += chained intro += nodes.Text(' after this syntax checker:') checker_list = nodes.enumerated_list() para = nodes.paragraph() para += checker_list outro = nodes.paragraph() outro += nodes.Text('The ') outro += nodes.strong('', 'first') outro += nodes.Text(' suitable syntax checker is used.') chaining = nodes.admonition( '', title, intro, para, outro, classes=['note', 'el-flycheck-checker-chaining']) for next_checker in next_checkers: xref = addnodes.pending_xref( next_checker.checker, reftype='flyc-checker', refdomain='el', refexplicit=False, reftarget=next_checker.checker, refwarn=False, refdoc=self.env.docname) set_role_source_info(self.state.inliner, self.lineno, xref) xref += nodes.literal('', next_checker.checker, classes=['xref', 'el', 'el-flyc-checker']) para = nodes.paragraph() para += xref if next_checker.maximum_level: para += nodes.Text(', if there are no errors above level ') para += nodes.literal('', next_checker.maximum_level) checker_list += nodes.list_item('', para) return chaining
def render_list(self, token): list_node = None if token.start_at is not None: list_node = nodes.enumerated_list() # TODO deal with token.start_at? # TODO support numerals/letters for lists # (see https://stackoverflow.com/a/48372856/5033292) # See docutils/docutils/parsers/rst/states.py:Body.enumerator # list_node['enumtype'] = 'arabic', 'loweralpha', 'upperroman', etc. # list_node['start'] # list_node['prefix'] # list_node['suffix'] else: list_node = nodes.bullet_list() # TODO deal with token.loose? self.add_line_and_source_path(list_node, token) self.current_node.append(list_node) with self.current_node_context(list_node): self.render_children(token)
def run(self): env = self.state.document.settings.env if not hasattr(env, 'bibtex_refs'): return [bibtex_bibliography()] # print dir(env) # print env.doc2path(env.docname) bibtex_refs = env.bibtex_refs env.bibtex_refs = [] entries = env.bibtex_entries style = Style(env.bibtex_style_dir, env.bibtex_style_name) list_node = nodes.enumerated_list() list_node['classes'].append('bibliography') for ref in bibtex_refs: if ref not in entries: raise self.warning("%s: reference not found." % ref) entry = entries[ref] rendered = style.render(pybtex_entry_to_dict(entry)) if not rendered: raise self.warning("%s: no template for entry type (%s)." % \ (ref, entry.type)) list_item = nodes.list_item() list_item['ids'].append(ref) list_item += nodes.raw(rendered, rendered, format="html") list_node += list_item bibliography = bibtex_bibliography() bibliography += list_node return [bibliography]
def process_mathdef_nodes(app, doctree, fromdocname): """ process_mathdef_nodes """ if not app.config['mathdef_include_mathsext']: for node in doctree.traverse(mathdef_node): node.parent.remove(node) # Replace all mathdeflist nodes with a list of the collected mathsext. # Augment each mathdef with a backlink to the original location. env = app.builder.env if hasattr(env, "settings") and hasattr(env.settings, "language_code"): lang = env.settings.language_code else: lang = "en" orig_entry = TITLES[lang]["original entry"] mathmes = TITLES[lang]["mathmes"] if not hasattr(env, 'mathdef_all_mathsext'): env.mathdef_all_mathsext = [] for ilist, node in enumerate(doctree.traverse(mathdeflist)): if 'ids' in node: node['ids'] = [] if not app.config['mathdef_include_mathsext']: node.replace_self([]) continue nbmath = 0 content = [] mathtag = node["mathtag"] add_contents = node["mathcontents"] mathdocname = node["docname"] if add_contents: bullets = nodes.enumerated_list() content.append(bullets) double_list = [(info.get('mathtitle', ''), info) for info in env.mathdef_all_mathsext] double_list.sort(key=lambda x: x[:1]) for n, mathdef_info_ in enumerate(double_list): mathdef_info = mathdef_info_[1] if mathdef_info["mathtag"] != mathtag: continue nbmath += 1 para = nodes.paragraph(classes=['mathdef-source']) if app.config['mathdef_link_only']: description = _('<<%s>>' % orig_entry) else: description = ( _(mathmes) % (orig_entry, os.path.split(mathdef_info['source'])[-1], mathdef_info['lineno']) ) desc1 = description[:description.find('<<')] desc2 = description[description.find('>>') + 2:] para += nodes.Text(desc1, desc1) # Create a reference newnode = nodes.reference('', '', internal=True) innernode = nodes.emphasis( _(orig_entry), _(orig_entry)) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, mathdef_info['docname']) try: newnode['refuri'] += '#' + mathdef_info['target']['refid'] except Exception as e: raise KeyError("refid in not present in '{0}'".format( mathdef_info['target'])) from e except NoUri: # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(innernode) para += newnode para += nodes.Text(desc2, desc2) # (Recursively) resolve references in the mathdef content mathdef_entry = mathdef_info['mathdef'] idss = ["index-mathdef-%d-%d" % (ilist, n)] # Insert into the mathreflist if add_contents: title = mathdef_info['mathtitle'] item = nodes.list_item() p = nodes.paragraph() item += p newnode = nodes.reference('', '', internal=True) innernode = nodes.paragraph(text=title) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, mathdocname) newnode['refuri'] += '#' + idss[0] except NoUri: # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(innernode) p += newnode bullets += item mathdef_entry["ids"] = idss env.resolve_references(mathdef_entry, mathdef_info['docname'], app.builder) # Insert into the mathdeflist content.append(mathdef_entry) content.append(para) node.replace_self(content)
def visit_ol(self, node): return nodes.enumerated_list()
def render_ordered_list_open(self, token): list_node = nodes.enumerated_list() self.add_line_and_source_path(list_node, token) with self.current_node_context(list_node, append=True): self.render_children(token)
def process_blocref_nodes_generic(app, doctree, fromdocname, class_name, entry_name, class_node, class_node_list): """ process_blocref_nodes and other kinds of nodes, If the configuration file specifies a variable ``blocref_include_blocrefs`` equals to False, all nodes are removed. """ # logging cont = info_blocref(app, doctree, fromdocname, class_name, entry_name, class_node, class_node_list) if not cont: return # check this is something to process env = app.builder.env attr_name = '%s_all_%ss' % (class_name, class_name) if not hasattr(env, attr_name): setattr(env, attr_name, []) bloc_list_env = getattr(env, attr_name) if len(bloc_list_env) == 0: return # content incconf = '%s_include_%ss' % (class_name, class_name) if app.config[incconf] and not app.config[incconf]: for node in doctree.traverse(class_node): node.parent.remove(node) # Replace all blocreflist nodes with a list of the collected blocrefs. # Augment each blocref with a backlink to the original location. if hasattr(env, "settings") and hasattr(env.settings, "language_code"): lang = env.settings.language_code else: lang = "en" orig_entry = TITLES[lang]["original entry"] brefmes = TITLES[lang][entry_name] for ilist, node in enumerate(doctree.traverse(class_node_list)): if 'ids' in node: node['ids'] = [] if not app.config[incconf]: node.replace_self([]) continue nbbref = 0 content = [] breftag = node["breftag"] brefsort = node["brefsort"] add_contents = node["brefcontents"] brefdocname = node["docname"] if add_contents: bullets = nodes.enumerated_list() content.append(bullets) # sorting if brefsort == 'title': double_list = [(info.get('breftitle', ''), info) for info in bloc_list_env if info['breftag'] == breftag] double_list.sort(key=lambda x: x[:1]) elif brefsort == 'file': double_list = [((info.get('breffile', ''), info.get('brefline', '')), info) for info in bloc_list_env if info['breftag'] == breftag] double_list.sort(key=lambda x: x[:1]) elif brefsort == 'number': double_list = [(info.get('brefmid', ''), info) for info in bloc_list_env if info['breftag'] == breftag] double_list.sort(key=lambda x: x[:1]) else: raise ValueError("sort option should be file, number, title") # printing now = datetime.datetime.now() app.info(" {0} - process tag '{1}' #={2}".format(now, breftag, len(double_list))) for n, blocref_info_ in enumerate(double_list): blocref_info = blocref_info_[1] nbbref += 1 if len(double_list) % 5 == 0: now = datetime.datetime.now() app.info(" {0} - process tag '{1}' node={2}/{3}".format(now, breftag, nbbref, len(double_list))) para = nodes.paragraph(classes=['%s-source' % class_name]) if app.config['%s_link_only' % class_name]: description = _('<<%s>>' % orig_entry) else: description = ( _(brefmes) % (orig_entry, os.path.split(blocref_info['source'])[-1], blocref_info['lineno']) ) desc1 = description[:description.find('<<')] desc2 = description[description.find('>>') + 2:] para += nodes.Text(desc1, desc1) # Create a reference newnode = nodes.reference('', '', internal=True) innernode = nodes.emphasis( _(orig_entry), _(orig_entry)) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, blocref_info['docname']) try: newnode['refuri'] += '#' + blocref_info['target']['refid'] except Exception as e: raise KeyError("refid in not present in '{0}'".format( blocref_info['target'])) from e except NoUri: # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(innernode) para += newnode para += nodes.Text(desc2, desc2) blocref_entry = blocref_info['blocref'] idss = ["index-%s-%d-%d" % (class_name, ilist, n)] # Insert into the blocreflist if add_contents: title = blocref_info['breftitle'] item = nodes.list_item() p = nodes.paragraph() item += p newnode = nodes.reference('', '', internal=True) innernode = nodes.paragraph(text=title) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, brefdocname) newnode['refuri'] += '#' + idss[0] except NoUri: # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(innernode) p += newnode bullets += item blocref_entry["ids"] = idss env.resolve_references(blocref_entry, blocref_info[ 'docname'], app.builder) content.append(blocref_entry) content.append(para) app.info(" {0} - replace - '{1}'".format(now, breftag)) node.replace_self(content) app.info(" {0} - END - '{1}'".format(now, breftag))
def ordered_list(self, items): ordered_list = nodes.enumerated_list() self._build_list(items, ordered_list) self.current_node.append(ordered_list)
def process_mathdef_nodes(app, doctree, fromdocname): """ process_mathdef_nodes """ if not app.config['mathdef_include_mathsext']: for node in doctree.traverse(mathdef_node): node.parent.remove(node) # Replace all mathdeflist nodes with a list of the collected mathsext. # Augment each mathdef with a backlink to the original location. env = app.builder.env if hasattr(env, "settings") and hasattr(env.settings, "language_code"): lang = env.settings.language_code else: lang = "en" orig_entry = TITLES[lang]["original entry"] mathmes = TITLES[lang]["mathmes"] if not hasattr(env, 'mathdef_all_mathsext'): env.mathdef_all_mathsext = [] for ilist, node in enumerate(doctree.traverse(mathdeflist)): if 'ids' in node: node['ids'] = [] if not app.config['mathdef_include_mathsext']: node.replace_self([]) continue nbmath = 0 content = [] mathtag = node["mathtag"] add_contents = node["mathcontents"] mathdocname = node["docname"] if add_contents: bullets = nodes.enumerated_list() content.append(bullets) double_list = [(info.get('mathtitle', ''), info) for info in env.mathdef_all_mathsext] double_list.sort(key=lambda x: x[:1]) for n, mathdef_info_ in enumerate(double_list): mathdef_info = mathdef_info_[1] if mathdef_info["mathtag"] != mathtag: continue nbmath += 1 para = nodes.paragraph(classes=['mathdef-source']) if app.config['mathdef_link_only']: description = _('<<%s>>' % orig_entry) else: description = ( _(mathmes) % (orig_entry, os.path.split(mathdef_info['source'])[-1], mathdef_info['lineno']) ) desc1 = description[:description.find('<<')] desc2 = description[description.find('>>') + 2:] para += nodes.Text(desc1, desc1) # Create a reference newnode = nodes.reference('', '', internal=True) innernode = nodes.emphasis('', _(orig_entry)) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, mathdef_info['docname']) try: newnode['refuri'] += '#' + mathdef_info['target']['refid'] except Exception as e: # pragma: no cover raise KeyError("refid in not present in '{0}'".format( mathdef_info['target'])) from e except NoUri: # pragma: no cover # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(innernode) para += newnode para += nodes.Text(desc2, desc2) # (Recursively) resolve references in the mathdef content mathdef_entry = mathdef_info['mathdef'] idss = ["index-mathdef-%d-%d" % (ilist, n)] # Insert into the mathreflist if add_contents: title = mathdef_info['mathtitle'] item = nodes.list_item() p = nodes.paragraph() item += p newnode = nodes.reference('', '', internal=True) innernode = nodes.paragraph(text=title) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, mathdocname) newnode['refuri'] += '#' + idss[0] except NoUri: # pragma: no cover # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(innernode) p += newnode bullets += item mathdef_entry["ids"] = idss if not hasattr(mathdef_entry, "settings"): mathdef_entry.settings = Values() mathdef_entry.settings.env = env # If an exception happens here, see blog 2017-05-21 from the # documentation. env.resolve_references(mathdef_entry, mathdef_info['docname'], app.builder) # Insert into the mathdeflist content.append(mathdef_entry) content.append(para) node.replace_self(content)
def process_blocref_nodes_generic(app, doctree, fromdocname, class_name, entry_name, class_node, class_node_list): """ process_blocref_nodes and other kinds of nodes, If the configuration file specifies a variable ``blocref_include_blocrefs`` equals to False, all nodes are removed. """ # logging cont = info_blocref(app, doctree, fromdocname, class_name, entry_name, class_node, class_node_list) if not cont: return # check this is something to process env = app.builder.env attr_name = '%s_all_%ss' % (class_name, class_name) if not hasattr(env, attr_name): setattr(env, attr_name, []) bloc_list_env = getattr(env, attr_name) if len(bloc_list_env) == 0: return # content incconf = '%s_include_%ss' % (class_name, class_name) if app.config[incconf] and not app.config[incconf]: for node in doctree.traverse(class_node): node.parent.remove(node) # Replace all blocreflist nodes with a list of the collected blocrefs. # Augment each blocref with a backlink to the original location. if hasattr(env, "settings"): settings = env.settings if hasattr(settings, "language_code"): lang = env.settings.language_code else: lang = "en" else: settings = None lang = "en" orig_entry = TITLES[lang]["original entry"] brefmes = TITLES[lang][entry_name] for ilist, node in enumerate(doctree.traverse(class_node_list)): if 'ids' in node: node['ids'] = [] if not app.config[incconf]: node.replace_self([]) continue nbbref = 0 content = [] breftag = node["breftag"] brefsort = node["brefsort"] add_contents = node["brefcontents"] brefdocname = node["docname"] if add_contents: bullets = nodes.enumerated_list() content.append(bullets) # sorting if brefsort == 'title': double_list = [(info.get('breftitle', ''), info) for info in bloc_list_env if info['breftag'] == breftag] double_list.sort(key=lambda x: x[:1]) elif brefsort == 'file': double_list = [((info.get('breffile', ''), info.get('brefline', '')), info) for info in bloc_list_env if info['breftag'] == breftag] double_list.sort(key=lambda x: x[:1]) elif brefsort == 'number': double_list = [(info.get('brefmid', ''), info) for info in bloc_list_env if info['breftag'] == breftag] double_list.sort(key=lambda x: x[:1]) else: raise ValueError("sort option should be file, number, title") # printing for n, blocref_info_ in enumerate(double_list): blocref_info = blocref_info_[1] nbbref += 1 para = nodes.paragraph(classes=['%s-source' % class_name]) # Create a target? int_ids = [ 'index%s-%s' % (blocref_info['target']['refid'], env.new_serialno(blocref_info['target']['refid'])) ] int_targetnode = nodes.target(blocref_info['breftitle'], '', ids=int_ids) para += int_targetnode # rest of the content if app.config['%s_link_only' % class_name]: description = _('<<%s>>' % orig_entry) else: description = ( _(brefmes) % (orig_entry, os.path.split( blocref_info['source'])[-1], blocref_info['lineno'])) desc1 = description[:description.find('<<')] desc2 = description[description.find('>>') + 2:] para += nodes.Text(desc1, desc1) # Create a reference newnode = nodes.reference('', '', internal=True) newnode['name'] = _(orig_entry) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, blocref_info['docname']) if blocref_info['target'] is None: raise NoUri # pragma: no cover try: newnode['refuri'] += '#' + blocref_info['target']['refid'] except Exception as e: # pragma: no cover raise KeyError("refid in not present in '{0}'".format( blocref_info['target'])) from e except NoUri: # pragma: no cover # ignore if no URI can be determined, e.g. for LaTeX output pass newnode.append(nodes.Text(newnode['name'])) # para is duplicate of the content of the bloc para += newnode para += nodes.Text(desc2, desc2) blocref_entry = blocref_info['blocref'] idss = ["index-%s-%d-%d" % (class_name, ilist, n)] # Inserts into the blocreflist # in the list of links at the beginning of the page. if add_contents: title = blocref_info['breftitle'] item = nodes.list_item() p = nodes.paragraph() item += p newnode = nodes.reference('', title, internal=True) try: newnode['refuri'] = app.builder.get_relative_uri( fromdocname, brefdocname) newnode['refuri'] += '#' + idss[0] except NoUri: # pragma: no cover # ignore if no URI can be determined, e.g. for LaTeX output pass p += newnode bullets += item # Adds the content. blocref_entry["ids"] = idss if not hasattr(blocref_entry, "settings"): blocref_entry.settings = Values() blocref_entry.settings.env = env # If an exception happens here, see blog 2017-05-21 from the # documentation. env.resolve_references(blocref_entry, blocref_info['docname'], app.builder) content.append(blocref_entry) content.append(para) node.replace_self(content)
def create_list_node(self, marker: str) -> Element: return nodes.enumerated_list(start=int(marker[:-1]), enumtype="arabic", suffix=marker[-1])
def parse_sockets(self, sockets): l = nodes.enumerated_list() l += [self.parse_socket(socket) for socket in sockets] return l