@@ -30,56 +30,51 @@ public HtmlString RenderBlock()
3030 return new HtmlString ( result ) ;
3131 }
3232
33- public HtmlString RenderConsoleCallouts ( int lineNumber )
33+ public HtmlString RenderLineWithCallouts ( string content , int lineNumber )
3434 {
3535 if ( EnhancedCodeBlock ? . CallOuts == null )
36- return HtmlString . Empty ;
36+ return new HtmlString ( content ) ;
3737
3838 var callouts = EnhancedCodeBlock . CallOuts . Where ( c => c . Line == lineNumber ) ;
3939 if ( ! callouts . Any ( ) )
40- return HtmlString . Empty ;
40+ return new HtmlString ( content ) ;
4141
42+ var line = content ;
4243 var html = new System . Text . StringBuilder ( ) ;
44+
45+ // Remove callout markers from the line
46+ foreach ( var callout in callouts )
47+ {
48+ var calloutPattern = $ "<{ callout . Index } >";
49+ line = line . Replace ( calloutPattern , "" ) ;
50+ }
51+ line = line . TrimEnd ( ) ;
52+
53+ _ = html . Append ( line ) ;
54+
55+ // Add callout HTML after the line
4356 foreach ( var callout in callouts )
4457 {
4558 _ = html . Append ( $ "<span class=\" code-callout\" data-index=\" { callout . Index } \" ></span>") ;
4659 }
60+
4761 return new HtmlString ( html . ToString ( ) ) ;
4862 }
4963
5064 public HtmlString RenderContentLinesWithCallouts ( List < ( string Content , int LineNumber ) > contentLinesWithNumbers )
5165 {
52- if ( EnhancedCodeBlock ? . CallOuts == null || contentLinesWithNumbers . Count == 0 )
53- return new HtmlString ( string . Join ( " \n " , contentLinesWithNumbers . Select ( c => c . Content ) ) ) ;
66+ if ( contentLinesWithNumbers . Count == 0 )
67+ return HtmlString . Empty ;
5468
5569 var html = new System . Text . StringBuilder ( ) ;
5670 for ( var i = 0 ; i < contentLinesWithNumbers . Count ; i ++ )
5771 {
5872 var ( content , lineNumber ) = contentLinesWithNumbers [ i ] ;
59- var line = content ;
60-
61- // Find callouts for this line
62- var callouts = EnhancedCodeBlock . CallOuts . Where ( c => c . Line == lineNumber ) ;
63- if ( callouts . Any ( ) )
64- {
65- // Remove callout markers from the line
66- foreach ( var callout in callouts )
67- {
68- var calloutPattern = $ "<{ callout . Index } >";
69- line = line . Replace ( calloutPattern , "" ) ;
70- }
71- line = line . TrimEnd ( ) ;
72- }
7373
7474 if ( i > 0 )
7575 _ = html . Append ( '\n ' ) ;
76- _ = html . Append ( line ) ;
7776
78- // Add callout HTML after the line
79- foreach ( var callout in callouts )
80- {
81- _ = html . Append ( $ "<span class=\" code-callout\" data-index=\" { callout . Index } \" ></span>") ;
82- }
77+ _ = html . Append ( RenderLineWithCallouts ( content , lineNumber ) ) ;
8378 }
8479 return new HtmlString ( html . ToString ( ) ) ;
8580 }
0 commit comments