Package lxml :: Module htmlbuilder
[hide private]
[frames] | no frames]

Source Code for Module lxml.htmlbuilder

  1  # 
  2  # HTML specialisation of ``builder.py`` by Fredrik Lundh 
  3  # 
  4  # -------------------------------------------------------------------- 
  5  # The ElementTree toolkit is 
  6  # 
  7  # Copyright (c) 1999-2004 by Fredrik Lundh 
  8  # 
  9  # By obtaining, using, and/or copying this software and/or its 
 10  # associated documentation, you agree that you have read, understood, 
 11  # and will comply with the following terms and conditions: 
 12  # 
 13  # Permission to use, copy, modify, and distribute this software and 
 14  # its associated documentation for any purpose and without fee is 
 15  # hereby granted, provided that the above copyright notice appears in 
 16  # all copies, and that both that copyright notice and this permission 
 17  # notice appear in supporting documentation, and that the name of 
 18  # Secret Labs AB or the author not be used in advertising or publicity 
 19  # pertaining to distribution of the software without specific, written 
 20  # prior permission. 
 21  # 
 22  # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD 
 23  # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- 
 24  # ABILITY AND FITNESS.  IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR 
 25  # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
 26  # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
 27  # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 
 28  # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
 29  # OF THIS SOFTWARE. 
 30  # -------------------------------------------------------------------- 
 31   
 32  """ 
 33  Usage:: 
 34   
 35      >>> from lxml.htmlbuilder import * 
 36      >>> html = HTML( 
 37      ...            HEAD( TITLE("Hello World") ), 
 38      ...            BODY( CLASS("main"), 
 39      ...                  H1("Hello World !") 
 40      ...            ) 
 41      ...        ) 
 42   
 43      >>> import lxml.etree 
 44      >>> print lxml.etree.tostring(html, pretty_print=True) 
 45      <html> 
 46        <head> 
 47          <title>Hello World</title> 
 48        </head> 
 49        <body class="main"> 
 50          <h1>Hello World !</h1> 
 51        </body> 
 52      </html> 
 53   
 54  """ 
 55   
 56  from builder import E 
 57   
 58  # elements 
 59  A = E.a # anchor 
 60  ABBR = E.abbr # abbreviated form (e.g., WWW, HTTP, etc.) 
 61  ACRONYM = E.acronym #  
 62  ADDRESS = E.address # information on author 
 63  APPLET = E.applet # Java applet (DEPRECATED) 
 64  AREA = E.area # client-side image map area 
 65  B = E.b # bold text style 
 66  BASE = E.base # document base URI 
 67  BASEFONT = E.basefont # base font size (DEPRECATED) 
 68  BDO = E.bdo # I18N BiDi over-ride 
 69  BIG = E.big # large text style 
 70  BLOCKQUOTE = E.blockquote # long quotation 
 71  BODY = E.body # document body 
 72  BR = E.br # forced line break 
 73  BUTTON = E.button # push button 
 74  CAPTION = E.caption # table caption 
 75  CENTER = E.center # shorthand for DIV align=center (DEPRECATED) 
 76  CITE = E.cite # citation 
 77  CODE = E.code # computer code fragment 
 78  COL = E.col # table column 
 79  COLGROUP = E.colgroup # table column group 
 80  DD = E.dd # definition description 
 81  DEL = getattr(E, 'del') # deleted text 
 82  DFN = E.dfn # instance definition 
 83  DIR = E.dir # directory list (DEPRECATED) 
 84  DIV = E.div # generic language/style container 
 85  DL = E.dl # definition list 
 86  DT = E.dt # definition term 
 87  EM = E.em # emphasis 
 88  FIELDSET = E.fieldset # form control group 
 89  FONT = E.font # local change to font (DEPRECATED) 
 90  FORM = E.form # interactive form 
 91  FRAME = E.frame # subwindow 
 92  FRAMESET = E.frameset # window subdivision 
 93  H1 = E.h1 # heading 
 94  H2 = E.h2 # heading 
 95  H3 = E.h3 # heading 
 96  H4 = E.h4 # heading 
 97  H5 = E.h5 # heading 
 98  H6 = E.h6 # heading 
 99  HEAD = E.head # document head 
100  HR = E.hr # horizontal rule 
101  HTML = E.html # document root element 
102  I = E.i # italic text style 
103  IFRAME = E.iframe # inline subwindow 
104  IMG = E.img # Embedded image 
105  INPUT = E.input # form control 
106  INS = E.ins # inserted text 
107  ISINDEX = E.isindex # single line prompt (DEPRECATED) 
108  KBD = E.kbd # text to be entered by the user 
109  LABEL = E.label # form field label text 
110  LEGEND = E.legend # fieldset legend 
111  LI = E.li # list item 
112  LINK = E.link # a media-independent link 
113  MAP = E.map # client-side image map 
114  MENU = E.menu # menu list (DEPRECATED) 
115  META = E.meta # generic metainformation 
116  NOFRAMES = E.noframes # alternate content container for non frame-based rendering 
117  NOSCRIPT = E.noscript # alternate content container for non script-based rendering 
118  OBJECT = E.object # generic embedded object 
119  OL = E.ol # ordered list 
120  OPTGROUP = E.optgroup # option group 
121  OPTION = E.option # selectable choice 
122  P = E.p # paragraph 
123  PARAM = E.param # named property value 
124  PRE = E.pre # preformatted text 
125  Q = E.q # short inline quotation 
126  S = E.s # strike-through text style (DEPRECATED) 
127  SAMP = E.samp # sample program output, scripts, etc. 
128  SCRIPT = E.script # script statements 
129  SELECT = E.select # option selector 
130  SMALL = E.small # small text style 
131  SPAN = E.span # generic language/style container 
132  STRIKE = E.strike # strike-through text (DEPRECATED) 
133  STRONG = E.strong # strong emphasis 
134  STYLE = E.style # style info 
135  SUB = E.sub # subscript 
136  SUP = E.sup # superscript 
137  TABLE = E.table #  
138  TBODY = E.tbody # table body 
139  TD = E.td # table data cell 
140  TEXTAREA = E.textarea # multi-line text field 
141  TFOOT = E.tfoot # table footer 
142  TH = E.th # table header cell 
143  THEAD = E.thead # table header 
144  TITLE = E.title # document title 
145  TR = E.tr # table row 
146  TT = E.tt # teletype or monospaced text style 
147  U = E.u # underlined text style (DEPRECATED) 
148  UL = E.ul # unordered list 
149  VAR = E.var # instance of a variable or program argument 
150   
151  # attributes (only reserved words are included here) 
152  ATTR = dict 
153 -def CLASS(v): return {'class': v}
154 -def FOR(v): return {'for': v}
155