Skip to content

adjunct.html

HTML parsing and serialisation support.

Element dataclass

A HTML element.

Attributes:

Name Type Description
tag str | None

the tag name

attrs dict

the tag's attributes

children list

the child elements of the element

serialize(dest=None)

Serialise the element to a file-like object.

Parameters:

Name Type Description Default
dest TextIO | None

the file-like object to serialise the document to; if this is None, as io.StringIO object will be created instead.

None

Returns:

Type Description
TextIO

A file-like object containing the serialised element.

make(tag, attrs, *, close=None)

Helper for quickly constructing a HTML tag.

Parameters:

Name Type Description Default
tag str

tag name

required
attrs Mapping[str, str | None]

attributes to apply to the tag

required
close bool | None

set to True or False to determine whether a closing tag should be generated; omit to let the function decide

None

Returns:

Type Description
str

the tag

parse(markup)

Parse a HTML document, returning its root element.

Parameters:

Name Type Description Default
markup str

the document to parse

required

Returns:

Type Description
Element

The root element of the document.