Пример #1
0
    def visit_moinpage_table_of_content(self, elem):
        level = int(elem.get(moin_page.outline_level, 6))

        attrib = {html.class_: 'moin-table-of-contents'}
        elem = html.div(attrib=attrib)

        self._special_stack[-1].add_toc(elem, level)
        return elem
Пример #2
0
    def visit_moinpage_table_of_content(self, elem):
        level = int(elem.get(moin_page.outline_level, 6))

        attribs = elem.attrib.copy()
        attribs[html.class_] = "moin-table-of-contents"
        elem = html.div(attrib=attribs)

        self._special_stack[-1].add_toc(elem, level)
        return elem
Пример #3
0
    def visit_moinpage_blockcode(self, elem):
        pre = self.new_copy(html.pre, elem)

        # TODO: Unify somehow
        if elem.get(moin_page.class_) == 'codearea':
            div = html.div(attrib={html.class_: 'codearea'})
            div.append(pre)
            return div

        return pre
Пример #4
0
    def visit_moinpage_blockcode(self, elem):
        pre = self.new_copy(html.pre, elem)

        # TODO: Unify somehow
        if elem.get(moin_page.class_) == 'codearea':
            div = html.div(attrib={html.class_: 'codearea'})
            div.append(pre)
            return div

        return pre
Пример #5
0
    def visit_moinpage_table_of_content(self, elem):
        try:
            level = int(elem.get(moin_page.outline_level))
            del elem.attrib[moin_page.outline_level]
        except TypeError:
            level = 6

        attribs = elem.attrib.copy()
        attribs[html.class_] = 'moin-table-of-contents'
        elem = html.div(attrib=attribs)

        self._special_stack[-1].add_toc(elem, level)
        return elem
Пример #6
0
    def visit_moinpage_table_of_content(self, elem):
        try:
            level = int(elem.get(moin_page.outline_level))
            del elem.attrib[moin_page.outline_level]
        except TypeError:
            level = 6

        attribs = elem.attrib.copy()
        attribs[html.class_] = 'moin-table-of-contents'
        elem = html.div(attrib=attribs)

        self._special_stack[-1].add_toc(elem, level)
        return elem
Пример #7
0
def wrap_object_with_overlay(elem, href):
    """
    Given both an element and either an href or text, wraps an object with the appropriate div,
    and attaches the overlay element.
    """
    txt = u"→"

    href = remove_overlay_prefixes(href)

    child = html.a(attrib={
        html.href: href
    }, children=(txt, ))

    overlay = html.div(attrib={
        html.class_: "object-overlay"
    }, children=(child, ))

    owrapper = html.div(attrib={
        html.class_: "object-overlay-wrapper"
    }, children=(overlay, ))

    return html.div(attrib={
        html.class_: "page-object"
    }, children=(elem, owrapper))
Пример #8
0
 def create_footnotes(self, top):
     """Return footnotes formatted into an ET structure."""
     footnotes_div = html.div({html.class_: "moin-footnotes"})
     for elem in top.footnotes():
         footnotes_div.append(elem)
     return footnotes_div
Пример #9
0
    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)
                maxlevel = max(h[1] for h in headings)
                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
                    # Ignore the last character in the text so permalink icon doesn't show in TOC
                    text = ''.join(elem.itertext())[:-1]
                    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
Пример #10
0
    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 = html.div({html.class_: "moin-footnotes"})
                special.root.append(footnotes_div)
                for elem in special.footnotes():
                    footnotes_div.append(elem)

            for elem, headings in special.tocs():
                headings = list(headings)
                maxlevel = max(h[1] for h in headings)
                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
                    # Ignore the last character in the text so permalink icon doesn't show in TOC
                    text = ''.join(elem.itertext())[:-1]
                    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%s' % id}))
                        last_level += 1
                    if need_item:
                        stack.pop()
                        stack_push(html.li({html.id_: 'li%s' % id}))
                    togglelink = html.a(attrib={
                                         html.href_: "#",
                                         html.onclick_:
                                            "$('#li%s ol').toggle();return false;" % id,
                                         html.class_: 'showhide',
                                     },
                                     children=["[+]", ])
                    elem_a = html.a(attrib={html.href: '#' + id},
                                    children=[text, ])
                    stack_top_append(elem_a)
                    old_toggle = togglelink
        return ret
Пример #11
0
 def create_footnotes(self, top):
     """Return footnotes formatted into an ET structure."""
     footnotes_div = html.div({html.class_: "moin-footnotes"})
     for elem in top.footnotes():
         footnotes_div.append(elem)
     return footnotes_div
Пример #12
0
    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