Beispiel #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()
Beispiel #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[:]))
Beispiel #3
0
    def macro(self, content, arguments, page_url, alternative):
        args = arguments[0] if arguments else ""
        if not args:
            raise ValueError("Missing font name")

        args = args.split(',')
        fonts = args[0].split()

        color = args[1].strip() if len(args) > 1 else ""
        size = args[2].strip() if len(args) > 2 else ""

        if color.startswith('#'):
            try:
                int(color[1:], 16)
                assert len(color) in (4, 7)
                color = 'color: {0}; '.format(color)
            except (ValueError, AssertionError):
                color = ""

        if size:
            try:
                s = float(size)
                assert s > 0.1
                assert s < 99
                size = 'font-size: {0}em;'.format(size)
            except (ValueError, AssertionError):
                size = ""

        style = color + size

        classes = []
        for font in fonts:
            f = font if font.startswith(
                'fa-') or font == 'fa' else 'fa-' + font
            classes.append(f)
        if 'fa' not in classes:
            classes.insert(0, 'fa')
        classes = ' '.join(classes)

        attrib = {html.class_: classes}
        if style:
            attrib[html.style] = style
        return html.span(attrib={html.class_: classes, html.style: style})