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
def visit_moinpage_object(self, elem): """ elem of type img are converted to img tags here, others are left as object tags. We do not use Attributes.convert to convert all attributes, but copy selected attributes and follow html5 rules to place right attributes within img and object tags. """ href = elem.get(xlink.href, None) attrib = {} whitelist = [ 'width', 'height', 'alt', 'class', 'data-href', 'style', 'title' ] for key in elem.attrib: if key.name in whitelist: if key.name == 'style': attrib[key] = style_attr_filter(elem.attrib[key]) else: 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(str(href)) alt = re.sub(r'^/', '', 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