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: handle backslashes in md (marimo convert) (#424)

Akshay Agrawalb3b9c5146414
diff --git a/marimo/_cli/ipynb_to_marimo.py b/marimo/_cli/ipynb_to_marimo.py
index 4c05cd3470..6da1ff366a 100644
--- a/marimo/_cli/ipynb_to_marimo.py
+++ b/marimo/_cli/ipynb_to_marimo.py
@@ -33,7 +33,8 @@ def convert(ipynb_path: str) -> str:
source = "\n".join(
[
"mo.md(",
- codegen.indent_text('"""'),
+ # r-string: a backslash is just a backslash!
+ codegen.indent_text('r"""'),
codegen.indent_text(source),
codegen.indent_text('"""'),
")",
diff --git a/marimo/_cli/test_ipynb_to_marimo.py b/marimo/_cli/test_ipynb_to_marimo.py
index 128419c543..e5d0ea06b5 100644
--- a/marimo/_cli/test_ipynb_to_marimo.py
+++ b/marimo/_cli/test_ipynb_to_marimo.py
@@ -43,7 +43,7 @@ def test_markdown() -> None:
== textwrap.dedent(
"""
mo.md(
- \"\"\"
+ r\"\"\"
# Hello, markdown
\\"\\"\\"
@@ -60,10 +60,10 @@ def test_markdown() -> None:
== textwrap.dedent(
"""
mo.md(
- \"\"\"
+ r\"\"\"
Here is some math
- $x = 0$
+ $x \\approx 0$
\"\"\"
)
"""
diff --git a/marimo/_plugins/ui/_impl/utils/dataframe.py b/marimo/_plugins/ui/_impl/utils/dataframe.py
index 43e5eca30f..914c7326c7 100644
--- a/marimo/_plugins/ui/_impl/utils/dataframe.py
+++ b/marimo/_plugins/ui/_impl/utils/dataframe.py
@@ -74,6 +74,6 @@ def _get_row_headers_for_index(
or dtype == "category"
):
name = str(index.name) if index.name else ""
- return [(name, index.tolist())] # type: ignore[list-item]
+ return [(name, index.tolist())] # type: ignore[list-item]
return []
diff --git a/marimo/_test_utils/ipynb_data/markdown.ipynb.txt b/marimo/_test_utils/ipynb_data/markdown.ipynb.txt
index 92b228ae67..00cb5c9de5 100644
--- a/marimo/_test_utils/ipynb_data/markdown.ipynb.txt
+++ b/marimo/_test_utils/ipynb_data/markdown.ipynb.txt
@@ -20,7 +20,7 @@
"source": [
"Here is some math\n",
"\n",
- "$x = 0$"
+ "$x \\approx 0$"
]
}
],