def body(self): """The BODY of the html document""" reports = E.OL(id='reports') code = self.code() for i, (state_html, state_problem) in enumerate(self.states(), 1): reports.append( E.LI( E.ATTR(id="state{0}".format(i)), E.E.header( E.DIV( E.CLASS('error'), state_problem, ), E.DIV( E.CLASS('report-count'), E.H3('Report'), str(i), ), ), E.DIV( E.CLASS('body'), E.DIV( E.CLASS('source'), deepcopy(code), ), state_html, ), ), ) return E.BODY( self.header(), reports, self.footer(), )
def tocify(_toc, curr): section = E.OL() i = 0 for level, text, id in _toc: i += 1 if level == top_heading_level: continue if level < curr: return section if level == curr: section.append( E.LI(E.A(text, href="#" + id), tocify(_toc[i:], curr + 1))) return section
def states(self): """Return an ordered-list of states, for each report.""" for report in self.data['reports']: annotations = E.OL({'class': 'states'}) prevline = None lineno_to_index = {} index = -1 for state in report['states']: if not state['location'] or not state['message']: continue line = state['location'][0]['line'] state = E.P(state['message']) # We try to combine with the previous state. if line != prevline: child = E.LI({'data-line': str(line)}) annotations.append(child) index += 1 child.append(state) lineno_to_index[line] = (index, child) prevline = line for note in report['notes']: line = note['location'][0]['line'] note = E.P({'class': 'note'}, note['message']) # Put this note on the last matching state, if possible for ann in reversed(tuple(annotations)): annline = int(ann.attrib['data-line']) if line == annline: ann.append(note) break elif line > annline: ann.addnext( E.LI({'data-line': str(line)}, note) ) break else: annotations.insert(0, E.LI({'data-line': str(line)}, note)) yield annotations, report['message']
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)