The HtmlBuilder class implements the standard XHTML tag set with all attributes. No additional whitespace is added. >>> from pagebot.toolbox.color import color >>> b = HtmlBuilder() >>> b.compact = True >>> b.html() >>> b.body() >>> b.addHtml('Hello world') >>> b.add
| 31 | from pagebot.constants import DEFAULT_FONT |
| 32 | |
| 33 | class HtmlBuilder(XmlBuilder): |
| 34 | """The HtmlBuilder class implements the standard XHTML tag set with all |
| 35 | attributes. No additional whitespace is added. |
| 36 | |
| 37 | >>> from pagebot.toolbox.color import color |
| 38 | >>> b = HtmlBuilder() |
| 39 | >>> b.compact = True |
| 40 | >>> b.html() |
| 41 | >>> b.body() |
| 42 | >>> b.addHtml('Hello world') |
| 43 | >>> b.addCss('body {background-color: %s;}' % color('yellow').css) |
| 44 | >>> b._body() |
| 45 | >>> b._html() |
| 46 | >>> b.getHtml() |
| 47 | '<html xmlns="http://www.w3.org/1999/xhtml"><body>Hello world</body></html>' |
| 48 | >>> ''.join(b._cssOut) |
| 49 | 'body {background-color: #FFFF00;}' |
| 50 | """ |
| 51 | # ID to make build_html hook name. Views will be calling e.build_html() |
| 52 | PB_ID = 'html' |
| 53 | |
| 54 | # Names of attributes that are written without their value. |
| 55 | # Since this breaks XML validation, this list is empty by default, |
| 56 | # but it can be redefined by the inheriting application class. |
| 57 | SINGLE_ATTRIBUTES = [] |
| 58 | # Attributes that allow attributes to be tuple or list and joined |
| 59 | # on tag output with separating spaces. |
| 60 | CASCADING_ATTRIBUTES = ('cssClass', 'class') |
| 61 | |
| 62 | HTML_ATTRIBUTES = {'dir', 'lang', 'xmllang', 'manifest'} |
| 63 | |
| 64 | HEAD_ATTRIBUTES = {'profile'} |
| 65 | |
| 66 | LINK_ATTRIBUTES = {'charset', 'href', 'hreflang', 'media', 'rel', |
| 67 | 'rev', 'target', 'dir', 'lang', 'type', 'sizes' } |
| 68 | |
| 69 | BODY_ATTRIBUTES = {'dir', 'lang', |
| 70 | 'onload', 'onunload', 'ondblclick', 'onmousedown', 'onmouseup', |
| 71 | 'onmouseover', 'onmousemove', 'onmouseout', 'onkeypress', 'onkeydown', |
| 72 | 'onkeyup'} |
| 73 | |
| 74 | H_ATTRIBUTES = {'dir', 'lang'} |
| 75 | |
| 76 | LABEL_ATTRIBUTES = {'for'} |
| 77 | |
| 78 | BUTTON_ATTRIBUTES = INPUT_ATTRIBUTES = {'accesskey', 'dirname', 'onblur', |
| 79 | 'pattern', 'relation', 'onchange', 'type', 'onmouseup', 'value', 'step', |
| 80 | 'onmousedown', 'autofocus', 'onkeypress', 'onselect', 'list', 'formnovalidate', |
| 81 | 'maxlength', 'onkeyup', 'tabindex', 'autocapitalize', 'autocorrect', |
| 82 | 'results', 'min', 'placeholder', 'formtaget', 'inputmode', 'src', |
| 83 | 'formaction', 'height', 'formenctype', 'size', 'onmousemove', 'name', |
| 84 | 'alt', 'autocomplete', 'onmouseout', 'required', 'onkeydown', 'multiple', |
| 85 | 'ondblclick', 'readonly', 'onfocus', 'accept', 'align', 'form', 'max', |
| 86 | 'disabled', 'checked', 'formmethod', 'onmouseover'} |
| 87 | |
| 88 | INPUT_ATTRIBUTES_DEFAULTS = {'alt':'+', 'disabled': 'false'} |
| 89 | |
| 90 | BLOCKQUOTE_ATTRIBUTES = {} |