Exemple #1
0
    def visit_moinpage_inline_part(self, elem):
        body = error = None

        for item in elem:
            if item.tag.uri == moin_page:
                if item.tag.name == 'inline-body':
                    body = item
                elif item.tag.name == 'error':
                    error = item

        if body:
            return self.new_copy(html.span, item)

        if error:
            if len(error):
                ret = html.span(children=error)
            else:
                ret = html.span(children=('Error', ))
            ret.set(html.class_, 'moin-error')
            return ret

        # XXX: Move handling of namespace-less attributes into emeraldtree
        alt = elem.get(moin_page.alt, elem.get('alt'))
        if alt:
            return html.span(children=(alt, ))

        return html.span()
Exemple #2
0
    def visit_moinpage_page(self, elem):
        for item in elem:
            if item.tag.uri == moin_page and item.tag.name == 'body':
                # if this is a transcluded page, we must pass the class and data-href attribs
                attribs = elem.attrib.copy()
                if moin_page.page_href in attribs:
                    del attribs[moin_page.page_href]
                if attribs and len(item) == 1:

                    if item[0].tag.name in ('object', 'a'):
                        # png, jpg, gif are objects here, will be changed to img when they are processed
                        # transclusion is a single inline element "My pet {{bird.jpg}} flys." or
                        # "[[SomePage|{{Logo.png}}]]"
                        return self.new_copy(html.span, item, attribs)

                    elif item[0].tag.name == 'p':
                        # transclusion is a single p-tag that can be coerced to inline  "Yes, we have {{no}} bananas."
                        new_span = html.span(children=item[0][:])
                        return self.new_copy(html.span, new_span, attribs)

                # transclusion is a block element
                return self.new_copy(html.div, item, attribs)

        raise RuntimeError(
            'page:page need to contain exactly one page:body tag, got {0!r}'.
            format(elem[:]))