dj_angles.replacers.attributes

Replace attributes like <div dj-if=”condition”> with Django template tags.

  1. Parses HTML into a tree structure

  2. Groups conditional elements by their parent (siblings)

  3. Chains siblings together (if → elif → else)

  4. Generates output with proper {% if %}/{% endif %} wrapping

Module Contents

class dj_angles.replacers.attributes.ConditionalElement

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

type: str
condition: str
start_pos: int
end_pos: int
full_end_pos: int
original_tag: str
original_full: str
attr_match: re.Match
chain_id: int
next_in_chain: ConditionalElement | None = None
dj_angles.replacers.attributes.replace_attributes(html: str) str

Convert dj-if/elif/else attributes to Django template tags.

Parameters:
  • html – The HTML string to process

  • prefix – The attribute prefix (default “dj-“). If None, uses detailed configuration.

Returns:

HTML with Django template tags