Exemple #1
0
    def visit_moinpage_object(self, elem):
        href = elem.get(xlink.href, None)
        attrib = {}
        mimetype = Type(_type=elem.get(moin_page.type_, 'application/x-nonexistent'))
        # Get the object type
        obj_type = self.eval_object_type(mimetype, href)

        # The attribute source attribute for img,video, and audio is the same (src)
        # <object>'s attribute is 'data'
        attr = html.src if obj_type != "object" else html.data

        # The return element
        new_elem = None

        if href is not None:
            # Set the attribute of the returned element appropriately
            attrib[attr] = href

        if obj_type == "img":
            # Images have alt text
            alt = ''.join(str(e) for e in elem) # XXX handle non-text e
            if alt:
                attrib[html.alt] = alt
            new_elem = html.img(attrib=attrib)

        else:
            if obj_type != "object":
                # Non-objects have the "controls" attribute
                attrib[html.controls] = 'controls'
            new_elem = self.new_copy(getattr(html, obj_type), elem, attrib)

        return mark_item_as_transclusion(new_elem, href)
Exemple #2
0
 def macro(self, content, arguments, page_url, alternative):
     icon = arguments[0] if arguments else ''
     if not icon:
         raise ValueError("Missing icon name")
     src = url_for('static', filename='img/icons/' + icon)
     reason = _('Icon not rendered, verify name is valid')
     alt = '<<Icon({0})>> - {1}'.format(icon, reason)
     return html.img(attrib={html.src: src, html.alt: alt, html.class_: 'moin-icon-macro'})
    def visit_moinpage_object(self, elem):
        """
        elem of type img are converted to img tags here, others are left as object tags
        """
        href = elem.get(xlink.href, None)
        attrib = {}
        whitelist = ['width', 'height', 'alt', 'class', 'data-href']
        for key in elem.attrib:
            if key.name in whitelist:
                attrib[key] = elem.attrib[key]
        mimetype = Type(_type=elem.get(moin_page.type_, CONTENTTYPE_NONEXISTENT))
        if elem.get(moin_page.type_):
            del elem.attrib[moin_page.type_]
        # Get the object type
        obj_type = self.eval_object_type(mimetype, href)

        # The attribute source attribute for img,video, and audio is the same (src)
        # <object>'s attribute is 'data'
        attr = html.src if obj_type != "object" else html.data

        # The return element
        new_elem = None

        if href is not None:
            # Set the attribute of the returned element appropriately
            attrib[attr] = href
        alt = convert_getlink_to_showlink(unicode(href))
        alt = re.sub('^\/', '', alt)

        if obj_type == "img":
            # Images must have alt attribute in html5, but if user did not specify then default to url
            if not attrib.get(html.alt):
                attrib[html.alt] = alt
            new_elem = html.img(attrib=attrib)

        else:
            if obj_type != "object":
                # Non-objects like video and audio have the "controls" attribute
                attrib[html.controls] = 'controls'
                new_elem = self.new_copy(getattr(html, obj_type), elem, attrib)
            else:
                # is an object
                new_elem = html.object(attrib=attrib)
            # alt attr is invalid within object, audio, and video tags , append alt text as a child
            if new_elem.attrib.get(html.alt):
                new_elem.append(new_elem.attrib.get(html.alt))
                del new_elem.attrib[html.alt]
            else:
                new_elem.append(alt)

        if obj_type == "object" and getattr(href, 'scheme', None):
            # items similar to {{http://moinmo.in}} are marked here, other objects are marked in include.py
            return mark_item_as_transclusion(new_elem, href)
        return new_elem
