def add_heading(self, elem, level, id=None): elem.append(html.a(attrib={ html.href: "#{0}".format(id), html.class_: "moin-permalink", html.title_: _("Link to this heading") })) self._headings.append((elem, level, id))
def __call__(self, element): special_root = SpecialPage() self._special = [special_root] self._special_stack = [special_root] self._id = SpecialId() ret = super(ConverterPage, self).__call__(element) special_root.root = ret for special in self._special: if special._footnotes: footnotes_div = self.create_footnotes(special) special.root.append(footnotes_div) for elem, headings in special.tocs(): headings = list(headings) headings_list = [h[1] for h in headings] if headings_list: maxlevel = max(headings_list) headtogglelink = html.a(attrib={ html.class_: 'moin-showhide', html.href_: '#', html.onclick_: "$('.moin-table-of-contents ol').toggle();return false;", }, children=[ '[+]', ]) elem_h = html.div( attrib={html.class_: 'moin-table-of-contents-heading'}, children=[_('Contents'), headtogglelink]) elem.append(elem_h) stack = [elem] def stack_push(elem): stack[-1].append(elem) stack.append(elem) def stack_top_append(elem): stack[-1].append(elem) last_level = 0 old_toggle = "" for elem, level, id in headings: need_item = last_level >= level text = ''.join(elem.itertext()) while last_level > level: stack.pop() stack.pop() last_level -= 1 while last_level < level: if maxlevel != 1: stack_top_append(old_toggle) stack_push(html.ol()) stack_push(html.li({html.id_: 'li{0}'.format(id)})) last_level += 1 if need_item: stack.pop() stack_push(html.li({html.id_: 'li{0}'.format(id)})) togglelink = html.a(attrib={ html.href_: "#", html.onclick_: "$('#li{0} ol').toggle();return false;".format(id), html.class_: 'moin-showhide', }, children=[ "[+]", ]) elem_a = html.a(attrib={html.href: '#' + id}, children=[ text, ]) stack_top_append(elem_a) old_toggle = togglelink return ret