@@ -23,11 +23,11 @@ public static class LlmRenderingHelpers
2323{
2424 public static void RenderBlockWithIndentation ( LlmMarkdownRenderer renderer , MarkdownObject block , string indentation = " " )
2525 {
26- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
27- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
28- var tempRenderer = subscription . LlmMarkdownRenderer ;
29- _ = tempRenderer . Render ( block ) ;
30- var content = subscription . RentedStringBuilder ! . ToString ( ) ;
26+ var content = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
27+ {
28+ _ = tempRenderer . Render ( block ) ;
29+ } ) ;
30+
3131 if ( string . IsNullOrEmpty ( content ) )
3232 return ;
3333 var lines = content . Split ( [ '\n ' , '\r ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -36,7 +36,6 @@ public static void RenderBlockWithIndentation(LlmMarkdownRenderer renderer, Mark
3636 renderer . Write ( indentation ) ;
3737 renderer . WriteLine ( line ) ;
3838 }
39- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
4039 }
4140
4241 /// <summary>
@@ -46,7 +45,7 @@ public static void RenderBlockWithIndentation(LlmMarkdownRenderer renderer, Mark
4645 {
4746 if (
4847 string . IsNullOrEmpty ( url )
49- || renderer . BuildContext ! . CanonicalBaseUrl == null
48+ || renderer . BuildContext . CanonicalBaseUrl == null
5049 || Uri . IsWellFormedUriString ( url , UriKind . Absolute )
5150 || ! Uri . IsWellFormedUriString ( url , UriKind . Relative ) )
5251 return url ;
@@ -191,11 +190,10 @@ private static string GetContinuationIndent(string baseIndent, bool isOrdered) =
191190
192191 private static void RenderBlockWithIndentation ( LlmMarkdownRenderer renderer , Block block , string baseIndent , bool isOrdered )
193192 {
194- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
195- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
196- var tempRenderer = subscription . LlmMarkdownRenderer ;
197- _ = tempRenderer . Render ( block ) ;
198- var blockOutput = subscription . RentedStringBuilder ! . ToString ( ) ;
193+ var blockOutput = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
194+ {
195+ _ = tempRenderer . Render ( block ) ;
196+ } ) ;
199197
200198 var continuationIndent = GetContinuationIndent ( baseIndent , isOrdered ) ;
201199 var lines = blockOutput . Split ( '\n ' ) ;
@@ -213,7 +211,6 @@ private static void RenderBlockWithIndentation(LlmMarkdownRenderer renderer, Blo
213211 else if ( i < lines . Length - 1 )
214212 renderer . WriteLine ( ) ;
215213 }
216- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
217214 }
218215
219216 /// <summary>
@@ -290,19 +287,19 @@ protected override void Write(LlmMarkdownRenderer renderer, Table table)
290287 renderer . Writer . Write ( " " ) ;
291288
292289 // Capture cell content
293- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
294- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
295- var tempRenderer = subscription . LlmMarkdownRenderer ;
296- // Render cell content to temporary writer
297- foreach ( var inline in cell . Descendants ( ) . OfType < Inline > ( ) )
298- tempRenderer . Write ( inline ) ;
290+ var content = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
291+ {
292+ // Render cell content to temporary writer
293+ foreach ( var inline in cell . Descendants ( ) . OfType < Inline > ( ) )
294+ {
295+ tempRenderer . Write ( inline ) ;
296+ }
297+ } ) ;
299298
300299 // Write padded content
301- var content = subscription . RentedStringBuilder ! . ToString ( ) ;
302300 renderer . Writer . Write ( content . PadRight ( columnWidths [ cellIndex ] ) ) ;
303301 renderer . Writer . Write ( " |" ) ;
304302 cellIndex ++ ;
305- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
306303 }
307304
308305 renderer . WriteLine ( ) ;
@@ -328,19 +325,19 @@ protected override void Write(LlmMarkdownRenderer renderer, Table table)
328325 renderer . Writer . Write ( " " ) ;
329326
330327 // Capture cell content
331- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
332- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
333- var tempRenderer = subscription . LlmMarkdownRenderer ;
334- // Render cell content to temporary writer
335- foreach ( var inline in cell . Descendants ( ) . OfType < Inline > ( ) )
336- tempRenderer . Write ( inline ) ;
328+ var content = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
329+ {
330+ // Render cell content to temporary writer
331+ foreach ( var inline in cell . Descendants ( ) . OfType < Inline > ( ) )
332+ {
333+ tempRenderer . Write ( inline ) ;
334+ }
335+ } ) ;
337336
338337 // Write padded content
339- var content = subscription . RentedStringBuilder ! . ToString ( ) ;
340338 renderer . Writer . Write ( content . PadRight ( columnWidths [ cellIndex ] ) ) ;
341339 renderer . Writer . Write ( " |" ) ;
342340 cellIndex ++ ;
343- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
344341 }
345342
346343 renderer . WriteLine ( ) ;
@@ -367,20 +364,18 @@ private static int[] CalculateColumnWidths(LlmMarkdownRenderer renderer, Table t
367364 foreach ( var cell in row . Cast < TableCell > ( ) )
368365 {
369366 // Capture cell content
370- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
371- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
372- var tempRenderer = subscription . LlmMarkdownRenderer ;
373- // Render cell content to temporary writer
374- foreach ( var inline in cell . Descendants ( ) . OfType < Inline > ( ) )
367+ var content = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
375368 {
376- tempRenderer . Write ( inline ) ;
377- }
369+ // Render cell content to temporary writer
370+ foreach ( var inline in cell . Descendants ( ) . OfType < Inline > ( ) )
371+ {
372+ tempRenderer . Write ( inline ) ;
373+ }
374+ } ) ;
378375
379376 // Update width if this cell is wider
380- var content = subscription . RentedStringBuilder ! . ToString ( ) ;
381377 widths [ cellIndex ] = Math . Max ( widths [ cellIndex ] , content . Length ) ;
382378 cellIndex ++ ;
383- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
384379 }
385380 }
386381
@@ -450,7 +445,7 @@ private void WriteIncludeBlock(LlmMarkdownRenderer renderer, IncludeBlock block)
450445 {
451446 if ( ! block . Found || block . IncludePath is null )
452447 {
453- renderer . BuildContext ! . Collector . EmitError ( block . IncludePath ?? string . Empty , "File not found or invalid path" ) ;
448+ renderer . BuildContext . Collector . EmitError ( block . IncludePath ?? string . Empty , "File not found or invalid path" ) ;
454449 return ;
455450 }
456451
@@ -460,7 +455,7 @@ private void WriteIncludeBlock(LlmMarkdownRenderer renderer, IncludeBlock block)
460455 var snippet = block . Build . ReadFileSystem . FileInfo . New ( block . IncludePath ) ;
461456 if ( ! snippet . Exists )
462457 {
463- renderer . BuildContext ! . Collector . EmitError ( block . IncludePath ?? string . Empty , "File not found or invalid path" ) ;
458+ renderer . BuildContext . Collector . EmitError ( block . IncludePath ?? string . Empty , "File not found or invalid path" ) ;
464459 return ;
465460 }
466461
@@ -489,7 +484,7 @@ private void WriteIncludeBlock(LlmMarkdownRenderer renderer, IncludeBlock block)
489484 }
490485 catch ( Exception ex )
491486 {
492- renderer . BuildContext ! . Collector . EmitError ( block . IncludePath ?? string . Empty , "Failed to parse included content" , ex ) ;
487+ renderer . BuildContext . Collector . EmitError ( block . IncludePath ?? string . Empty , "Failed to parse included content" , ex ) ;
493488 }
494489 }
495490
@@ -499,25 +494,24 @@ private void WriteIncludeBlock(LlmMarkdownRenderer renderer, IncludeBlock block)
499494 private static void WriteChildrenWithIndentation ( LlmMarkdownRenderer renderer , Block container , string indent )
500495 {
501496 // Capture output and manually add indentation
502- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
503- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
504- var tempRenderer = subscription . LlmMarkdownRenderer ;
505- switch ( container )
497+ var content = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
506498 {
507- case ContainerBlock containerBlock :
508- tempRenderer . WriteChildren ( containerBlock ) ;
509- break ;
510- case LeafBlock leafBlock :
511- tempRenderer . WriteLeafInline ( leafBlock ) ;
512- break ;
513- }
514- var content = subscription . RentedStringBuilder ! . ToString ( ) ;
499+ switch ( container )
500+ {
501+ case ContainerBlock containerBlock :
502+ tempRenderer . WriteChildren ( containerBlock ) ;
503+ break ;
504+ case LeafBlock leafBlock :
505+ tempRenderer . WriteLeafInline ( leafBlock ) ;
506+ break ;
507+ }
508+ } ) ;
509+
515510 if ( string . IsNullOrEmpty ( content ) )
516511 return ;
517512 var reader = new StringReader ( content ) ;
518513 while ( reader . ReadLine ( ) is { } line )
519514 renderer . WriteLine ( string . IsNullOrWhiteSpace ( line ) ? string . Empty : indent + line ) ;
520- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
521515 }
522516}
523517
@@ -544,12 +538,11 @@ protected override void Write(LlmMarkdownRenderer renderer, DefinitionItem obj)
544538
545539 private static string GetPlainTextFromLeafBlock ( LlmMarkdownRenderer renderer , LeafBlock leafBlock )
546540 {
547- var subscription = DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Get ( ) ;
548- subscription . SetBuildContext ( renderer . BuildContext ! ) ;
549- var tempRenderer = subscription . LlmMarkdownRenderer ;
550- tempRenderer . WriteLeafInline ( leafBlock ) ;
551- var markdownText = subscription . RentedStringBuilder ! . ToString ( ) ;
552- DocumentationObjectPoolProvider . LlmMarkdownRendererPool . Return ( subscription ) ;
541+ var markdownText = DocumentationObjectPoolProvider . UseLlmMarkdownRenderer ( renderer . BuildContext , tempRenderer =>
542+ {
543+ tempRenderer . WriteLeafInline ( leafBlock ) ;
544+ } ) ;
545+
553546 return markdownText . StripMarkdown ( ) ;
554547 }
555548}
0 commit comments