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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: jupytext convert with markdown with quotes (#6789)
Myles Scolnickc0ad4792f40d
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.pyindex 9d997725dc..550d3a9d5f 100644--- a/marimo/_ast/codegen.py+++ b/marimo/_ast/codegen.py@@ -300,7 +300,7 @@ def generate_unparsable_cell(flags = {}if config != CellConfig():- flags = dict(config.__dict__)+ flags = config.asdict()if name is not None:flags["name"] = namediff --git a/marimo/_convert/utils.py b/marimo/_convert/utils.pyindex 781370f95a..06b93f5276 100644--- a/marimo/_convert/utils.py+++ b/marimo/_convert/utils.py@@ -14,7 +14,10 @@ def markdown_to_marimo(source: str) -> str:if not source:source = " "- if "\n" not in source:+ # If quotes are on either side, we need to use the multiline format.+ bounded_by_quotes = source.startswith('"') or source.endswith('"')++ if "\n" not in source and not bounded_by_quotes:return f'mo.md(r"""{source}""")'return "\n".join(diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.pyindex 9e858d0a43..0d4f42b566 100644--- a/tests/_ast/test_codegen.py+++ b/tests/_ast/test_codegen.py@@ -225,6 +225,20 @@ class TestGeneration:# leading 4 spaces followed by nothingassert stringified[3] == " " * 4+ @staticmethod+ def test_generate_unparsable_cell_with_config() -> None:+ """Test that generate_unparsable_cell works with non-default CellConfig."""+ code = 'mo.md("markdown in marimo")'+ config = CellConfig(hide_code=True)++ # This should not raise AttributeError+ raw = codegen.generate_unparsable_cell(code, None, config)++ # Verify the config is included in the output+ assert "hide_code=True" in raw+ # Verify the code is properly escaped and included+ assert 'mo.md(\\"markdown in marimo\\")' in raw+@staticmethoddef test_long_line_in_main() -> None:cell_one = "\n".join(diff --git a/tests/_convert/test_convert_utils.py b/tests/_convert/test_convert_utils.pyindex d716a67503..1f21239b65 100644--- a/tests/_convert/test_convert_utils.py+++ b/tests/_convert/test_convert_utils.py@@ -14,7 +14,12 @@ def test_markdown_to_marimo():assert utils.markdown_to_marimo(markdown) == expectedmarkdown = 'Here are some quotes: """'- expected = r'mo.md(r"""Here are some quotes: \"\"\"""")'+ expected = r'''+mo.md(+ r"""+Here are some quotes: \"\"\"+"""+)'''.strip()assert utils.markdown_to_marimo(markdown) == expected@@ -23,6 +28,19 @@ def test_markdown_to_marimo():assert utils.markdown_to_marimo(markdown) == expected+def test_markdown_to_marimo_with_quotes():+ markdown = '"this is markdown"'+ expected = (+ '''\+mo.md(+ r"""+"this is markdown"+"""+)'''+ ).strip()+ assert utils.markdown_to_marimo(markdown) == expected++def test_generate_from_sources():# Test with basic sourcessources = ["print('Hello')", "x = 5"]@@ -92,3 +110,30 @@ if __name__ == "__main__":app.run()""".lstrip())+++def test_markdown_with_quotes_and_cell_configs():+ """Test that markdown ending in double quotes works with cell configs.++ Regression test for issue #6741 where markdown cells ending in double+ quotes failed to convert when cell configs were non-default.+ """+ # Simulate a markdown cell ending in double quotes that can't be parsed+ markdown_code = 'mo.md("Marimo is the best")'+ sources = [markdown_code]+ cell_configs = [CellConfig(hide_code=True)]++ # This should not raise AttributeError+ result = codegen.generate_filecontents(+ codes=sources,+ names=["_"],+ cell_configs=cell_configs,+ )++ # Verify the result contains the expected config+ assert "hide_code=True" in result+ # Verify the markdown content is properly escaped+ assert (+ r"mo.md(\"Marimo is the best\")" in result+ or "Marimo is the best" in result+ )