text

class domilite.util.text(text: str, escape: bool = True)[source]

Bases: dom_tag

Attributes Summary

attributes

The attributes associated with this tag.

children

The list of child tags or markup objects

classes

The (HTML) classes associated with this tag, managed as a set of strings.

flags

Rendering flags for this tag.

name

The name of this tag, inferred from the name of the class

Methods Summary

add(*children)

Add child tags to this tag.

clear()

Remove all chilren.

descendants()

Iterate over all children and children of children recursively.

find_tag_type(name)

Find a particular subclass of this tag with a given name.

iter_subclasses()

Iterate through all known subclasses of this tag, recursively.

remove(child)

Remove a particular child.

render([indent, flags, pretty, xhtml])

Render this tree of tags to a string.

Attributes Documentation

attributes: ClassVar[AttributesProperty['dom_tag']]

The attributes associated with this tag. See Attributes for more details.

children: list['dom_tag | Markup']

The list of child tags or markup objects

classes

The (HTML) classes associated with this tag, managed as a set of strings. See Classes for more details.

flags: ClassVar['Flags'] = 4

Rendering flags for this tag.

name: Name = 'text'

The name of this tag, inferred from the name of the class

Methods Documentation

add(*children: dom_tag | str | Markup) Self

Add child tags to this tag.

Parameters:

children (tag, string, or Markup) – Tags become children, strings are escaped, and Markup is text that is added raw to this tag.

Returns:

self

Return type:

this tag, to facilitate method chaining

clear() Self

Remove all chilren.

Returns:

self

Return type:

this tag, to facilitate method chaining

descendants() Iterator[dom_tag]

Iterate over all children and children of children recursively.

classmethod find_tag_type(name: str) type[Self] | None

Find a particular subclass of this tag with a given name.

classmethod iter_subclasses() Iterator[type[Self]]

Iterate through all known subclasses of this tag, recursively.

remove(child: dom_tag | Markup) Self

Remove a particular child. If you are removing a string, escape it first with Markup.escape().

Parameters:

child (tag or Markup) – Child to remove. If it doesn’t exist, an error will be raised.

Returns:

self

Return type:

this tag, to facilitate method chaining

render(indent: str = '  ', flags: ~domilite.render.RenderFlags = <RenderFlags.PRETTY: 1>, pretty: bool | None = None, xhtml: bool | None = None) str

Render this tree of tags to a string.

Parameters:
  • indent (str, optional) – String to use for indenting in pretty mode. Defaults to two spaces: ` `

  • flags (RenderFlags) – Adjust the rendering properties to use (e.g. turn off PRETTY)

  • pretty (bool or None) – Explicitly enable or disable pretty rendering.

  • xhtml (bool or None) – Explicitly enable or disable xhtml rendering.