|
5 | 5 | from collections.abc import Mapping, Sequence |
6 | 6 | from functools import reduce |
7 | 7 |
|
8 | | -from python_hiccup.transform import transform |
| 8 | +from python_hiccup.transform import CONTENT_TAG, transform |
9 | 9 |
|
10 | 10 |
|
11 | 11 | def _element_allows_raw_content(element: str) -> bool: |
@@ -56,23 +56,28 @@ def _suffix(element_data: str) -> str: |
56 | 56 | return "" if any(s in normalized for s in specials) else " /" |
57 | 57 |
|
58 | 58 |
|
59 | | -def _to_html(tag: Mapping) -> list: |
| 59 | +def _is_content(element: str) -> bool: |
| 60 | + return element == CONTENT_TAG |
| 61 | + |
| 62 | + |
| 63 | +def _to_html(tag: Mapping, parent: str = "") -> list: |
60 | 64 | element = next(iter(tag.keys())) |
61 | 65 | child = next(iter(tag.values())) |
62 | 66 |
|
| 67 | + if _is_content(element): |
| 68 | + return [_escape(str(child), parent)] |
| 69 | + |
63 | 70 | attributes = reduce(_to_attributes, tag.get("attributes", []), "") |
64 | 71 | bool_attributes = reduce(_to_bool_attributes, tag.get("boolean_attributes", []), "") |
65 | 72 | element_attributes = attributes + bool_attributes |
66 | 73 |
|
67 | | - content = [_escape(str(c), element) for c in tag.get("content", [])] |
68 | | - |
69 | | - matrix = [_to_html(c) for c in child] |
| 74 | + matrix = [_to_html(c, element) for c in child] |
70 | 75 | flattened: list = reduce(operator.iadd, matrix, []) |
71 | 76 |
|
72 | 77 | begin = f"{element}{element_attributes}" if element_attributes else element |
73 | 78 |
|
74 | | - if flattened or content: |
75 | | - return [f"<{begin}>", *flattened, *content, f"</{element}>"] |
| 79 | + if flattened: |
| 80 | + return [f"<{begin}>", *flattened, f"</{element}>"] |
76 | 81 |
|
77 | 82 | if _closing_tag(element): |
78 | 83 | return [f"<{begin}>", f"</{element}>"] |
|
0 commit comments