Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
keithasaurus committed Oct 19, 2023
1 parent a1772b2 commit 080b126
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions simple_html/nodes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Tuple, Union, Dict, List, Generator, Optional
from typing import Tuple, Union, Dict, List, Generator, Optional, Literal

SafeString = Tuple[str]
SafeString = Tuple[Literal[":safe:"], str]


def safe_string(x: str) -> SafeString:
return (x,)
def safe_string(s: str) -> SafeString:
return ":safe:", s


Node = Union[
Expand Down Expand Up @@ -45,7 +45,7 @@ def __call__(
if children:
return f"{self.tag_start}{attrs}>", children, self.closing_tag
else:
return f"{self.tag_start}{attrs}{self.no_children_close}",
return ":safe:", f"{self.tag_start}{attrs}{self.no_children_close}"
return self.opening_tag, children, self.closing_tag


Expand Down
10 changes: 5 additions & 5 deletions simple_html/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ def _render(node: Node, strs: List[str]) -> None:
mutate a list instead of constantly rendering strings
"""
if type(node) is tuple:
if len(node) == 3:
if node[0] == ":safe:":
if TYPE_CHECKING:
node = cast(SafeString, node)
strs.append(node[0])
else:
if TYPE_CHECKING:
node = cast(TagTuple, node)
strs.append(node[0])
for child in node[1]:
_render(child, strs)
strs.append(node[2])
else:
if TYPE_CHECKING:
node = cast(SafeString, node)
strs.append(node[0])
elif isinstance(node, str):
strs.append(escape(node))
elif isinstance(node, Tag):
Expand Down

0 comments on commit 080b126

Please sign in to comment.