Support _repr_html_ and __html__ in both directions#1
Merged
niklasf merged 4 commits intoniklasf:masterfrom Jan 11, 2025
Merged
Support _repr_html_ and __html__ in both directions#1niklasf merged 4 commits intoniklasf:masterfrom
niklasf merged 4 commits intoniklasf:masterfrom
Conversation
_repr_html_ is already supported to allow fragments to be rendered in a jupyter notebook - this change extends that support in two ways: - it allows fragments to also render objects that support this protocol, so objects that already display html in a notebook can be rendered directly. - in addition to _repr_html_, fragments also allow rendering and being rendered by __html__. This means that tinyhtml fragments can be rendered in other templates like Jinja.
Owner
|
Awesome. Will release as 1.3.0 in a moment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello, thanks for the library - it's really neat to be able to read a single short file and see immediately how everything works.
This PR is a small suggestion to extend the ideas already there around
_repr_html_in two ways:__html__convention, so tinyhtml fragments can be included directly in something like a Jinja template (and vice-versa for objects annotated with__html__)._repr_html_as part of a template. This is intended to allow inclusion of things that are already renderable in Jupyter notebooks without any additional work.For context, I'd like to use tinyhtml as part of a library where 1.) I don't want to be too prescriptive about what templating engine people use and 2.) I expect many people will be using Jupyter notebooks, and may already be working with objects that have
_repr_html_that they want to be rendered as part of a bigger template.Obviously it's not a huge deal to have people wrap things in
raw()if they're using something else, it just turns out almost all of the supporting infrastructure is already in tinyhtml so it didn't seem too big a change to propose.(I also extended tests and metadata to 3.13 while I was here :)