fix: normalize Html subclasses in as_html for correct f-string formatting#8223
Merged
mscolnick merged 1 commit intomarimo-team:mainfrom Feb 10, 2026
Merged
Conversation
…ting
When `mo.as_html(mo.md("# Title"))` is used in an f-string, Python calls
`__format__` on the returned object. Since `_md` overrides `__format__`
to return raw markdown (to support nested `mo.md()` calls), the f-string
produces raw markdown instead of HTML.
Fix by normalizing Html subclasses to plain Html objects in `as_html()`,
so that `__format__` returns processed HTML text.
Closes marimo-team#7931
Contributor
|
@Light2Dark i know you were looking at this before. what do you think of this approach? |
Collaborator
|
I think this should be an improvement over the original behaviour. Tested it with the smoke tests However, nested markdown and nested md in Html still doesn't work cleanly. You'd need to call eg. #7931 (comment) solution = mo.md("**the solution**")
mo.md(rf"""
<details>
<summary>
Solution
</summary>
{solution}
</details>
""") |
Light2Dark
approved these changes
Feb 10, 2026
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.19.10-dev35 |
mscolnick
added a commit
that referenced
this pull request
Feb 10, 2026
…g formatting (#8223)" (#8257) This reverts commit 2d2f100. Commit 2d2f100 changed as_html() to normalize Html subclasses (like Spinner) into plain Html objects. This creates a new object, breaking the identity-based comparison (is not) in output.remove(). When the spinner's context manager exits and calls remove(self), it can't find the spinner in the output list because a different Html object was stored.
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.
Summary
f"{mo.as_html(mo.md('# Title'))}"returned raw markdown instead of rendered HTML becausemo.md()returns an_mdsubclass that overrides__format__(). Normalizes subclasses to the baseHtmltype so f-string formatting works correctly.Closes #7931
Test Plan
as_html(mo.md(...))returns baseHtmltype