lxml.html.defs

Package lxml :: Package html :: Module defs |
[hide private]
[frames] | no frames]

# Source Code for Module lxml.html.defs

      1  # FIXME: this should all be confirmed against what a DTD says
      2  # (probably in a test; this may not match the DTD exactly, but we
      3  # should document just how it differs).
      4
      5  # Data taken from http://www.w3.org/TR/html401/index/elements.html
      6
      7  try:
      8      frozenset
      9  except NameError:
     10      from sets import Set as frozenset
     11
     12
     13  empty_tags = frozenset([
     14      'area', 'base', 'basefont', 'br', 'col', 'frame', 'hr',
     15      'img', 'input', 'isindex', 'link', 'meta', 'param'])
     16
     17  deprecated_tags = frozenset([
     18      'applet', 'basefont', 'center', 'dir', 'font', 'isindex',
     19      'menu', 's', 'strike', 'u'])
     20
     21  # archive actually takes a space-separated list of URIs
     22  link_attrs = frozenset([
     23      'action', 'archive', 'background', 'cite', 'classid',
     24      'codebase', 'data', 'href', 'longdesc', 'profile', 'src',
     25      'usemap',
     26      # Not standard:
     27      'dynsrc', 'lowsrc',
     28      ])
     29
     30  # Not in the HTML 4 spec:
     31  # onerror, onresize
     32  event_attrs = frozenset([
     33      'onblur', 'onchange', 'onclick', 'ondblclick', 'onerror',
     34      'onfocus', 'onkeydown', 'onkeypress', 'onkeyup', 'onload',
     35      'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
     36      'onmouseup', 'onreset', 'onresize', 'onselect', 'onsubmit',
     37      'onunload',
     38      ])
     39
     40  safe_attrs = frozenset([
     41      'abbr', 'accept', 'accept-charset', 'accesskey', 'action', 'align',
     42      'alt', 'axis', 'border', 'cellpadding', 'cellspacing', 'char', 'charoff',
     43      'charset', 'checked', 'cite', 'class', 'clear', 'cols', 'colspan',
     44      'color', 'compact', 'coords', 'datetime', 'dir', 'disabled', 'enctype',
     45      'for', 'frame', 'headers', 'height', 'href', 'hreflang', 'hspace', 'id',
     46      'ismap', 'label', 'lang', 'longdesc', 'maxlength', 'media', 'method',
     47      'multiple', 'name', 'nohref', 'noshade', 'nowrap', 'prompt', 'readonly',
     48      'rel', 'rev', 'rows', 'rowspan', 'rules', 'scope', 'selected', 'shape',
     49      'size', 'span', 'src', 'start', 'summary', 'tabindex', 'target', 'title',
     50      'type', 'usemap', 'valign', 'value', 'vspace', 'width'])
     51
     52  # From http://htmlhelp.com/reference/html40/olist.html
     53  top_level_tags = frozenset([
     54      'html', 'head', 'body', 'frameset',
     55      ])
     56
     57  head_tags = frozenset([
     58      'base', 'isindex', 'link', 'meta', 'script', 'style', 'title',
     59      ])
     60
     61  general_block_tags = frozenset([
     62      'address',
     63      'blockquote',
     64      'center',
     65      'del',
     66      'div',
     67      'h1',
     68      'h2',
     69      'h3',
     70      'h4',
     71      'h5',
     72      'h6',
     73      'hr',
     74      'ins',
     75      'isindex',
     76      'noscript',
     77      'p',
     78      'pre',
     79      ])
     80
     81  list_tags = frozenset([
     82      'dir', 'dl', 'dt', 'dd', 'li', 'menu', 'ol', 'ul',
     83      ])
     84
     85  table_tags = frozenset([
     86      'table', 'caption', 'colgroup', 'col',
     87      'thead', 'tfoot', 'tbody', 'tr', 'td', 'th',
     88      ])
     89
     90  # just this one from
     91  # http://www.georgehernandez.com/h/XComputers/HTML/2BlockLevel.htm
     92  block_tags = general_block_tags | list_tags | table_tags | frozenset([
     93      # Partial form tags
     94      'fieldset', 'form', 'legend', 'optgroup', 'option',
     95      ])
     96
     97  form_tags = frozenset([
     98      'form', 'button', 'fieldset', 'legend', 'input', 'label',
     99      'select', 'optgroup', 'option', 'textarea',
    100      ])
    101
    102  special_inline_tags = frozenset([
    103      'a', 'applet', 'basefont', 'bdo', 'br', 'embed', 'font', 'iframe',
    104      'img', 'map', 'area', 'object', 'param', 'q', 'script',
    105      'span', 'sub', 'sup',
    106      ])
    107
    108  phrase_tags = frozenset([
    109      'abbr', 'acronym', 'cite', 'code', 'del', 'dfn', 'em',
    110      'ins', 'kbd', 'samp', 'strong', 'var',
    111      ])
    112
    113  font_style_tags = frozenset([
    114      'b', 'big', 'i', 's', 'small', 'strike', 'tt', 'u',
    115      ])
    116
    117  frame_tags = frozenset([
    118      'frameset', 'frame', 'noframes',
    119      ])
    120
    121  # These tags aren't standard
    122  nonstandard_tags = frozenset(['blink', 'marque'])
    123
    124  tags = (top_level_tags | head_tags | general_block_tags | list_tags
    125          | table_tags | form_tags | special_inline_tags | phrase_tags
    126          | font_style_tags | nonstandard_tags)
    127