Exemple #4
0
    def visit_moinpage_object(self, elem):
        """
        elem of type img are converted to img tags here, others are left as object tags
        """
        href = elem.get(xlink.href, None)
        attrib = {}
        whitelist = ['width', 'height', 'alt', 'class', 'data-href']
        for key in elem.attrib:
            if key.name in whitelist:
                attrib[key] = elem.attrib[key]
        mimetype = Type(_type=elem.get(moin_page.type_, CONTENTTYPE_NONEXISTENT))
        if elem.get(moin_page.type_):
            del elem.attrib[moin_page.type_]
        # Get the object type
        obj_type = self.eval_object_type(mimetype, href)

        # The attribute source attribute for img,video, and audio is the same (src)
        # <object>'s attribute is 'data'
        attr = html.src if obj_type != "object" else html.data

        # The return element
        new_elem = None

        if href is not None:
            # Set the attribute of the returned element appropriately
            attrib[attr] = href
        alt = convert_getlink_to_showlink(unicode(href))
        alt = re.sub('^\/', '', alt)

        if obj_type == "img":
            # Images must have alt attribute in html5, but if user did not specify then default to url
            if not attrib.get(html.alt):
                attrib[html.alt] = alt
            new_elem = html.img(attrib=attrib)

        else:
            if obj_type != "object":
                # Non-objects like video and audio have the "controls" attribute
                attrib[html.controls] = 'controls'
                new_elem = self.new_copy(getattr(html, obj_type), elem, attrib)
            else:
                # is an object
                new_elem = html.object(attrib=attrib)
            # alt attr is invalid within object, audio, and video tags , append alt text as a child
            if new_elem.attrib.get(html.alt):
                new_elem.append(new_elem.attrib.get(html.alt))
                del new_elem.attrib[html.alt]
            else:
                new_elem.append(alt)

        if obj_type == "object" and getattr(href, 'scheme', None):
            # items similar to {{http://moinmo.in}} are marked here, other objects are marked in include.py
            return mark_item_as_transclusion(new_elem, href)
        return new_elem
Exemple #5
0
    def macro(self, content, arguments, page_url, alternative):
        my_dir = os.path.abspath(os.path.dirname(__file__))
        icon_dir = os.path.join(
            os.path.split(my_dir)[0], 'static', 'img', 'icons')

        headings = (_('Markup'), _('Result'))
        files = [f for f in listdir(icon_dir) if isfile(join(icon_dir, f))]
        rows = []
        for filename in files:
            markup = '<<Icon({0})>>'.format(filename)
            src = url_for('static', filename='img/icons/' + filename)
            reason = _('Icon not rendered, verify name is valid')
            alt = '<<Icon({0})>> - {1}'.format(filename, reason)
            rows.append(
                (markup, html.img(attrib={
                    html.src: src,
                    html.alt: filename
                })))
        table = TableMixin()
        ret = table.build_dom_table(rows, head=headings)
        return ret
Exemple #6
0
    def visit_moinpage_object(self, elem):
        # TODO: maybe IE8 would display transcluded external pages if we could do <object... type="text/html" ...>
        href = elem.get(xlink.href, None)
        attrib = {}
        mimetype = Type(_type=elem.get(moin_page.type_, CONTENTTYPE_NONEXISTENT))
        # Get the object type
        obj_type = self.eval_object_type(mimetype, href)

        # The attribute source attribute for img,video, and audio is the same (src)
        # <object>'s attribute is 'data'
        attr = html.src if obj_type != "object" else html.data

        # The return element
        new_elem = None

        if href is not None:
            # Set the attribute of the returned element appropriately
            attrib[attr] = href

        if obj_type == "img":
            # Images have alt text
            alt = "".join(unicode(e) for e in elem)  # XXX handle non-text e
            if alt:
                attrib[html.alt] = alt
            new_elem = html.img(attrib=attrib)

        else:
            if obj_type != "object":
                # Non-objects have the "controls" attribute
                attrib[html.controls] = "controls"
            new_elem = self.new_copy(getattr(html, obj_type), elem, attrib)

        if obj_type == "object" and href.scheme:
            # items similar to {{http://moinmo.in}} are marked here, other objects are marked in include.py
            return mark_item_as_transclusion(new_elem, href)
        return new_elem