@@ -76,8 +76,18 @@ def process_notebook(notebook_path, output_path,
7676 # command is present
7777 continue
7878
79+ # Check for analyze-only command before processing headers
80+ analyze_only = any ([True for e in parsed_md .elements \
81+ if isinstance (e , MarkdownCommand ) \
82+ and e .type == MarkdownCommandType .ANALYZE_ONLY ])
83+
7984 for md_element in parsed_md .elements :
8085 if isinstance (md_element , MarkdownHeader ):
86+ # Skip header processing; we're only analyzing the cell
87+ # i.e. do not create a file/folder for it
88+ if analyze_only :
89+ continue
90+
8191 # handle MarkdownHeader
8292 header = md_element
8393 header_name = __sanitize_node_name (header .name )
@@ -230,6 +240,10 @@ def __handle_markdown_command(command, current_node, node_stack):
230240 # this is handled externally to avoid the processing cost
231241 pass
232242
243+ elif command .type == MarkdownCommandType .ANALYZE_ONLY :
244+ # Mark the current node to be analyzed but not written to a file
245+ current_node .analyze_only = True
246+
233247 # NODE-MANIPULATION COMMANDS
234248 elif command .type == MarkdownCommandType .RENAME_PACKAGE :
235249 # override the current node's name + assert package type
@@ -260,20 +274,57 @@ def __handle_markdown_command(command, current_node, node_stack):
260274 # create a new node and assert its node type to module
261275 node_name = __sanitize_node_name (command .value )
262276
263- new_node_parent = current_node
264-
265- # default to sibling-level if we're not at root level
266- if current_node .parent is not None :
267- node_stack .pop ()
268- new_node_parent = current_node .parent
269-
270- new_node = ModuleNode (node_name , new_node_parent ,
271- depth = new_node_parent .depth + 1 )
272-
273- new_node .node_type = 'module'
274- new_node_parent .add_child (new_node )
275-
276- node_stack .append (new_node )
277+ # If we're in a package context, the module should be created inside that package
278+ if current_node .node_type == 'package' :
279+ # Create module inside the current package
280+ new_node = ModuleNode (node_name , current_node ,
281+ depth = current_node .depth + 1 )
282+ new_node .node_type = 'module'
283+ current_node .add_child (new_node )
284+ node_stack .append (new_node )
285+ else :
286+ # Check if this should be a package structure (contains . or /)
287+ if '.' in node_name or '/' in node_name :
288+ # Split into package/module parts
289+ parts = node_name .replace ('/' , '.' ).split ('.' )
290+ module_name = parts [- 1 ]
291+ package_parts = parts [:- 1 ]
292+
293+ # Start from current node's parent if we're not at root
294+ new_node_parent = current_node
295+ if current_node .parent is not None :
296+ node_stack .pop ()
297+ new_node_parent = current_node .parent
298+
299+ # Create package structure
300+ for package_part in package_parts :
301+ package_node = ModuleNode (package_part , new_node_parent ,
302+ depth = new_node_parent .depth + 1 )
303+ package_node .node_type = 'package'
304+ new_node_parent .add_child (package_node )
305+ new_node_parent = package_node
306+ node_stack .append (package_node )
307+
308+ # Create the actual module at the leaf
309+ new_node = ModuleNode (module_name , new_node_parent ,
310+ depth = new_node_parent .depth + 1 )
311+ new_node .node_type = 'module'
312+ new_node_parent .add_child (new_node )
313+ node_stack .append (new_node )
314+ else :
315+ new_node_parent = current_node
316+
317+ # default to sibling-level if we're not at root level
318+ if current_node .parent is not None :
319+ node_stack .pop ()
320+ new_node_parent = current_node .parent
321+
322+ new_node = ModuleNode (node_name , new_node_parent ,
323+ depth = new_node_parent .depth + 1 )
324+
325+ new_node .node_type = 'module'
326+ new_node_parent .add_child (new_node )
327+ node_stack .append (new_node )
277328
278329 elif command .type == MarkdownCommandType .DECLARE_NODE :
279330 # create a new generic node (type will be automatically inferred)
0 commit comments