Skip to content

fix: normalize Html subclasses in as_html for correct f-string formatting#8223

Merged
mscolnick merged 1 commit intomarimo-team:mainfrom
AhmadYasser1:fix/as-html-md-format
Feb 10, 2026
Merged

fix: normalize Html subclasses in as_html for correct f-string formatting#8223
mscolnick merged 1 commit intomarimo-team:mainfrom
AhmadYasser1:fix/as-html-md-format

Conversation

@AhmadYasser1
Copy link
Contributor

Summary

f"{mo.as_html(mo.md('# Title'))}" returned raw markdown instead of rendered HTML because mo.md() returns an _md subclass that overrides __format__(). Normalizes subclasses to the base Html type so f-string formatting works correctly.

Closes #7931

Test Plan

  • Added test verifying as_html(mo.md(...)) returns base Html type

…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
@mscolnick mscolnick requested a review from Light2Dark February 9, 2026 21:33
@mscolnick
Copy link
Contributor

@Light2Dark i know you were looking at this before. what do you think of this approach?

@Light2Dark Light2Dark added the bug Something isn't working label Feb 10, 2026
@Light2Dark
Copy link
Collaborator

Light2Dark commented Feb 10, 2026

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 .text or wrap with as_html

eg. #7931 (comment)

solution = mo.md("**the solution**")

mo.md(rf"""
<details>
    <summary>
    Solution
    </summary>
    {solution}
</details>
""")

@mscolnick mscolnick merged commit 2d2f100 into marimo-team:main Feb 10, 2026
29 of 44 checks passed
@github-actions
Copy link

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.19.10-dev35

@AhmadYasser1 AhmadYasser1 deleted the fix/as-html-md-format branch February 10, 2026 16:11
mscolnick added a commit that referenced this pull request Feb 10, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

as_html not working as expected for markdown

3 participants