dom_tag

class domilite.tags.dom_tag(*args: str | dom_tag | Markup, **kwargs: str | bool)[source]

Bases: object

Base class for any tag object.

Subclass this to create custom tags.

Parameters:
  • *args (string or tag) – Provide child tags, which will be added via add()

  • **kwargs (string or bool) – Provide attribute values, which will be added to attributes

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] = 2

Rendering flags for this tag.

name: Name = 'dom_tag'

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

Methods Documentation

add(*children: dom_tag | str | Markup) Self[source]

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[source]

Remove all chilren.

Returns:

self

Return type:

this tag, to facilitate method chaining

descendants() Iterator[dom_tag][source]

Iterate over all children and children of children recursively.

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

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

classmethod iter_subclasses() Iterator[type[Self]][source]

Iterate through all known subclasses of this tag, recursively.

remove(child: dom_tag | Markup) Self[source]

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[source]

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.