HTMLSerializer


Attributes

a encoding

'utf-8'

a noescape_elements

set(['style', 'script'])

a boolean_attributes

set(['compact', 'defer', 'checked', 'nohref', 'selected', 'ismap', 'disabled', 'noshade', 'noresize', 'multiple', 'nowrap', 'declare'])

a formatted

False

a empty_elements

set(['img', 'area', 'basefont', 'frame', 'isindex', 'meta', 'param', 'hr', 'base', 'link', 'br', 'input', 'col'])

a formatted_elements

set(['pre', 'code', 'textarea', 'script', 'kbd', 'math'])

a src_encoding

'utf-8'

a format

Format(simple_newlines=True)

a transpose

False

a inline_elements

set(['em', 'code', 'kbd', 'font', 'select', 'span', 'sub', 'img', 'bdo', 'label', 'basefont', 'dfn', 'sup', 'strike', 'input', 'samp', 'cite', 'acronym', 'big', 'var', 'abbr', 'br', 'strong', 'a', 'b', 'textarea', 'i', 'q', 's', 'u', 'small', 'tt'])

a namespaces

{'http://purl.org/atom/ns#': 'atom',
 'http://purl.org/rss/1.0/': 'rss',
 'http://www.w3.org/1999/02/22-rdf-syntax-ns#': 'rdf',
 'http://www.w3.org/1999/xhtml': 'html',
 'http://www.w3.org/XML/1998/namespace': 'xml'}

a doctype

('HTML',
 '-//W3C//DTD HTML 4.01 Transitional//EN',
 'http://www.w3.org/TR/html4/loose.dtd')

a inject_type

True

a inline

False

a entity_map

None

Methods

f serialize(self, stream, encoding=None, fragment=False, format=None) ...

f write(self, stream, file, encoding=None, fragment=False, format=None) ...

f apply_filters(self, stream, format=None) ...

f format_stream(self, stream, format) ...

Apply format to stream.

Note that this method is unaware of the serialization of the tags and does only take into account the text inside the stream. So the results may sometimes differ from what you expect when formatting the complete serialized output.

f can_be_empty_element(self, tag) ...

f is_formatted(self, tag) ...

f is_inline(self, tag) ...

f inject_meta_content_type(self, stream, encoding) ...

Injects a meta tag for the content-type.

f inject_meta_tags(self, stream, taglist) ...

Injects meta tags at the start of the head section.

If meta tags already exist at that position, they are kept. Expects a list of meta-tag attributes with content keys. The attribute names and values must be given in lower case.

f __init__(self, encoding='utf-8', doctype=None, transpose=False, inject_type=None, entity_map=None, format=None) ...

Initialize HTMLSerializer.

You can change the following parameters:

encoding: the output encoding doctype: add doctype (None, string, tuple) transpose: alter tag names (None, True/False, callable) inject_type: inject content type (True/False) entity_map: use named entities for output (True/False or mapping) format: format to be applied (string or instance of Format)

f tagname(tag) ...

Remove namespace from tag and make it lowercase.

f is_escape(self, tag) ...

f is_boolean_attribute(self, attribute) ...

f generate(self, stream, encoding=None, fragment=False, format=None) ...

Serializes an event stream to bytes of the specified encoding.

This function yields an encoded string over and over until the stream is exhausted.

f escape_cdata(text, encoding=None, entity_map=None, escape=True) ...

Escape character data.

f escape_attrib(text, encoding=None, entity_map=None) ...

Escape attribute value.

See the source for more information.