Skip to content

Commit

Permalink
style is special as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tammoippen committed Aug 18, 2023
1 parent ff78269 commit 812567d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tagic/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ class script(HTMLElement):
blocking: bool = False

def do_render(self, indent: str | None) -> str:
# script-tags must have a closing tag, they cannot be self-closing
# script-tags must have a closing tag
if self.children == []:
self.children = [""]
return super(script, self).do_render(indent)
Expand Down Expand Up @@ -1244,6 +1244,12 @@ class style(HTMLElement):
title: str | None = None
blocking: bool = False

def do_render(self, indent: str | None) -> str:
# style-tags must have a closing tag
if self.children == []:
self.children = [""]
return super(style, self).do_render(indent)


@dataclass(kw_only=True, slots=True, repr=False)
class sub(HTMLElement):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
p,
script,
span,
style,
title,
)
from tagic.html import (
Expand Down Expand Up @@ -283,3 +284,10 @@ def test_script_is_special():
assert "<script type=\"text/javascript\">console.log('test');</script>" == str(
script(type="text/javascript")[base.NoEscape("console.log('test');")]
)


def test_style_is_special():
assert "<style></style>" == str(style())
assert "<style>p {\n color: #26b72b;\n}</style>" == str(
style[base.NoEscape("p {\n color: #26b72b;\n}")]
)

0 comments on commit 812567d

Please sign in to comment.