@@ -130,10 +130,12 @@ public override bool Close(BlockProcessor processor, Block block)
130130 //update string slices to ignore call outs
131131 if ( codeBlock . CallOuts ? . Count > 0 )
132132 {
133- foreach ( var calloutLine in codeBlock . CallOuts . Select ( c => c . Line ) . ToHashSet ( ) )
133+ foreach ( var calloutLine in codeBlock . CallOuts . Select ( c => c . Line ) . Distinct ( ) )
134134 {
135135 var line = lines . Lines [ calloutLine - 1 ] ;
136136 var index = Math . Max ( line . Slice . AsSpan ( ) . IndexOf ( "//" ) , line . Slice . AsSpan ( ) . IndexOf ( '#' ) ) ;
137+ if ( index < 0 )
138+ continue ;
137139 var newSpan = line . Slice . AsSpan ( ) [ ..( index ) ] ;
138140 var s = new StringSlice ( newSpan . ToString ( ) ) ;
139141 lines . Lines [ calloutLine - 1 ] = new StringLine ( ref s ) ;
@@ -163,46 +165,71 @@ private static List<CallOut> EnumerateAnnotations(Regex.ValueMatchEnumerator mat
163165 if ( match . Length == 0 )
164166 continue ;
165167
166- var startIndex = span . LastIndexOf ( "<" ) ;
167- if ( ! inlineCodeAnnotation && startIndex <= 0 )
168- continue ;
169168 if ( inlineCodeAnnotation )
170169 {
171- startIndex = Math . Max ( span . LastIndexOf ( "//" ) , span . LastIndexOf ( '#' ) ) ;
172- if ( startIndex <= 0 )
173- continue ;
170+ var callOut = ParseMagicCallout ( match , ref span , ref callOutIndex , originatingLine ) ;
171+ if ( callOut != null )
172+ return [ callOut ] ;
173+ continue ;
174174 }
175175
176- callOutIndex ++ ;
176+ var classicCallOuts = ParseClassicCallOuts ( match , ref span , ref callOutIndex , originatingLine ) ;
177+ callOuts . AddRange ( classicCallOuts ) ;
178+ }
177179
178- var allStartIndices = new List < int > ( ) ;
179- for ( var i = 0 ; i < span . Length ; i ++ )
180- {
181- if ( span [ i ] == '<' ) allStartIndices . Add ( i ) ;
182- }
180+ return callOuts ;
181+ }
182+
183+ private static CallOut ? ParseMagicCallout ( ValueMatch match , ref ReadOnlySpan < char > span , ref int callOutIndex , int originatingLine )
184+ {
185+ var startIndex = Math . Max ( span . LastIndexOf ( "//" ) , span . LastIndexOf ( '#' ) ) ;
186+ if ( startIndex <= 0 )
187+ return null ;
188+
189+ callOutIndex ++ ;
190+ var callout = span . Slice ( match . Index + startIndex , match . Length - startIndex ) ;
183191
184- foreach ( var individualStartIndex in allStartIndices )
192+ return new CallOut
193+ {
194+ Index = callOutIndex ,
195+ Text = callout . TrimStart ( '/' ) . TrimStart ( '#' ) . TrimStart ( ) . ToString ( ) ,
196+ InlineCodeAnnotation = true ,
197+ SliceStart = startIndex ,
198+ Line = originatingLine ,
199+ } ;
200+ }
201+
202+ private static List < CallOut > ParseClassicCallOuts ( ValueMatch match , ref ReadOnlySpan < char > span , ref int callOutIndex , int originatingLine )
203+ {
204+ var startIndex = span . LastIndexOf ( "<" ) ;
205+ if ( startIndex <= 0 )
206+ return [ ] ;
207+
208+ callOutIndex ++ ;
209+
210+ var allStartIndices = new List < int > ( ) ;
211+ for ( var i = 0 ; i < span . Length ; i ++ )
212+ {
213+ if ( span [ i ] == '<' )
214+ allStartIndices . Add ( i ) ;
215+ }
216+
217+ var callOuts = new List < CallOut > ( ) ;
218+ foreach ( var individualStartIndex in allStartIndices )
219+ {
220+ var endIndex = span . Slice ( match . Index + individualStartIndex ) . IndexOf ( '>' ) + 1 ;
221+ var callout = span . Slice ( match . Index + individualStartIndex , endIndex ) ;
222+ _ = int . TryParse ( callout . Trim ( [ '<' , '>' ] ) , out var index ) ;
223+ callOuts . Add ( new CallOut
185224 {
186- var endIndex = span . Slice ( match . Index + individualStartIndex ) . IndexOf ( '>' ) + 1 ;
187- var callout = span . Slice ( match . Index + individualStartIndex , endIndex ) ;
188- var index = callOutIndex ;
189- if ( ! inlineCodeAnnotation && int . TryParse ( callout . Trim ( [ '<' , '>' ] ) , out index ) )
190- {
191-
192- }
193-
194- callOuts . Add ( new CallOut
195- {
196- Index = index ,
197- Text = callout . TrimStart ( '/' ) . TrimStart ( '#' ) . TrimStart ( ) . ToString ( ) ,
198- InlineCodeAnnotation = inlineCodeAnnotation ,
199- SliceStart = individualStartIndex ,
200- Line = originatingLine ,
201- } ) ;
202- }
225+ Index = index ,
226+ Text = callout . TrimStart ( '/' ) . TrimStart ( '#' ) . TrimStart ( ) . ToString ( ) ,
227+ InlineCodeAnnotation = false ,
228+ SliceStart = individualStartIndex ,
229+ Line = originatingLine ,
230+ } ) ;
203231 }
204232
205233 return callOuts ;
206234 }
207235}
208-
0 commit comments