Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion marimo/_ast/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = name
Expand Down
5 changes: 4 additions & 1 deletion marimo/_convert/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions tests/_ast/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ def test_generate_unparsable_cell_with_await() -> None:
# leading 4 spaces followed by nothing
assert 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

@staticmethod
def test_long_line_in_main() -> None:
cell_one = "\n".join(
Expand Down
47 changes: 46 additions & 1 deletion tests/_convert/test_convert_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ def test_markdown_to_marimo():
assert utils.markdown_to_marimo(markdown) == expected

markdown = '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

Expand All @@ -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 sources
sources = ["print('Hello')", "x = 5"]
Expand Down Expand Up @@ -92,3 +110,30 @@ def _():
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
)
Loading