@@ -41,6 +41,7 @@ class MathBlock:
41
41
metadata : Dict [str , Any ] = field (default_factory = dict )
42
42
children : List ["MathBlock" ] = field (default_factory = list )
43
43
parent : Optional ["MathBlock" ] = None
44
+ content_html : Optional [str ] = None # Stores the inner HTML content (without wrapper)
44
45
45
46
@property
46
47
def css_class (self ) -> str :
@@ -422,8 +423,8 @@ def render_block_html(
422
423
# Render child blocks that are referenced in the content
423
424
for marker_id , child_block in block_markers .items ():
424
425
if child_block .parent == block and marker_id in processed_content :
425
- # Render the child block
426
- child_html = self . _render_child_block ( child_block , block_markers , md_processor )
426
+ # Child blocks are always processed first, so rendered_html is available
427
+ child_html = child_block . rendered_html
427
428
# Replace marker with rendered child
428
429
processed_content = processed_content .replace (f"<p>{ marker_id } </p>" , child_html )
429
430
processed_content = processed_content .replace (marker_id , child_html )
@@ -441,41 +442,6 @@ def render_block_html(
441
442
442
443
return "\n " .join (html_parts )
443
444
444
- def _render_child_block (
445
- self , block : MathBlock , block_markers : Dict [str , MathBlock ], md_processor
446
- ) -> str :
447
- """Render a child block with its content."""
448
- # Process the block's content through markdown
449
- block_content = block .content
450
-
451
- # Process cross-references using the unified processor (first pass)
452
- block_ref_processor = BlockReferenceProcessor (
453
- block_markers = block_markers ,
454
- current_file = self .current_file ,
455
- block_index = self .block_index ,
456
- )
457
- block_content = block_ref_processor .process_references (block_content )
458
-
459
- # Protect math before markdown processing
460
- child_math_protector = MathProtector (prefix = "CHILDMATH" )
461
- block_content = child_math_protector .protect_math (block_content )
462
-
463
- # Process through markdown
464
- block_html = md_processor .convert (block_content )
465
- md_processor .reset ()
466
-
467
- # Restore math
468
- block_html = child_math_protector .restore_math (block_html )
469
-
470
- # Process embedded blocks after markdown conversion (second pass)
471
- if block_ref_processor .embedded_blocks :
472
- block_html = block_ref_processor .process_embedded_blocks (block_html , md_processor )
473
-
474
- # Render the block with nested support
475
- # For child blocks on the same page, use #label as URL
476
- url = f"#{ block .label } " if block .label else None
477
- return self .render_block_html (block , block_html , block_markers , md_processor , url )
478
-
479
445
def get_blocks_by_type (self , block_type : MathBlockType ) -> List [MathBlock ]:
480
446
"""Get all blocks of a specific type."""
481
447
return [block for block in self .blocks if block .block_type == block_type ]
0 commit comments