@@ -329,14 +329,17 @@ private static void ProcessConsoleCodeBlock(
329329 // Check if this line is an HTTP verb (API call header)
330330 if ( IsHttpVerb ( lineText ) )
331331 {
332- // If we have a current segment with content, save it
333332 if ( ! string . IsNullOrEmpty ( currentSegment . Header ) || currentSegment . ContentLines . Count > 0 )
334333 codeBlock . ApiSegments . Add ( currentSegment ) ;
335334
336- // Start a new segment
335+ // Process callouts before creating the segment to capture them on the original line
336+ if ( codeBlockArgs . UseCallouts && codeBlock . OpeningFencedCharCount <= 3 )
337+ ProcessCalloutsForLine ( span , codeBlock , ref callOutIndex , originatingLine ) ;
338+
337339 currentSegment = new ApiSegment
338340 {
339- Header = lineText
341+ Header = lineText ,
342+ LineNumber = originatingLine
340343 } ;
341344
342345 // Clear this line from the content since it's now a header
@@ -345,14 +348,12 @@ private static void ProcessConsoleCodeBlock(
345348 }
346349 else
347350 {
348- // This is content for the current segment
349351 if ( ! string . IsNullOrEmpty ( lineText . Trim ( ) ) )
350352 currentSegment . ContentLines . Add ( lineText ) ;
351- }
352353
353- // Process callouts if enabled
354- if ( codeBlockArgs . UseCallouts && codeBlock . OpeningFencedCharCount <= 3 )
355- ProcessCalloutsForLine ( span , codeBlock , ref callOutIndex , originatingLine ) ;
354+ if ( codeBlockArgs . UseCallouts && codeBlock . OpeningFencedCharCount <= 3 )
355+ ProcessCalloutsForLine ( span , codeBlock , ref callOutIndex , originatingLine ) ;
356+ }
356357 }
357358
358359 // Add the last segment if it has content
@@ -413,12 +414,38 @@ private static void ProcessCalloutPostProcessing(StringLineGroup lines, Enhanced
413414 return acc ;
414415 } ) ;
415416
416- foreach ( var callout in callouts . Values )
417+ // Console code blocks use ApiSegments for rendering, so we need to update headers directly
418+ // Note: console language gets converted to "json" for syntax highlighting
419+ if ( ( codeBlock . Language == "json" || codeBlock . Language == "console" ) && codeBlock . ApiSegments . Count > 0 )
417420 {
418- var line = lines . Lines [ callout . Line - 1 ] ;
419- var newSpan = line . Slice . AsSpan ( ) [ ..callout . SliceStart ] ;
420- var s = new StringSlice ( newSpan . ToString ( ) ) ;
421- lines . Lines [ callout . Line - 1 ] = new StringLine ( ref s ) ;
421+ foreach ( var callout in callouts . Values )
422+ {
423+ foreach ( var segment in codeBlock . ApiSegments )
424+ {
425+ var calloutPattern = $ "<{ callout . Index } >";
426+ if ( segment . Header . Contains ( calloutPattern ) )
427+ {
428+ segment . Header = segment . Header . Replace ( calloutPattern , "" ) . Trim ( ) ;
429+ break ;
430+ }
431+ }
432+ }
433+ }
434+ else
435+ {
436+ foreach ( var callout in callouts . Values )
437+ {
438+ var line = lines . Lines [ callout . Line - 1 ] ;
439+ var span = line . Slice . AsSpan ( ) ;
440+
441+ // Skip callouts on cleared lines to avoid ArgumentOutOfRangeException
442+ if ( span . Length == 0 || callout . SliceStart >= span . Length )
443+ continue ;
444+
445+ var newSpan = span [ ..callout . SliceStart ] ;
446+ var s = new StringSlice ( newSpan . ToString ( ) ) ;
447+ lines . Lines [ callout . Line - 1 ] = new StringLine ( ref s ) ;
448+ }
422449 }
423450 }
424451 }
0 commit comments