From d38691d93787f12f49280e7d0d71e30f453a7908 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sat, 28 Dec 2024 03:31:29 +0200 Subject: bump --- htmtl/htmtl.py | 100 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 20 deletions(-) (limited to 'htmtl') diff --git a/htmtl/htmtl.py b/htmtl/htmtl.py index 1de2cfa..15b37a1 100644 --- a/htmtl/htmtl.py +++ b/htmtl/htmtl.py @@ -1,5 +1,7 @@ from __future__ import annotations -from typing import Dict, Any, Tuple, Callable, Optional +from typing import Dict, Any, Tuple, Callable, Optional, Union + +from pygments.util import tag_re class Node: @@ -16,8 +18,7 @@ class Node: class IRBlockPosNode: name: str coords: Tuple[int, int] - moved: bool - children: list[IRBlockPosNode] + children: list[Union[IRBlockPosNode, str]] def __init__(self, name: str, coords: Tuple[int, int]): self.name = name @@ -26,11 +27,10 @@ class IRBlockPosNode: class IRBlockNode: name: str - children: list[IRBlockNode] + children: list[Union[IRBlockNode, str]] def __init__(self, name: str, children: list[IRBlockNode]): self.name = name - self.moved = False self.children = children @@ -50,40 +50,72 @@ class Htmtl: self.__ir_block_pos_nodes = [] self.__ir_block_nodes = [] self.__create_ir_block_pos_nodes() + self.__fill_ir_block_pos_node_caps() self.__join_ir_block_pos_nodes() - self.__create_ir_block_nodes() - # self.__create_nodes() - # self.__run_attribute_parsers() + #self.__create_ir_block_nodes() + self.__create_nodes() + self.__run_attribute_parsers() def __create_ir_block_pos_nodes(self): - start = None - end = None + tag_start = None + tag_end = None + text_start = None + text_end = None for idx, part in enumerate(self.__template): if part == "<": - start = idx + if text_start is not None: + text_end = idx + + tag_start = idx if part == ">": - end = idx + 1 + tag_end = idx + 1 - if start is not None and end is not None: - tag = self.__template[start:end] + if tag_start is not None and tag_end is not None: + tag = self.__template[tag_start:tag_end] if tag.startswith("