diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py index 9d997725dc7..451f82833bc 100644 --- a/marimo/_ast/codegen.py +++ b/marimo/_ast/codegen.py @@ -67,7 +67,12 @@ def pop_setup_cell( def indent_text(text: str) -> str: - return textwrap.indent(text, INDENT) + if not text: + return "" + lines = text.splitlines(keepends=True) + return "".join( + (INDENT + line if line.strip() != "" else line) for line in lines + ) def _format_arg(arg: Any) -> str: