You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.2 KiB

4 years ago
  1. # --------------------------------------------------------------------
  2. # The ElementTree toolkit is
  3. # Copyright (c) 1999-2004 by Fredrik Lundh
  4. # --------------------------------------------------------------------
  5. """
  6. A set of HTML generator tags for building HTML documents.
  7. Usage::
  8. >>> from lxml.html.builder import *
  9. >>> html = HTML(
  10. ... HEAD( TITLE("Hello World") ),
  11. ... BODY( CLASS("main"),
  12. ... H1("Hello World !")
  13. ... )
  14. ... )
  15. >>> import lxml.etree
  16. >>> print lxml.etree.tostring(html, pretty_print=True)
  17. <html>
  18. <head>
  19. <title>Hello World</title>
  20. </head>
  21. <body class="main">
  22. <h1>Hello World !</h1>
  23. </body>
  24. </html>
  25. """
  26. from lxml.builder import ElementMaker
  27. from lxml.html import html_parser
  28. E = ElementMaker(makeelement=html_parser.makeelement)
  29. # elements
  30. A = E.a # anchor
  31. ABBR = E.abbr # abbreviated form (e.g., WWW, HTTP, etc.)
  32. ACRONYM = E.acronym #
  33. ADDRESS = E.address # information on author
  34. APPLET = E.applet # Java applet (DEPRECATED)
  35. AREA = E.area # client-side image map area
  36. B = E.b # bold text style
  37. BASE = E.base # document base URI
  38. BASEFONT = E.basefont # base font size (DEPRECATED)
  39. BDO = E.bdo # I18N BiDi over-ride
  40. BIG = E.big # large text style
  41. BLOCKQUOTE = E.blockquote # long quotation
  42. BODY = E.body # document body
  43. BR = E.br # forced line break
  44. BUTTON = E.button # push button
  45. CAPTION = E.caption # table caption
  46. CENTER = E.center # shorthand for DIV align=center (DEPRECATED)
  47. CITE = E.cite # citation
  48. CODE = E.code # computer code fragment
  49. COL = E.col # table column
  50. COLGROUP = E.colgroup # table column group
  51. DD = E.dd # definition description
  52. DEL = getattr(E, 'del') # deleted text
  53. DFN = E.dfn # instance definition
  54. DIR = E.dir # directory list (DEPRECATED)
  55. DIV = E.div # generic language/style container
  56. DL = E.dl # definition list
  57. DT = E.dt # definition term
  58. EM = E.em # emphasis
  59. FIELDSET = E.fieldset # form control group
  60. FONT = E.font # local change to font (DEPRECATED)
  61. FORM = E.form # interactive form
  62. FRAME = E.frame # subwindow
  63. FRAMESET = E.frameset # window subdivision
  64. H1 = E.h1 # heading
  65. H2 = E.h2 # heading
  66. H3 = E.h3 # heading
  67. H4 = E.h4 # heading
  68. H5 = E.h5 # heading
  69. H6 = E.h6 # heading
  70. HEAD = E.head # document head
  71. HR = E.hr # horizontal rule
  72. HTML = E.html # document root element
  73. I = E.i # italic text style
  74. IFRAME = E.iframe # inline subwindow
  75. IMG = E.img # Embedded image
  76. INPUT = E.input # form control
  77. INS = E.ins # inserted text
  78. ISINDEX = E.isindex # single line prompt (DEPRECATED)
  79. KBD = E.kbd # text to be entered by the user
  80. LABEL = E.label # form field label text
  81. LEGEND = E.legend # fieldset legend
  82. LI = E.li # list item
  83. LINK = E.link # a media-independent link
  84. MAP = E.map # client-side image map
  85. MENU = E.menu # menu list (DEPRECATED)
  86. META = E.meta # generic metainformation
  87. NOFRAMES = E.noframes # alternate content container for non frame-based rendering
  88. NOSCRIPT = E.noscript # alternate content container for non script-based rendering
  89. OBJECT = E.object # generic embedded object
  90. OL = E.ol # ordered list
  91. OPTGROUP = E.optgroup # option group
  92. OPTION = E.option # selectable choice
  93. P = E.p # paragraph
  94. PARAM = E.param # named property value
  95. PRE = E.pre # preformatted text
  96. Q = E.q # short inline quotation
  97. S = E.s # strike-through text style (DEPRECATED)
  98. SAMP = E.samp # sample program output, scripts, etc.
  99. SCRIPT = E.script # script statements
  100. SELECT = E.select # option selector
  101. SMALL = E.small # small text style
  102. SPAN = E.span # generic language/style container
  103. STRIKE = E.strike # strike-through text (DEPRECATED)
  104. STRONG = E.strong # strong emphasis
  105. STYLE = E.style # style info
  106. SUB = E.sub # subscript
  107. SUP = E.sup # superscript
  108. TABLE = E.table #
  109. TBODY = E.tbody # table body
  110. TD = E.td # table data cell
  111. TEXTAREA = E.textarea # multi-line text field
  112. TFOOT = E.tfoot # table footer
  113. TH = E.th # table header cell
  114. THEAD = E.thead # table header
  115. TITLE = E.title # document title
  116. TR = E.tr # table row
  117. TT = E.tt # teletype or monospaced text style
  118. U = E.u # underlined text style (DEPRECATED)
  119. UL = E.ul # unordered list
  120. VAR = E.var # instance of a variable or program argument
  121. # attributes (only reserved words are included here)
  122. ATTR = dict
  123. def CLASS(v): return {'class': v}
  124. def FOR(v): return {'for': v}