Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.formatter.text_html Namespace Reference

Classes

class  Formatter

Functions

def rewrite_attribute_name
def extend_attribute_dictionary

Variables

tuple logging = log.getLogger(__name__)
 _id_debug = False
 line_anchors = True
 prettyprint = False
tuple _blocks
tuple _self_closing_tags
tuple _auto_closing_tags = set(['p'])
tuple _indenting_tags = set(['ol', 'ul', 'dl', 'li', 'dt', 'dd', 'tr', 'td'])
tuple _space_eating_tags
tuple _html_attribute_boolflags
tuple _common_attributes

Function Documentation

def MoinMoin.formatter.text_html.extend_attribute_dictionary (   attributedict,
  ns,
  name,
  value 
)
Add a new attribute to an attribute dictionary, merging values where possible.

The attributedict must be a dictionary with tuple-keys of the form:
(namespace, attrname).

The given ns, name, and value will be added to the dictionary.  It
will replace the old value if it existed, except for a few special
cases where the values are logically merged instead (CSS class
names and style rules).

As a special case, if value is None (not just ''), then the
attribute is actually deleted from the dictionary.

Definition at line 140 of file text_html.py.

00140 
00141 def extend_attribute_dictionary(attributedict, ns, name, value):
00142     """Add a new attribute to an attribute dictionary, merging values where possible.
00143 
00144     The attributedict must be a dictionary with tuple-keys of the form:
00145     (namespace, attrname).
00146 
00147     The given ns, name, and value will be added to the dictionary.  It
00148     will replace the old value if it existed, except for a few special
00149     cases where the values are logically merged instead (CSS class
00150     names and style rules).
00151 
00152     As a special case, if value is None (not just ''), then the
00153     attribute is actually deleted from the dictionary.
00154     """
00155 
00156     key = ns, name
00157     if value is None:
00158         if key in attributedict:
00159             del attributedict[key]
00160     else:
00161         if ns == 'html' and key in attributedict:
00162             if name == 'class':
00163                 # CSS classes are appended by space-separated list
00164                 value = attributedict[key] + ' ' + value
00165             elif name == 'style':
00166                 # CSS styles are appended by semicolon-separated rules list
00167                 value = attributedict[key] + '; ' + value
00168             elif name in _html_attribute_boolflags:
00169                 # All attributes must have a value. According to XHTML those
00170                 # traditionally used as flags should have their value set to
00171                 # the same as the attribute name.
00172                 value = name
00173         attributedict[key] = value
00174 

Here is the caller graph for this function:

def MoinMoin.formatter.text_html.rewrite_attribute_name (   name,
  default_namespace = 'html' 
)
Takes an attribute name and tries to make it HTML correct.

This function takes an attribute name as a string, as it may be
passed in to a formatting method using a keyword-argument syntax,
and tries to convert it into a real attribute name.  This is
necessary because some attributes may conflict with Python
reserved words or variable syntax (such as 'for', 'class', or
'z-index'); and also to help with backwards compatibility with
older versions of MoinMoin where different names may have been
used (such as 'content_id' or 'css').

Returns a tuple of strings: (namespace, attribute).

Namespaces: The default namespace is always assumed to be 'html',
unless the input string contains a colon or a double-underscore;
in which case the first such occurance is assumed to separate the
namespace prefix from name.  So, for example, to get the HTML
attribute 'for' (as on a <label> element), you can pass in the
string 'html__for' or even '__for'.

Hyphens:  To better support hyphens (which are not allowed in Python
variable names), all occurances of two underscores will be replaced
with a hyphen.  If you use this, then you must also provide a
namespace since the first occurance of '__' separates a namespace
from the name.

Special cases: Within the 'html' namespace, mainly to preserve
backwards compatibility, these exceptions ars recognized:
'content_type', 'content_id', 'css_class', and 'css'.
Additionally all html attributes starting with 'on' are forced to
lower-case.  Also the string 'xmlns' is recognized as having
no namespace.

