dom_tag¶
- class domilite.tags.dom_tag(*args: str | dom_tag | Markup, **kwargs: str | bool)[source]¶
Bases:
objectBase 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
The attributes associated with this tag.
The list of child tags or markup objects
The (HTML) classes associated with this tag, managed as a set of strings.
Rendering flags for this tag.
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.
Iterate over all children and children of children recursively.
find_tag_type(name)Find a particular subclass of this tag with a given name.
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
Attributesfor more details.
- classes¶
The (HTML) classes associated with this tag, managed as a set of strings. See
Classesfor more details.
- 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.