Skip to content

Conversation

@Light2Dark
Copy link
Contributor

@Light2Dark Light2Dark commented Jan 22, 2026

📝 Summary

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

before
image

image

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

after
image

image

🔍 Description of Changes

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.
@vercel
Copy link

vercel bot commented Jan 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jan 23, 2026 1:49pm

Request Review

@Light2Dark Light2Dark changed the title Markdown to return Jan 22, 2026
@Light2Dark Light2Dark added the bug Something isn't working label Jan 23, 2026
@Light2Dark Light2Dark requested a review from Copilot January 23, 2026 04:46
Copy link
Contributor

Copilot AI left a 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("""
Copy link

Copilot AI Jan 23, 2026

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.

Suggested change
code_block=mo.md("""
code_block = mo.md("""
Copilot uses AI. Check for mistakes.
@Light2Dark Light2Dark marked this pull request as ready for review January 23, 2026 04:59
@ffmiruz
Copy link

ffmiruz commented Jan 23, 2026

looks like nested mo.md() results in nested html

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>
@Light2Dark
Copy link
Contributor Author

Light2Dark commented Jan 23, 2026

looks like nested mo.md() results in nested html

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 __format__ just returned _markdown_text 🤔

I guess in the current state, if users want HTML string, call .text
if want the markdown text, just f"mo.md(...)" is fine. So it is more flexible. However, this does differ in the approach for mo.Html where __format__ returns .text

@Light2Dark Light2Dark marked this pull request as draft January 23, 2026 13:39
@ffmiruz
Copy link

ffmiruz commented Jan 24, 2026

looks like nested mo.md() results in nested html

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 __format__ just returned _markdown_text 🤔

I guess in the current state, if users want HTML string, call .text if want the markdown text, just f"mo.md(...)" is fine. So it is more flexible. However, this does differ in the approach for mo.Html where __format__ returns .text

Haha yea the price to pay so we can embed. What do you think about doing this #7931 (comment)?

@Light2Dark
Copy link
Contributor Author

Light2Dark commented Jan 26, 2026

@ffmiruz that doesn't solve the original issue the PR tried to solve which was nested code blocks in markdown losing their formatting
image

_code_block = mo.md("""
```python
def add(x: int, y: int):
    return x + y
```
""")

mo.md(f"""
**Nested code block**
{_code_block}
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

3 participants