Examples:
    'id' -> ('html', 'id')
    'css_class' -> ('html', 'class')
    'content_id' -> ('html', 'id')
    'content_type' -> ('html', 'type')
    'html__for' -> ('html', 'for)
    'xml__space' -> ('xml', 'space')
    '__z__index' -> ('html', 'z-index')
    '__http__equiv' -> ('html', 'http-equiv')
    'onChange' -> ('html', 'onchange')
    'xmlns' -> ('', 'xmlns')
    'xmlns__abc' -> ('xmlns', 'abc')

(In actuality we only deal with namespace prefixes, not any real
namespace URI...we only care about the syntax not the meanings.)

Definition at line 64 of file text_html.py.

00064 
00065 def rewrite_attribute_name(name, default_namespace='html'):
00066     """
00067     Takes an attribute name and tries to make it HTML correct.
00068 
00069     This function takes an attribute name as a string, as it may be
00070     passed in to a formatting method using a keyword-argument syntax,
00071     and tries to convert it into a real attribute name.  This is
00072     necessary because some attributes may conflict with Python
00073     reserved words or variable syntax (such as 'for', 'class', or
00074     'z-index'); and also to help with backwards compatibility with
00075     older versions of MoinMoin where different names may have been
00076     used (such as 'content_id' or 'css').
00077 
00078     Returns a tuple of strings: (namespace, attribute).
00079 
00080     Namespaces: The default namespace is always assumed to be 'html',
00081     unless the input string contains a colon or a double-underscore;
00082     in which case the first such occurance is assumed to separate the
00083     namespace prefix from name.  So, for example, to get the HTML
00084     attribute 'for' (as on a <label> element), you can pass in the
00085     string 'html__for' or even '__for'.
00086 
00087     Hyphens:  To better support hyphens (which are not allowed in Python
00088     variable names), all occurances of two underscores will be replaced
00089     with a hyphen.  If you use this, then you must also provide a
00090     namespace since the first occurance of '__' separates a namespace
00091     from the name.
00092 
00093     Special cases: Within the 'html' namespace, mainly to preserve
00094     backwards compatibility, these exceptions ars recognized:
00095     'content_type', 'content_id', 'css_class', and 'css'.
00096     Additionally all html attributes starting with 'on' are forced to
00097     lower-case.  Also the string 'xmlns' is recognized as having
00098     no namespace.
00099 
00100     Examples:
00101         'id' -> ('html', 'id')
00102         'css_class' -> ('html', 'class')
00103         'content_id' -> ('html', 'id')
00104         'content_type' -> ('html', 'type')
00105         'html__for' -> ('html', 'for)
00106         'xml__space' -> ('xml', 'space')
00107         '__z__index' -> ('html', 'z-index')
00108         '__http__equiv' -> ('html', 'http-equiv')
00109         'onChange' -> ('html', 'onchange')
00110         'xmlns' -> ('', 'xmlns')
00111         'xmlns__abc' -> ('xmlns', 'abc')
00112 
00113     (In actuality we only deal with namespace prefixes, not any real
00114     namespace URI...we only care about the syntax not the meanings.)
00115     """
00116 
00117     # Handle any namespaces (just in case someday we support XHTML)
00118     if ':' in name:
00119         ns, name = name.split(':', 1)
00120     elif '__' in name:
00121         ns, name = name.split('__', 1)
00122     elif name == 'xmlns':
00123         ns = ''
00124     else:
00125         ns = default_namespace
00126 
00127     name.replace('__', '-')
00128     if ns == 'html':
00129         # We have an HTML attribute, fix according to DTD
00130         if name == 'content_type': # MIME type such as in <a> and <link> elements
00131             name = 'type'
00132         elif name == 'content_id': # moin historical convention
00133             name = 'id'
00134         elif name in ('css_class', 'css'): # to avoid python word 'class'
00135             name = 'class'
00136         elif name.startswith('on'): # event handler hook
00137             name = name.lower()
00138     return ns, name
00139 

Here is the caller graph for this function:


Variable Documentation

Definition at line 41 of file text_html.py.

Initial value:
00001 set(['dd', 'div', 'dl', 'dt', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
00002                'hr', 'li', 'ol', 'p', 'pre', 'table', 'tbody', 'td', 'tfoot', 'th',
00003                'thead', 'tr', 'ul', 'blockquote', ])

Definition at line 27 of file text_html.py.

Initial value:
00001 set(['accesskey', 'class', 'dir', 'disabled', 'id', 'lang',
00002                           'style', 'tabindex', 'title'])

Definition at line 60 of file text_html.py.

Initial value:
00001 set(['compact', 'disabled', 'ismap', 'nohref',
00002                                  'noresize', 'noshade', 'nowrap', 'readonly',
00003                                  'selected', 'wrap'])

Definition at line 55 of file text_html.py.

Definition at line 21 of file text_html.py.

tuple MoinMoin.formatter.text_html._indenting_tags = set(['ol', 'ul', 'dl', 'li', 'dt', 'dd', 'tr', 'td'])

Definition at line 45 of file text_html.py.

Initial value:
00001 set(['area', 'base', 'br', 'col', 'frame', 'hr', 'img',
00002                           'input', 'isindex', 'link', 'meta', 'param'])

Definition at line 37 of file text_html.py.

Initial value:
00001 set(['colgroup', 'dl', 'frameset', 'head', 'map' 'menu',
00002                           'ol', 'optgroup', 'select', 'table', 'tbody', 'tfoot',
00003                           'thead', 'tr', 'ul'])

Definition at line 49 of file text_html.py.

Definition at line 23 of file text_html.py.

Definition at line 11 of file text_html.py.

Definition at line 24 of file text_html.py.