def parse(self, block): """""" list = E.DL() for inner_block in re.split(r"(?m)\n \n(?=\w)", block): term_block, _, definition_block = inner_block.partition("\n: ") for term in term_block.splitlines(): list.append(E.DT(term)) for def_block in definition_block.split("\n: "): definition = E.DD() self.parser.process_blocks(definition, clean_indent(def_block)) list.append(definition) return list
def write_list(self, list, parent, level=0): # grab the anchors that exist if self.indexmode: t_count = 0 for t in list.findall('t'): t_count += 1 anchor = t.attrib.get('anchor') if anchor: self._indexListParagraph(t_count, anchor) # style comes from the node if one exists style = list.attrib.get('style', '') if not style: # otherwise look for the nearest list parent with a style and use it for elder in list.iterancestors(): if elder.tag == 'list': style = elder.attrib.get('style', '') if style: break if not style: style = 'empty' if style == 'hanging': list_elem = E.DL() hangIndent = list.attrib.get('hangIndent', '8') style = 'margin-left: ' + hangIndent for t in list.findall('t'): hangText = t.attrib.get('hangText', '') dt = E.DT(hangText) dd = E.DD(style=style) list_elem.append(dt) list_elem.append(dd) self.write_t_rec(t, parent=dd, level=level +1) elif style.startswith('format'): format_str = style.partition('format ')[2] allowed_formats = ('%c', '%C', '%d', '%i', '%I', '%o', '%x', '%X') if not any([ f in format_str for f in allowed_formats]): xml2rfc.log.warn('Invalid format specified: %s ' '(Must be one of %s)' % (style, ', '.join(allowed_formats))) counter_index = list.attrib.get('counter', None) if not counter_index: counter_index = 'temp' + str(level) self.list_counters[counter_index] = 0 elif counter_index not in self.list_counters: # Initialize if we need to self.list_counters[counter_index] = 0 list_elem = E.DL() for t in list.findall('t'): self.list_counters[counter_index] += 1 count = self.list_counters[counter_index] bullet = self._format_counter(format_str, count) + ' ' dt = E.DT(bullet) dd = E.DD() list_elem.append(dt) list_elem.append(dd) self.write_t_rec(t, parent=dd, level=level + 1) else: if style == 'symbols': list_elem = E.UL() elif style == 'numbers': list_elem = E.OL() elif style == 'letters': letter_style = "list-style-type: upper-alpha" if (level % 2) else "list-style-type: lower-alpha" list_elem = E.OL(style= letter_style) else: # style == empty list_elem = E.UL() list_elem.attrib['class'] = 'empty' for t in list.findall('t'): li = E.LI() list_elem.append(li) self.write_t_rec(t, parent=li, level= level + 1) parent.append(list_elem)
def visit_Enum(self, node): """Return a list of DT/DD elements for the enum DL.""" return ([E.DT(node.name, E.SPAN(str(node.value), CLASS('address')))] + [E.DD(d) for d in node.description])