Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "python-hiccup"
version = "0.1.0"
version = "0.2.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
9 changes: 9 additions & 0 deletions src/python_hiccup/html/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def _to_bool_attributes(acc: str, attributes: set) -> str:
return _join(acc, attrs)


def _closing_tag(element: str) -> bool:
specials = {"script"}

return str.lower(element) in specials


def _suffix(element_data: str) -> str:
specials = {"doctype"}
normalized = str.lower(element_data)
Expand All @@ -68,6 +74,9 @@ def _to_html(tag: Mapping) -> list:
if flattened or content:
return [f"<{begin}>", *flattened, *content, f"</{element}>"]

if _closing_tag(element):
return [f"<{begin}>", f"</{element}>"]

extra = _suffix(begin)

return [f"<{begin}{extra}>"]
Expand Down
11 changes: 10 additions & 1 deletion test/test_render_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,20 @@ def test_parses_attribute_shorthand() -> None:
assert render(data) == expected


def test_explicit_closing_tag() -> None:
"""Assert that some html elements are parsed with a closing tag."""
data = ["script"]

expected = "<script></script>"

assert render(data) == expected


def test_parses_boolean_attributes() -> None:
"""Assert that attributes without values, such as async or defer, is parsed as expected."""
data = ["script", {"async"}, {"src": "path/to/script"}]

expected = '<script src="path/to/script" async />'
expected = '<script src="path/to/script" async></script>'

assert render(data) == expected

Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.