dj_angles.replacers.attributes.elements

Module Contents

class dj_angles.replacers.attributes.elements.Element

Represents an HTML element with a dj-* attribute.

tag_name: str

Name of the HTML tag, e.g. div or img.

tag_start: int

Position of the < that starts the opening tag in the original HTML.

tag_end: int

Position just after the > that ends the opening tag.

full_end: int

Position just after the element’s closing tag, or tag_end for void/self-closing tags.

original_tag: str

The original opening tag string, including the dj-* attribute.

original_full: str

The full original element, from the opening tag through the closing tag.

attr_match: re.Match

Regex match for the dj-* attribute that triggered this element’s discovery.

type: str

The dj-* attribute type, e.g. if, elif, else, or value.

value: str = ''

The value of the dj-* attribute, e.g. the condition for dj-if or the variable for dj-value.

classmethod from_match(html: str, match: re.Match, attr_type: str) Element

Find the HTML element containing a dj-* attribute match and return an instance.

property is_closing: bool

Whether the element is a closing tag.

remove_attribute() str

Remove the dj-* attribute from the tag.

contains(other: Element) bool

Whether this element fully contains another element.

closing_tag() str

Return the existing closing tag or generate one.

make_edit(content: str, *, replace: bool = False) dj_angles.replacers.objects.AtomicEdit

Convenience: insert content at tag_start, optionally replacing the opening tag.

class dj_angles.replacers.attributes.elements.ConditionalElement

Bases: Element

Represents an element with a dj-if/elif/else attribute.

chain_id: int
next_in_chain: ConditionalElement | None = None
property condition: str

The condition value of the attribute (empty for else).

class dj_angles.replacers.attributes.elements.ForElement

Bases: Element

Represents an element with a dj-for/dj-empty/dj-endfor attribute.

empty_sibling: ForElement | None = None

The linked dj-empty element, if any.