def anchordef(self, id): """Inserts an invisible element used as a link target. Inserts an empty <span> element with an id attribute, used as an anchor for link references. We use <span></span> rather than <span/> for browser portability. """ # Don't add newlines, \n, as it will break pre and # line-numbered code sections (from line_achordef() method). #return '<a id="%s"></a>' % (id, ) # do not use - this breaks PRE sections for IE return '<span class="anchor" id="%s"></span>' % wikiutil.escape(id, 1)
def _text(self, text): text = wikiutil.escape(text) if self._in_code: text = text.replace(' ', self.hardspace) return text
def _formatAttributes(self, attr=None, allowed_attrs=None, **kw): """ Return HTML attributes formatted as a single string. (INTERNAL USE BY HTML FORMATTER ONLY!) @param attr: dict containing keys and values @param allowed_attrs: A list of allowable attribute names @param kw: other arbitrary attributes expressed as keyword arguments. @rtype: string @return: formated attributes or empty string The attributes and their values can either be given in the 'attr' dictionary, or as extra keyword arguments. They are both merged together. See the function rewrite_attribute_name() for special notes on how to name attributes. Setting a value to None rather than a string (or string coercible) will remove that attribute from the list. If the list of allowed_attrs is provided, then an error is raised if an HTML attribute is encountered that is not in that list (or is not a common attribute which is always allowed or is not in another XML namespace using the double-underscore syntax). """ # Merge the attr dict and kw dict into a single attributes # dictionary (rewriting any attribute names, extracting # namespaces, and merging some values like css classes). attributes = {} # dict of key=(namespace,name): value=attribute_value if attr: for a, v in attr.items(): a_ns, a_name = rewrite_attribute_name(a) extend_attribute_dictionary(attributes, a_ns, a_name, v) if kw: for a, v in kw.items(): a_ns, a_name = rewrite_attribute_name(a) extend_attribute_dictionary(attributes, a_ns, a_name, v) # Add title attribute if missing, but it has an alt. if attributes.has_key(('html', 'alt')) and not attributes.has_key( ('html', 'title')): attributes[('html', 'title')] = attributes[('html', 'alt')] # Check all the HTML attributes to see if they are known and # allowed. Ignore attributes if in non-HTML namespaces. if allowed_attrs: for name in [ key[1] for key in attributes.keys() if key[0] == 'html' ]: if name in _common_attributes or name in allowed_attrs: pass elif name.startswith('on'): pass # Too many event handlers to enumerate, just let them all pass. else: # Unknown or unallowed attribute. err = 'Illegal HTML attribute "%s" passed to formatter' % name raise ValueError(err) # Finally, format them all as a single string. if attributes: # Construct a formatted string containing all attributes # with their values escaped. Any html:* namespace # attributes drop the namespace prefix. We build this by # separating the attributes into three categories: # # * Those without any namespace (should only be xmlns attributes) # * Those in the HTML namespace (we drop the html: prefix for these) # * Those in any other non-HTML namespace, including xml: xmlnslist = [ '%s="%s"' % (k[1], wikiutil.escape(v, 1)) for k, v in attributes.items() if not k[0] ] htmllist = [ '%s="%s"' % (k[1], wikiutil.escape(v, 1)) for k, v in attributes.items() if k[0] == 'html' ] otherlist = [ '%s:%s="%s"' % (k[0], k[1], wikiutil.escape(v, 1)) for k, v in attributes.items() if k[0] and k[0] != 'html' ] # Join all these lists together in a space-separated string. Also # prefix the whole thing with a space too. htmllist.sort() otherlist.sort() all = [''] + xmlnslist + htmllist + otherlist return ' '.join(all) return ''
def escapedText(self, text, **kw): txt = wikiutil.escape(text) if kw: return self._open('span', **kw) + txt + self._close('span') return txt
def _formatAttributes(self, attr=None, allowed_attrs=None, **kw): """ Return HTML attributes formatted as a single string. (INTERNAL USE BY HTML FORMATTER ONLY!) @param attr: dict containing keys and values @param allowed_attrs: A list of allowable attribute names @param kw: other arbitrary attributes expressed as keyword arguments. @rtype: string @return: formated attributes or empty string The attributes and their values can either be given in the 'attr' dictionary, or as extra keyword arguments. They are both merged together. See the function rewrite_attribute_name() for special notes on how to name attributes. Setting a value to None rather than a string (or string coercible) will remove that attribute from the list. If the list of allowed_attrs is provided, then an error is raised if an HTML attribute is encountered that is not in that list (or is not a common attribute which is always allowed or is not in another XML namespace using the double-underscore syntax). """ # Merge the attr dict and kw dict into a single attributes # dictionary (rewriting any attribute names, extracting # namespaces, and merging some values like css classes). attributes = {} # dict of key=(namespace,name): value=attribute_value if attr: for a, v in attr.items(): a_ns, a_name = rewrite_attribute_name(a) extend_attribute_dictionary(attributes, a_ns, a_name, v) if kw: for a, v in kw.items(): a_ns, a_name = rewrite_attribute_name(a) extend_attribute_dictionary(attributes, a_ns, a_name, v) # Add title attribute if missing, but it has an alt. if attributes.has_key(('html', 'alt')) and not attributes.has_key(('html', 'title')): attributes[('html', 'title')] = attributes[('html', 'alt')] # Check all the HTML attributes to see if they are known and # allowed. Ignore attributes if in non-HTML namespaces. if allowed_attrs: for name in [key[1] for key in attributes.keys() if key[0] == 'html']: if name in _common_attributes or name in allowed_attrs: pass elif name.startswith('on'): pass # Too many event handlers to enumerate, just let them all pass. else: # Unknown or unallowed attribute. err = 'Illegal HTML attribute "%s" passed to formatter' % name raise ValueError(err) # Finally, format them all as a single string. if attributes: # Construct a formatted string containing all attributes # with their values escaped. Any html:* namespace # attributes drop the namespace prefix. We build this by # separating the attributes into three categories: # # * Those without any namespace (should only be xmlns attributes) # * Those in the HTML namespace (we drop the html: prefix for these) # * Those in any other non-HTML namespace, including xml: xmlnslist = ['%s="%s"' % (k[1], wikiutil.escape(v, 1)) for k, v in attributes.items() if not k[0]] htmllist = ['%s="%s"' % (k[1], wikiutil.escape(v, 1)) for k, v in attributes.items() if k[0] == 'html'] otherlist = ['%s:%s="%s"' % (k[0], k[1], wikiutil.escape(v, 1)) for k, v in attributes.items() if k[0] and k[0] != 'html'] # Join all these lists together in a space-separated string. Also # prefix the whole thing with a space too. htmllist.sort() otherlist.sort() all = [''] + xmlnslist + htmllist + otherlist return ' '.join(all) return ''