Skip to content

Commit 19c5eba

Browse files
committed
add_style() added support for receiving HTML objects
1 parent 70f4e06 commit 19c5eba

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
* Exported `is_tag_node()` and `is_tag_child()` functions that utilize `typing.TypeIs` to narrow `TagNode` and `TagChild` type variables, respectively. (#86)
2727

2828
* Exported `consolidate_attrs(*args, **kwargs)` function. This function will combine the `TagAttrs` (supplied in `*args`) with `TagAttrValues` (supplied in `**kwargs`) into a single `TagAttrs` object. In addition, it will also return all `*args` that are not dictionary as a list of unaltered `TagChild` objects. (#86)
29-
* This function takes a list of `TagAttrs` and returns a single `TagAttrs` object. (#86)
29+
30+
* The `Tag` method `.add_style(style=)` added support for `HTML` objects in addition to `str` values. (#86)
3031

3132
### Bug fixes
3233

htmltools/_core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ def has_class(self, class_: str) -> bool:
780780
else:
781781
return False
782782

783-
def add_style(self: TagT, style: str, *, prepend: bool = False) -> TagT:
783+
def add_style(self: TagT, style: str | HTML, *, prepend: bool = False) -> TagT:
784784
"""
785785
Add a style value(s) to the HTML style attribute.
786786
@@ -804,7 +804,7 @@ def add_style(self: TagT, style: str, *, prepend: bool = False) -> TagT:
804804
"""
805805

806806
if isinstance( # type: ignore[reportUnnecessaryIsInstance]
807-
style, str
807+
style, (str, HTML)
808808
) and not style.endswith(";"):
809809
raise ValueError("`Tag.add_style(style=)` must end with a semicolon")
810810

0 commit comments

Comments
 (0)