All notable changes to htmltools for Python will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
-
HTML
no longer inherits fromstr
. It now inherits fromcollections.UserString
. This was done to avoid confusion betweenstr
andHTML
objects. (#86) -
TagList
no longer inherits fromlist
. It now inherits fromcollections.UserList
. This was done to avoid confusion betweenlist
andTagList
objects. (#97) -
Tag
andTagList
's method.get_html_string()
now both returnstr
instead ofHTML
. (#86) -
Strings added to
HTML
objects, now returnHTML
objects. E.g.HTML_value + str_value
andstr_value + HTML_value
both returnHTML
objects. To maintain astr
result, callstr()
on yourHTML
objects before adding them to other strings values. (#86) -
Items added to
TagList
objects, now returnTagList
objects. E.g.TagList_value + arr_value
andarr_value + TagList_value
both return newTagList
objects. To maintain alist
result, calllist()
on yourTagList
objects before combining them to other list objects. (#97)
-
Exported
ReprHtml
protocol class. If an object has a_repr_html_
method, then it is of instanceReprHtml
. (#86) -
Exported
is_tag_node()
andis_tag_child()
functions that utilizetyping.TypeIs
to narrowTagNode
andTagChild
type variables, respectively. (#86) -
Exported
consolidate_attrs(*args, **kwargs)
function. This function will combine theTagAttrs
(supplied in*args
) withTagAttrValues
(supplied in**kwargs
) into a singleTagAttrs
object. In addition, it will also return all*args
that are not dictionary as a list of unalteredTagChild
objects. (#86) -
The
Tag
method.add_style(style=)
added support forHTML
objects in addition tostr
values. (#86)
- Fixed an issue with
HTMLTextDocument()
returning extractedHTMLDependency()
s in a non-determistic order. (#95)
- HTML tags in docstrings are now escaped. (#90)
- The
HTMLDependency.copy()
method can now correctly copy folders in depenendencies that both include directories and haveall_files=True
. (#87)
-
Tag
objects can now be used as context managers, as inwith tags.div():
. When used this way, then inside thewith
block,sys.displayhook
is replaced with a function which adds items as children to theTag
. This is meant to be used with Shiny Express, Quarto, or Jupyter. (#76) -
Added a function
wrap_displayhook_handler()
. This alliows displayhooks to delegate their logic for handling various kinds of objects (likeTag
objects and objects with a_repr_html()
) to this function. (#77)
-
Objects with a
_repr_html_
method can now appear as children ofTag
/TagList
objects. (#74) -
Changed the type annotation of
_add_ws
frombool
toTagAttrValue
. This makes it easier to write functions which callTag
functions and pass along**kwargs
. (#67) -
Changed the type annotation of
collapse_
fromstr
tostr | float | None
. This makes it easier to write calls tocss()
pass along**kwargs
. (#68) -
Enhanced the type definition of
TagAttrs
to includeTagAttrDict
, the type of aTag
'sattrs
property. (#55) -
For
HTMLTextDocument
objects, deduplicate HTML dependencies. (#72) -
Switched from
setup.cfg
andsetup.py
topyproject.toml
. (#73)
- Fixed deserialization of JSON HTML dependencies when they contained newline characters. (#65)
-
Added
HTMLTextDocument
class, which takes as input a string representation of an HTML document. (#61) -
Added
htmltools.html_dependency_render_mode
. If this is set to"json"
, thenHTMLDependency
objects will be rendered as JSON inside of<script>
tags. (#61)
-
Added
Tag
methodsremove_class
andadd_style
. (#57) -
Added support for
Tag
'sadd_class(prepend=)
. (#57)
- Dropped support for Python 3.7 (#56)
- Fixed the stype signature of the
TagFunction
protocol class.
-
Added support for URL based
HTMLDependency
objects. (#53) -
Tag functions now have a boolean parameter
_add_ws
, which determines if the tag should be surrounded by whitespace. Tags which are normally block elements (likediv
) have this default toTrue
, and tags which are normally inline elements (likespan
) have this default toFalse
. This makes it possible to create HTML where neighboring elements have no whitespace between them. For example,span(span("a"), span("b"))
will now yield<span><span>a</span><span>b</span></span>
. (#54)
-
Changed types hints for
Tag
functions. The new types areTagChild
,TagNode
,TagAttrValue
, andTagAttrs
. (#51) -
Add public-facing
html_escape
function.
- Removed default argument values which were mutable objects.
- Moved packages from requirements-dev.txt to setup.cfg.
- Added alias for
htmltools._util._package_dir
function, which was used by shinywidgets 0.1.4.
- Fixed path handling on Windows. (#47)