OpenQuizz
Une application de gestion des contenus pédagogiques
HTMLSerializer Class Reference
Inheritance diagram for HTMLSerializer:
Collaboration diagram for HTMLSerializer:

Public Member Functions

def __init__ (self, **kwargs)
 
def encode (self, string)
 
def encodeStrict (self, string)
 
def serialize (self, treewalker, encoding=None)
 
def render (self, treewalker, encoding=None)
 
def serializeError (self, data="XXX ERROR MESSAGE NEEDED")
 

Data Fields

 errors
 
 strict
 
 encoding
 

Static Public Attributes

 quote_attr_values
 
 quote_char
 
 use_best_quote_char
 
 omit_optional_tags
 
 minimize_boolean_attributes
 
 use_trailing_solidus
 
 space_before_trailing_solidus
 
 escape_lt_in_attrs
 
 escape_rcdata
 
 resolve_entities
 
 alphabetical_attributes
 
 inject_meta_charset
 
 strip_whitespace
 
 sanitize
 
 options
 

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
**  kwargs 
)
Initialize HTMLSerializer

:arg inject_meta_charset: Whether or not to inject the meta charset.

    Defaults to ``True``.

:arg quote_attr_values: Whether to quote attribute values that don't
    require quoting per legacy browser behavior (``"legacy"``), when
    required by the standard (``"spec"``), or always (``"always"``).

    Defaults to ``"legacy"``.

:arg quote_char: Use given quote character for attribute quoting.

    Defaults to ``"`` which will use double quotes unless attribute
    value contains a double quote, in which case single quotes are
    used.

:arg escape_lt_in_attrs: Whether or not to escape ``<`` in attribute
    values.

    Defaults to ``False``.

:arg escape_rcdata: Whether to escape characters that need to be
    escaped within normal elements within rcdata elements such as
    style.

    Defaults to ``False``.

:arg resolve_entities: Whether to resolve named character entities that
    appear in the source tree. The XML predefined entities &lt; &gt;
    &amp; &quot; &apos; are unaffected by this setting.

    Defaults to ``True``.

:arg strip_whitespace: Whether to remove semantically meaningless
    whitespace. (This compresses all whitespace to a single space
    except within ``pre``.)

    Defaults to ``False``.

:arg minimize_boolean_attributes: Shortens boolean attributes to give
    just the attribute value, for example::

      <input disabled="disabled">

    becomes::

      <input disabled>

    Defaults to ``True``.

:arg use_trailing_solidus: Includes a close-tag slash at the end of the
    start tag of void elements (empty elements whose end tag is
    forbidden). E.g. ``<hr/>``.

    Defaults to ``False``.

:arg space_before_trailing_solidus: Places a space immediately before
    the closing slash in a tag using a trailing solidus. E.g.
    ``<hr />``. Requires ``use_trailing_solidus=True``.

    Defaults to ``True``.

:arg sanitize: Strip all unsafe or unknown constructs from output.
    See :py:class:`html5lib.filters.sanitizer.Filter`.

    Defaults to ``False``.

:arg omit_optional_tags: Omit start/end tags that are optional.

    Defaults to ``True``.

:arg alphabetical_attributes: Reorder attributes to be in alphabetical order.

    Defaults to ``False``.

Member Function Documentation

◆ encode()

def encode (   self,
  string 
)

◆ encodeStrict()

def encodeStrict (   self,
  string 
)

◆ render()

def render (   self,
  treewalker,
  encoding = None 
)
Serializes the stream from the treewalker into a string

:arg treewalker: the treewalker to serialize

:arg encoding: the string encoding to use

:returns: the serialized tree

Example:

>>> from html5lib import parse, getTreeWalker
>>> from html5lib.serializer import HTMLSerializer
>>> token_stream = parse('<html><body>Hi!</body></html>')
>>> walker = getTreeWalker('etree')
>>> serializer = HTMLSerializer(omit_optional_tags=False)
>>> serializer.render(walker(token_stream))
'<html><head></head><body>Hi!</body></html>'

◆ serialize()

def serialize (   self,
  treewalker,
  encoding = None 
)

◆ serializeError()

def serializeError (   self,
  data = "XXX ERROR MESSAGE NEEDED" 
)

Field Documentation

◆ alphabetical_attributes

alphabetical_attributes
static

◆ encoding

encoding

◆ errors

errors

◆ escape_lt_in_attrs

escape_lt_in_attrs
static

◆ escape_rcdata

escape_rcdata
static

◆ inject_meta_charset

inject_meta_charset
static

◆ minimize_boolean_attributes

minimize_boolean_attributes
static

◆ omit_optional_tags

omit_optional_tags
static

◆ options

options
static

◆ quote_attr_values

quote_attr_values
static

◆ quote_char

quote_char
static

◆ resolve_entities

resolve_entities
static

◆ sanitize

sanitize
static

◆ space_before_trailing_solidus

space_before_trailing_solidus
static

◆ strict

strict

◆ strip_whitespace

strip_whitespace
static

◆ use_best_quote_char

use_best_quote_char
static

◆ use_trailing_solidus

use_trailing_solidus
static

The documentation for this class was generated from the following file: