@@ -21,12 +21,21 @@ public class LLMTextExporter : IMarkdownExporter
2121
2222 public async ValueTask < bool > ExportAsync ( MarkdownExportContext context , Cancel ctx )
2323 {
24- var source = context . File . SourceFile ;
24+ var source = context . SourceFile . SourceFile ;
2525 var fs = source . FileSystem ;
26- var llmText = context . LLMText ??= ToLLMText ( context . BuildContext , context . File . YamlFrontMatter , context . Resolvers , source ) ;
26+ var llmText = context . LLMText ??= ToLLMText ( context . BuildContext , context . SourceFile . YamlFrontMatter , context . Resolvers , source ) ;
2727
28- var newFile = fs . FileInfo . New ( Path . ChangeExtension ( source . FullName , ".md" ) ) ;
29- await fs . File . WriteAllTextAsync ( newFile . FullName , llmText , ctx ) ;
28+ // write to the output version of the Markdown file directly
29+ var outputFile = context . DefaultOutputFile ;
30+ if ( outputFile . Name == "index.md" )
31+ {
32+ // Write to a file named after the parent folder
33+ outputFile = fs . FileInfo . New ( outputFile . Directory ! . FullName + ".md" ) ;
34+ }
35+ if ( outputFile . Directory is { Exists : false } )
36+ outputFile . Directory . Create ( ) ;
37+
38+ await fs . File . WriteAllTextAsync ( outputFile . FullName , llmText , ctx ) ;
3039 return true ;
3140 }
3241
@@ -35,7 +44,7 @@ public static string ToLLMText(BuildContext buildContext, YamlFrontMatter? front
3544 var fs = source . FileSystem ;
3645 var sb = DocumentationObjectPoolProvider . StringBuilderPool . Get ( ) ;
3746
38- Read ( source , fs , sb ) ;
47+ Read ( source , fs , sb , buildContext . DocumentationSourceDirectory ) ;
3948 var full = sb . ToString ( ) ;
4049 var state = new ParserState ( buildContext )
4150 {
@@ -50,7 +59,7 @@ public static string ToLLMText(BuildContext buildContext, YamlFrontMatter? front
5059
5160 }
5261
53- private static void Read ( IFileInfo source , IFileSystem fs , StringBuilder sb , int depth = 0 )
62+ private static void Read ( IFileInfo source , IFileSystem fs , StringBuilder sb , IDirectoryInfo setDirectory )
5463 {
5564 var text = fs . File . ReadAllText ( source . FullName ) . AsSpan ( ) ;
5665 var spanStart = ":::{include}" . AsSpan ( ) ;
@@ -69,7 +78,13 @@ private static void Read(IFileInfo source, IFileSystem fs, StringBuilder sb, int
6978 var relativeFile = marker [ relativeFileStart ..relativeFileEnd ] . Trim ( ) ;
7079 var includePath = Path . GetFullPath ( Path . Combine ( source . Directory ! . FullName , relativeFile . ToString ( ) ) ) ;
7180 var includeSource = fs . FileInfo . New ( includePath ) ;
72- Read ( includeSource , fs , sb , depth + 1 ) ;
81+ if ( relativeFile . StartsWith ( '/' ) )
82+ {
83+ includePath = Path . Combine ( setDirectory . FullName , relativeFile . TrimStart ( '/' ) . ToString ( ) ) ;
84+ includeSource = fs . FileInfo . New ( includePath ) ;
85+ }
86+ if ( includeSource . Extension == "md" && includePath . Contains ( "_snippets" ) )
87+ Read ( includeSource , fs , sb , setDirectory ) ;
7388 startIndex = cursor + relativeFileEnd ;
7489 startIndex = Math . Min ( text . Length , startIndex ) ;
7590 }
0 commit comments