您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

174 行
6.0 KiB

  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. ARTICLE = E.article #: self-contained article
  37. ASIDE = E.aside #: indirectly-related content
  38. AUDIO = E.audio #: embedded audio file
  39. B = E.b #: bold text style
  40. BASE = E.base #: document base URI
  41. BASEFONT = E.basefont #: base font size (DEPRECATED)
  42. BDI = E.bdi #: isolate bidirectional text
  43. BDO = E.bdo #: I18N BiDi over-ride
  44. BIG = E.big #: large text style
  45. BLOCKQUOTE = E.blockquote #: long quotation
  46. BODY = E.body #: document body
  47. BR = E.br #: forced line break
  48. BUTTON = E.button #: push button
  49. CANVAS = E.canvas #: scriptable graphics container
  50. CAPTION = E.caption #: table caption
  51. CENTER = E.center #: shorthand for DIV align=center (DEPRECATED)
  52. CITE = E.cite #: citation
  53. CODE = E.code #: computer code fragment
  54. COL = E.col #: table column
  55. COLGROUP = E.colgroup #: table column group
  56. DATA = E.data #: machine-readable translation
  57. DATALIST = E.datalist #: list of options for an input
  58. DD = E.dd #: definition description
  59. DEL = getattr(E, 'del') #: deleted text
  60. DETAILS = E.details #: expandable section
  61. DFN = E.dfn #: instance definition
  62. DIALOG = E.dialog #: dialog box
  63. DIR = E.dir #: directory list (DEPRECATED)
  64. DIV = E.div #: generic language/style container
  65. DL = E.dl #: definition list
  66. DT = E.dt #: definition term
  67. EM = E.em #: emphasis
  68. EMBED = E.embed #: embedded external content
  69. FIELDSET = E.fieldset #: form control group
  70. FIGCAPTION = E.figcaption #: figure caption
  71. FIGURE = E.figure #: self-contained, possibly-captioned content
  72. FONT = E.font #: local change to font (DEPRECATED)
  73. FOOTER = E.footer #: footer for nearest ancestor
  74. FORM = E.form #: interactive form
  75. FRAME = E.frame #: subwindow
  76. FRAMESET = E.frameset #: window subdivision
  77. H1 = E.h1 #: heading
  78. H2 = E.h2 #: heading
  79. H3 = E.h3 #: heading
  80. H4 = E.h4 #: heading
  81. H5 = E.h5 #: heading
  82. H6 = E.h6 #: heading
  83. HEAD = E.head #: document head
  84. HEADER = E.header #: heading content
  85. HGROUP = E.hgroup #: heading group
  86. HR = E.hr #: horizontal rule
  87. HTML = E.html #: document root element
  88. I = E.i #: italic text style
  89. IFRAME = E.iframe #: inline subwindow
  90. IMG = E.img #: Embedded image
  91. INPUT = E.input #: form control
  92. INS = E.ins #: inserted text
  93. ISINDEX = E.isindex #: single line prompt (DEPRECATED)
  94. KBD = E.kbd #: text to be entered by the user
  95. LABEL = E.label #: form field label text
  96. LEGEND = E.legend #: fieldset legend
  97. LI = E.li #: list item
  98. LINK = E.link #: a media-independent link
  99. MAIN = E.main #: main content
  100. MAP = E.map #: client-side image map
  101. MARK = E.mark #: marked/highlighted text
  102. MARQUEE = E.marquee #: scrolling text
  103. MENU = E.menu #: menu list (DEPRECATED)
  104. META = E.meta #: generic metainformation
  105. METER = E.meter #: numerical value display
  106. NAV = E.nav #: navigation section
  107. NOBR = E.nobr #: prevent wrapping
  108. NOFRAMES = E.noframes #: alternate content container for non frame-based rendering
  109. NOSCRIPT = E.noscript #: alternate content container for non script-based rendering
  110. OBJECT = E.object #: generic embedded object
  111. OL = E.ol #: ordered list
  112. OPTGROUP = E.optgroup #: option group
  113. OPTION = E.option #: selectable choice
  114. OUTPUT = E.output #: result of a calculation
  115. P = E.p #: paragraph
  116. PARAM = E.param #: named property value
  117. PICTURE = E.picture #: picture with multiple sources
  118. PORTAL = E.portal #: embedded preview
  119. PRE = E.pre #: preformatted text
  120. PROGRESS = E.progress #: progress bar
  121. Q = E.q #: short inline quotation
  122. RB = E.rb #: ruby base text
  123. RP = E.rp #: ruby parentheses
  124. RT = E.rt #: ruby text component
  125. RTC = E.rtc #: ruby semantic annotation
  126. RUBY = E.ruby #: ruby annotations
  127. S = E.s #: strike-through text style (DEPRECATED)
  128. SAMP = E.samp #: sample program output, scripts, etc.
  129. SCRIPT = E.script #: script statements
  130. SEARCH = E.search #: set of form controls for a search
  131. SECTION = E.section #: generic standalone section
  132. SELECT = E.select #: option selector
  133. SLOT = E.slot #: placeholder for JS use
  134. SMALL = E.small #: small text style
  135. SOURCE = E.source #: source for picture/audio/video element
  136. SPAN = E.span #: generic language/style container
  137. STRIKE = E.strike #: strike-through text (DEPRECATED)
  138. STRONG = E.strong #: strong emphasis
  139. STYLE = E.style #: style info
  140. SUB = E.sub #: subscript
  141. SUMMARY = E.summary #: summary for <details>
  142. SUP = E.sup #: superscript
  143. TABLE = E.table #:
  144. TBODY = E.tbody #: table body
  145. TD = E.td #: table data cell
  146. TEMPLATE = E.template #: fragment for JS use
  147. TEXTAREA = E.textarea #: multi-line text field
  148. TFOOT = E.tfoot #: table footer
  149. TH = E.th #: table header cell
  150. THEAD = E.thead #: table header
  151. TIME = E.time #: date/time
  152. TITLE = E.title #: document title
  153. TR = E.tr #: table row
  154. TRACK = E.track #: audio/video track
  155. TT = E.tt #: teletype or monospaced text style
  156. U = E.u #: underlined text style (DEPRECATED)
  157. UL = E.ul #: unordered list
  158. VAR = E.var #: instance of a variable or program argument
  159. VIDEO = E.video #: embedded video file
  160. WBR = E.wbr #: word break
  161. # attributes (only reserved words are included here)
  162. ATTR = dict
  163. def CLASS(v): return {'class': v}
  164. def FOR(v): return {'for': v}