1414from marimo ._ast .transformers import NameTransformer , RemoveImportTransformer
1515from marimo ._ast .variables import is_local
1616from marimo ._ast .visitor import Block , NamedNode , ScopedVisitor
17+ from marimo ._convert .comment_preserver import CommentPreserver
1718from marimo ._convert .utils import markdown_to_marimo
1819from marimo ._runtime .dataflow import DirectedGraph
1920from marimo ._schemas .serialization import (
@@ -709,7 +710,10 @@ def extract_inline_meta(script: str) -> tuple[str | None, str]:
709710
710711
711712def _transform_sources (
712- sources : list [str ], metadata : list [dict [str , Any ]], hide_flags : list [bool ]
713+ sources : list [str ],
714+ metadata : list [dict [str , Any ]],
715+ hide_flags : list [bool ],
716+ fix : bool = True ,
713717) -> list [CodeCell ]:
714718 """
715719 Process raw sources and metadata into finalized cells.
@@ -721,7 +725,6 @@ def _transform_sources(
721725
722726 After this step, cells are ready for execution or rendering.
723727 """
724- from marimo ._convert .comment_preserver import CommentPreserver
725728
726729 # Define transforms that don't need comment preservation
727730 simple_transforms = [
@@ -730,13 +733,6 @@ def _transform_sources(
730733 transform_exclamation_mark ,
731734 ]
732735
733- # Define transforms that should preserve comments
734- comment_preserving_transforms = [
735- transform_remove_duplicate_imports ,
736- transform_fixup_multiple_definitions ,
737- transform_duplicate_definitions ,
738- ]
739-
740736 # Run simple transforms first (no comment preservation needed)
741737 for source_transform in simple_transforms :
742738 new_sources = source_transform (sources )
@@ -745,6 +741,16 @@ def _transform_sources(
745741 )
746742 sources = new_sources
747743
744+ if not fix :
745+ return bind_cell_metadata (sources , metadata , hide_flags )
746+
747+ # Define transforms that should preserve comments
748+ comment_preserving_transforms = [
749+ transform_remove_duplicate_imports ,
750+ transform_fixup_multiple_definitions ,
751+ transform_duplicate_definitions ,
752+ ]
753+
748754 # Create comment preserver from the simplified sources
749755 comment_preserver = CommentPreserver (sources )
750756
@@ -773,6 +779,7 @@ def _transform_sources(
773779
774780def convert_from_ipynb_to_notebook_ir (
775781 raw_notebook : str ,
782+ fix : bool = True ,
776783) -> NotebookSerializationV1 :
777784 """
778785 Convert a raw notebook to a NotebookSerializationV1 object.
@@ -801,7 +808,9 @@ def convert_from_ipynb_to_notebook_ir(
801808 metadata .append (cell .get ("metadata" , {}))
802809 hide_flags .append (is_markdown )
803810
804- transformed_cells = _transform_sources (sources , metadata , hide_flags )
811+ transformed_cells = _transform_sources (
812+ sources , metadata , hide_flags , fix = fix
813+ )
805814
806815 return NotebookSerializationV1 (
807816 app = AppInstantiation (),
0 commit comments