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.

break: update markdown output to include 'contents' class (#6804)

Myles Scolnick56df45617ad5
diff --git a/frontend/islands/__demo__/index.html b/frontend/islands/__demo__/index.html
index 6de26999bc..794cb1eea6 100644
--- a/frontend/islands/__demo__/index.html
+++ b/frontend/islands/__demo__/index.html
@@ -58,7 +58,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><span class="paragraph">Hello, islands!</span></span>
+ <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Hello, islands!</span></span>
</marimo-cell-output>
<marimo-cell-code hidden>mo.md('Hello%2C%20islands!')</marimo-cell-code>
</marimo-island>
@@ -78,7 +78,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><span class="paragraph">Slider value: 0</span></span>
+ <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Slider value: 0</span></span>
</marimo-cell-output>
<marimo-cell-code hidden>%0Amo.md(f%22Slider%20value%3A%20%7Bslider.value%7D%22)%0A</marimo-cell-code>
</marimo-island>
@@ -88,7 +88,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><span class="paragraph">We can also show the island code!</span></span>
+ <span class="markdown prose dark:prose-invert contents"><span class="paragraph">We can also show the island code!</span></span>
</marimo-cell-output>
<marimo-ui-element object-id='3f8d1379-362f-ff6e-5534-e045a7f80ff7' random-id='3f8d1379-362f-ff6e-5534-e045a7f80ff7'><marimo-code-editor data-initial-value='&quot;mo.md(&#92;&quot;We can also show the island code!&#92;&quot;)&quot;' data-label='null' data-language='&quot;python&quot;' data-placeholder='&quot;&quot;' data-disabled='false' data-show-copy-button='true' data-debounce='false'></marimo-code-editor></marimo-ui-element>
</marimo-island>
@@ -118,7 +118,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><h1 id="hello-markdown">Hello, Markdown!</h1>
+ <span class="markdown prose dark:prose-invert contents"><h1 id="hello-markdown">Hello, Markdown!</h1>
<span class="paragraph">Use marimo's "<code>md</code>" function to embed rich text into your marimo
apps. This function compiles Markdown into HTML that marimo
can display.</span>
@@ -142,7 +142,7 @@ paragraph:</span>
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><h2 id="latex">LaTeX</h2>
+ <span class="markdown prose dark:prose-invert contents"><h2 id="latex">LaTeX</h2>
<span class="paragraph">You can embed LaTeX in Markdown.</span>
<span class="paragraph">For example,</span>
<div class="language-python3 codehilite"><pre><span></span><code><span class="n">mo</span><span class="o">.</span><span class="n">md</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;$f : \mathbf</span><span class="si">{R}</span><span class="s1"> o \mathbf</span><span class="si">{R}</span><span class="s1">$&#39;</span><span class="p">)</span>
@@ -189,4 +189,4 @@ f: \mathbf{R} o \mathbf{R}.
</body>
</html>
-
+
diff --git a/marimo/_output/md.py b/marimo/_output/md.py
index 64f250f9df..c8f9d3dc81 100644
--- a/marimo/_output/md.py
+++ b/marimo/_output/md.py
@@ -246,7 +246,7 @@ class _md(Html):
).replace("</p>", "</span>")
if apply_markdown_class:
- classes = ["markdown", "prose", "dark:prose-invert"]
+ classes = ["markdown", "prose", "dark:prose-invert", "contents"]
if size is not None:
classes.append(f"prose-{size}")
super().__init__(
diff --git a/marimo/_smoke_tests/markdown/stacked.py b/marimo/_smoke_tests/markdown/stacked.py
new file mode 100644
index 0000000000..deefcb82b8
--- /dev/null
+++ b/marimo/_smoke_tests/markdown/stacked.py
@@ -0,0 +1,54 @@
+import marimo
+
+__generated_with = "0.17.0"
+app = marimo.App(width="medium")
+
+
+def _():
+ import marimo as mo
+ return (mo,)
+
+
+def _(mo):
+ items = [
+ mo.md("# one"),
+ mo.md("# two"),
+ mo.md("## three"),
+ mo.md("## four"),
+ ]
+ return (items,)
+
+
+def _(items, mo):
+ mo.hstack(items)
+ return
+
+
+def _(items, mo):
+ mo.vstack(items)
+ return
+
+
+def _(items, mo):
+ _items = [
+ mo.md("a" * 200),
+ mo.md("b" * 180),
+ mo.md("c" * 160),
+ ]
+ mo.vstack(
+ [
+ mo.hstack(items),
+ mo.md("---"),
+ *_items,
+ ]
+ )
+ return
+
+
+if __name__ == "__main__":
+ app.run()
diff --git a/tests/_islands/snapshots/island-mimetypes.txt b/tests/_islands/snapshots/island-mimetypes.txt
index 94e72dedf5..602e77dfb7 100644
--- a/tests/_islands/snapshots/island-mimetypes.txt
+++ b/tests/_islands/snapshots/island-mimetypes.txt
@@ -4,7 +4,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><span class="paragraph">Hello, islands!</span></span>
+ <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Hello, islands!</span></span>
</marimo-cell-output>
<marimo-cell-code hidden>mo.md('Hello%2C%20islands!')</marimo-cell-code>
</marimo-island>
@@ -34,7 +34,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <marimo-json-output data-json-data='[1,&quot;text/html:&lt;span class=&#92;&quot;markdown prose dark:prose-invert&#92;&quot;&gt;&lt;span class=&#92;&quot;paragraph&#92;&quot;&gt;Hello&lt;/span&gt;&lt;/span&gt;&quot;]' data-value-types='&quot;python&quot;'></marimo-json-output>
+ <marimo-json-output data-json-data='[1,&quot;text/html:&lt;span class=&#92;&quot;markdown prose dark:prose-invert contents&#92;&quot;&gt;&lt;span class=&#92;&quot;paragraph&#92;&quot;&gt;Hello&lt;/span&gt;&lt;/span&gt;&quot;]' data-value-types='&quot;python&quot;'></marimo-json-output>
</marimo-cell-output>
<marimo-cell-code hidden>%5B1%2C%20mo.md('Hello')%5D</marimo-cell-code>
</marimo-island>
\ No newline at end of file
diff --git a/tests/_islands/snapshots/island-no-code.txt b/tests/_islands/snapshots/island-no-code.txt
index 590c37d118..3410c740be 100644
--- a/tests/_islands/snapshots/island-no-code.txt
+++ b/tests/_islands/snapshots/island-no-code.txt
@@ -4,7 +4,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><span class="paragraph">Hello, islands!</span></span>
+ <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Hello, islands!</span></span>
</marimo-cell-output>
<marimo-cell-code hidden>mo.md('Hello%2C%20islands!')</marimo-cell-code>
</marimo-island>
\ No newline at end of file
diff --git a/tests/_islands/snapshots/island.txt b/tests/_islands/snapshots/island.txt
index 590c37d118..3410c740be 100644
--- a/tests/_islands/snapshots/island.txt
+++ b/tests/_islands/snapshots/island.txt
@@ -4,7 +4,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><span class="paragraph">Hello, islands!</span></span>
+ <span class="markdown prose dark:prose-invert contents"><span class="paragraph">Hello, islands!</span></span>
</marimo-cell-output>
<marimo-cell-code hidden>mo.md('Hello%2C%20islands!')</marimo-cell-code>
</marimo-island>
\ No newline at end of file
diff --git a/tests/_islands/snapshots/markdown.txt b/tests/_islands/snapshots/markdown.txt
index 5896df0346..467d116a3c 100644
--- a/tests/_islands/snapshots/markdown.txt
+++ b/tests/_islands/snapshots/markdown.txt
@@ -4,7 +4,7 @@
data-reactive="true"
>
<marimo-cell-output>
- <span class="markdown prose dark:prose-invert"><h1 id="hello-markdown">Hello, Markdown!</h1>
+ <span class="markdown prose dark:prose-invert contents"><h1 id="hello-markdown">Hello, Markdown!</h1>
<span class="paragraph">This is a paragsraph.</span>
<div class="language-python3 codehilite"><pre><span></span><code><span class="n">mo</span><span class="o">.</span><span class="n">md</span><span class="p">(</span>
<span class="w"> </span><span class="sd">&#39;&#39;&#39;</span>
diff --git a/tests/_output/formatters/test_formatters.py b/tests/_output/formatters/test_formatters.py
index 441369703e..ef378b15c7 100644
--- a/tests/_output/formatters/test_formatters.py
+++ b/tests/_output/formatters/test_formatters.py
@@ -185,7 +185,7 @@ def test_repr_markdown():
assert mime == "text/html"
assert (
content
- == '<span class="markdown prose dark:prose-invert"><h1 id="hello-world">Hello, World!</h1></span>' # noqa: E501
+ == '<span class="markdown prose dark:prose-invert contents"><h1 id="hello-world">Hello, World!</h1></span>' # noqa: E501
)
@@ -201,7 +201,7 @@ def test_repr_latex():
assert mime == "text/html"
assert (
content
- == '<span class="markdown prose dark:prose-invert"><span class="paragraph"><marimo-tex class="arithmatex">||(f(x) = e^x||)</marimo-tex></span></span>' # noqa: E501
+ == '<span class="markdown prose dark:prose-invert contents"><span class="paragraph"><marimo-tex class="arithmatex">||(f(x) = e^x||)</marimo-tex></span></span>' # noqa: E501
)
@@ -429,7 +429,7 @@ def test_repr_mimebundle_with_markdown():
mime, content = formatter(obj)
assert mime == "application/vnd.marimo+mimebundle"
assert content == {
- "text/html": '<span class="markdown prose dark:prose-invert"><h1 id="hello-world">Hello, World!</h1></span>',
+ "text/html": '<span class="markdown prose dark:prose-invert contents"><h1 id="hello-world">Hello, World!</h1></span>',
"text/markdown": "# Hello, World!",
}
@@ -465,7 +465,7 @@ def test_repr_mimebundle_with_latex():
mime, content = formatter(obj)
assert mime == "application/vnd.marimo+mimebundle"
assert content == {
- "text/html": '<span class="markdown prose dark:prose-invert"><span class="paragraph"><marimo-tex class="arithmatex">||(e^x||)</marimo-tex></span></span>',
+ "text/html": '<span class="markdown prose dark:prose-invert contents"><span class="paragraph"><marimo-tex class="arithmatex">||(e^x||)</marimo-tex></span></span>',
"text/latex": r"$e^x$",
}
@@ -670,7 +670,10 @@ def test_as_html_with_repr_markdown() -> None:
obj = CustomMarkdown()
result = as_html(obj)
- assert '<span class="markdown prose dark:prose-invert">' in result.text
+ assert (
+ '<span class="markdown prose dark:prose-invert contents">'
+ in result.text
+ )
assert '<h1 id="markdown-title">Markdown Title</h1>' in result.text
diff --git a/tests/_output/test_md.py b/tests/_output/test_md.py
index 9b38a3470e..5d2a7a10af 100644
--- a/tests/_output/test_md.py
+++ b/tests/_output/test_md.py
@@ -15,7 +15,7 @@ if TYPE_CHECKING:
def test_md() -> None:
# Test basic markdown conversion
input_text = "This is **bold** and this is _italic_."
- expected_output = '<span class="markdown prose dark:prose-invert"><span class="paragraph">This is <strong>bold</strong> and this is <em>italic</em>.</span></span>' # noqa: E501
+ expected_output = '<span class="markdown prose dark:prose-invert contents"><span class="paragraph">This is <strong>bold</strong> and this is <em>italic</em>.</span></span>' # noqa: E501
assert _md(input_text).text == expected_output
# Test disabling markdown class
@@ -28,7 +28,7 @@ def test_md() -> None:
# def test_md_size() -> None:
# input_text = "This is **bold** and this is _italic_."
-# expected_output = '<span class="markdown prose dark:prose-invert prose-lg"><span class="paragraph">This is <strong>bold</strong> and this is <em>italic</em>.</span></span>' # noqa: E501
+# expected_output = '<span class="markdown prose dark:prose-invert contents prose-lg"><span class="paragraph">This is <strong>bold</strong> and this is <em>italic</em>.</span></span>' # noqa: E501
# assert _md(input_text, size="lg").text == expected_output
@@ -456,7 +456,7 @@ def test_latex_via_path(output: MagicMock, tmp_path: Path) -> None:
latex(filename=filename)
assert (
output.append.call_args[0][0].text
- == '<span class="markdown prose dark:prose-invert"><marimo-tex class="arithmatex">||[\n\\newcommand{\\\x0coo}{bar}\n||]</marimo-tex></span>'
+ == '<span class="markdown prose dark:prose-invert contents"><marimo-tex class="arithmatex">||[\n\\newcommand{\\\x0coo}{bar}\n||]</marimo-tex></span>'
)
@@ -470,5 +470,5 @@ def test_latex_via_url(mock_urlopen: MagicMock, output: MagicMock) -> None:
latex(filename="https://example.com/macros.tex")
assert (
output.append.call_args[0][0].text
- == '<span class="markdown prose dark:prose-invert"><marimo-tex class="arithmatex">||[\n\\newcommand{\\\foo}{bar}\n||]</marimo-tex></span>'
+ == '<span class="markdown prose dark:prose-invert contents"><marimo-tex class="arithmatex">||[\n\\newcommand{\\\foo}{bar}\n||]</marimo-tex></span>'
)
diff --git a/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt b/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
index 9cb1400d7a..9c36303b29 100644
--- a/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
+++ b/tests/_server/export/snapshots/notebook_with_outputs.ipynb.txt
@@ -163,7 +163,7 @@
{
"data": {
"text/html": [
- "<div style='display: flex;flex: 1;flex-direction: column;justify-content: flex-start;align-items: normal;flex-wrap: nowrap;gap: 0.5rem'><span class=\"markdown prose dark:prose-invert\"><span class=\"paragraph\">hello</span></span><span class=\"markdown prose dark:prose-invert\"><span class=\"paragraph\">world</span></span></div>"
+ "<div style='display: flex;flex: 1;flex-direction: column;justify-content: flex-start;align-items: normal;flex-wrap: nowrap;gap: 0.5rem'><span class=\"markdown prose dark:prose-invert contents\"><span class=\"paragraph\">hello</span></span><span class=\"markdown prose dark:prose-invert contents\"><span class=\"paragraph\">world</span></span></div>"
]
},
"metadata": {},