-
Notifications
You must be signed in to change notification settings - Fork 892
Markdown to return html string instead of just markdown #7934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
14abc39 to
3e2fc78
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #7931 where mo.as_html(mo.md(...)) was not working as expected - it was rendering raw markdown text instead of formatted HTML when embedded in HTML templates.
Changes:
- Modified
_md.__format__()to return rendered HTML (self.text) instead of raw markdown text (self._markdown_text) - Updated existing test to reflect the new behavior
- Added comprehensive test coverage for various nesting scenarios with markdown and HTML
- Extended smoke tests with extensive edge cases for nested markdown and HTML combinations
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| marimo/_output/md.py | Changed __format__ method to return rendered HTML instead of raw markdown, fixing the embedding issue |
| tests/_output/test_hypertext.py | Updated test docstrings and assertions to match new behavior; added comprehensive tests for md-in-html, html-in-md, and various nesting scenarios |
| marimo/_smoke_tests/markdown/codeblocks.py | Added extensive manual test cases covering edge cases for nested markdown/HTML, code blocks, tables, lists, and various combinations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @app.cell(hide_code=True) | ||
| def _(mo): | ||
| code_block = mo.md(""" | ||
| code_block=mo.md(""" |
Copilot
AI
Jan 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space around assignment operator. Python style guidelines (PEP 8) recommend spaces around assignment operators for readability.
| code_block=mo.md(""" | |
| code_block = mo.md(""" |
|
looks like nested inner = md("**bold**")
outer = md(f"Text: {inner}")
print(f"Nested mo.md: {outer.text}")Nested mo.md: <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Text: <span class="markdown prose dark:prose-invert contents"><span class="paragraph"><strong>bold</strong></span></span></span></span>expected: Nested mo.md: <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Text: <strong>bold</strong></span></span> |
Good catch @ffmiruz , that used to work better when I guess in the current state, if users want HTML string, call |
Haha yea the price to pay so we can embed. What do you think about doing this #7931 (comment)? |
|
@ffmiruz that doesn't solve the original issue the PR tried to solve which was nested code blocks in markdown losing their formatting _code_block = mo.md("""
```python
def add(x: int, y: int):
return x + y
```
""")
mo.md(f"""
**Nested code block**
{_code_block}
""") |

📝 Summary
Closes #7931. markdown format to return
htmltext instead of markdown text. This still is an improvement over the old behaviour before this PR #6464before

In order to make ^ work, we need to use
.text. With this PR, we don't need to do that anymoreafter

🔍 Description of Changes
📋 Checklist