Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: render all markdown cells in snippets, not just the title cell (#8480)

Myles Scolnicka70d556f4785
diff --git a/marimo/_snippets/snippets.py b/marimo/_snippets/snippets.py
index 4820578774..0179fdf50f 100644
--- a/marimo/_snippets/snippets.py
+++ b/marimo/_snippets/snippets.py
@@ -51,14 +51,14 @@ async def read_snippets(config: MarimoConfig) -> Snippets:
if not title and "# " in code:
title = get_title_from_code(code)
- ret = cell.run()
- if isinstance(ret, Awaitable):
- output, _defs = await ret
- else:
- output, _defs = ret
- sections.append(
- SnippetSection(html=output.text, id=cell._cell.cell_id)
- )
+ ret = cell.run()
+ if isinstance(ret, Awaitable):
+ output, _defs = await ret
+ else:
+ output, _defs = ret
+ sections.append(
+ SnippetSection(html=output.text, id=cell._cell.cell_id)
+ )
else:
sections.append(
SnippetSection(code=code, id=cell._cell.cell_id)
diff --git a/tests/_snippets/data/multi_markdown.py b/tests/_snippets/data/multi_markdown.py
new file mode 100644
index 0000000000..2b57f35b8e
--- /dev/null
+++ b/tests/_snippets/data/multi_markdown.py
@@ -0,0 +1,44 @@
+# Copyright 2026 Marimo. All rights reserved.
+import marimo
+
+__generated_with = "0.3.9"
+app = marimo.App()
+
+
+def __(mo):
+ mo.md(
+ r"""
+ # Multi Markdown Snippet
+
+ This is the title cell with a description.
+ """
+ )
+ return
+
+
+def __(mo):
+ mo.md(
+ r"""
+ This is a second markdown cell that should also be rendered.
+ """
+ )
+ return
+
+
+def __():
+ x = 1 + 1
+ return (x,)
+
+
+def __():
+ import marimo as mo
+
+ return (mo,)
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/tests/_snippets/test_snippets.py b/tests/_snippets/test_snippets.py
index 05fb561793..d9927a23e3 100644
--- a/tests/_snippets/test_snippets.py
+++ b/tests/_snippets/test_snippets.py
@@ -1,5 +1,7 @@
from __future__ import annotations
+from pathlib import Path
+
import pytest
from marimo._config.config import merge_default_config
@@ -10,6 +12,8 @@ from marimo._snippets.snippets import (
)
from marimo._utils.platform import is_windows
+TEST_DATA_DIR = str(Path(__file__).parent / "data")
+
async def test_snippets() -> None:
snippets = await read_snippets(merge_default_config({}))
@@ -58,6 +62,32 @@ def test_get_title_from_code_with_mo_md() -> None:
assert get_title_from_code(code) == "This is a title"
+async def test_snippets_with_multiple_markdown_cells() -> None:
+ """Regression test: all markdown cells should be rendered, not just the title."""
+ config = merge_default_config(
+ {
+ "snippets": {
+ "include_default_snippets": False,
+ "custom_paths": [TEST_DATA_DIR],
+ }
+ }
+ )
+ snippets = await read_snippets(config)
+ assert len(snippets.snippets) == 1
+ snippet = snippets.snippets[0]
+ assert snippet.title == "Multi Markdown Snippet"
+
+ html_sections = [s for s in snippet.sections if s.html is not None]
+ code_sections = [s for s in snippet.sections if s.code is not None]
+
+ # Both markdown cells should be rendered as HTML sections
+ assert len(html_sections) == 2, (
+ f"Expected 2 HTML sections (title + description), got {len(html_sections)}"
+ )
+ # The code cell should be rendered
+ assert len(code_sections) == 1
+
+
total_snippets = len(list(read_snippet_filenames(True, [])))