55using System . IO . Abstractions ;
66using Elastic . Markdown . IO ;
77using Elastic . Markdown . Slices ;
8+ using Markdig . Syntax ;
89
910namespace Elastic . Markdown . Exporters ;
1011
12+ public class ProcessingFileContext
13+ {
14+ public required BuildContext BuildContext { get ; init ; }
15+ public required DocumentationFile File { get ; init ; }
16+ public required IFileInfo OutputFile { get ; init ; }
17+ public required HtmlWriter HtmlWriter { get ; init ; }
18+ public required IConversionCollector ? ConversionCollector { get ; init ; }
19+
20+ public MarkdownDocument ? MarkdownDocument { get ; set ; }
21+ }
22+
1123public interface IDocumentationFileExporter
1224{
13- /// Used in documentation state to ensure we break the build cache if a different exporter is chosen
25+ /// Used in the documentation state to ensure we break the build cache if a different exporter is chosen
1426 string Name { get ; }
1527
16- Task ProcessFile ( BuildContext context , DocumentationFile file , IFileInfo outputFile , HtmlWriter htmlWriter , IConversionCollector ? conversionCollector ,
17- Cancel token ) ;
28+ ValueTask ProcessFile ( ProcessingFileContext context , Cancel ctx ) ;
1829
1930 Task CopyEmbeddedResource ( IFileInfo outputFile , Stream resourceStream , Cancel ctx ) ;
2031}
@@ -23,16 +34,14 @@ public abstract class DocumentationFileExporterBase(IFileSystem readFileSystem,
2334{
2435 public abstract string Name { get ; }
2536
26- public abstract Task ProcessFile ( BuildContext context , DocumentationFile file , IFileInfo outputFile , HtmlWriter htmlWriter ,
27- IConversionCollector ? conversionCollector ,
28- Cancel token ) ;
37+ public abstract ValueTask ProcessFile ( ProcessingFileContext context , Cancel ctx ) ;
2938
3039 protected async Task CopyFileFsAware ( DocumentationFile file , IFileInfo outputFile , Cancel ctx )
3140 {
3241 // fast path, normal case.
3342 if ( readFileSystem == writeFileSystem )
3443 readFileSystem . File . Copy ( file . SourceFile . FullName , outputFile . FullName , true ) ;
35- //slower when we are mocking the write filesystem
44+ //slower when we are mocking the write- filesystem
3645 else
3746 {
3847 var bytes = await file . SourceFile . FileSystem . File . ReadAllBytesAsync ( file . SourceFile . FullName , ctx ) ;
@@ -49,26 +58,20 @@ public async Task CopyEmbeddedResource(IFileInfo outputFile, Stream resourceStre
4958 }
5059}
5160
52- public class DocumentationFileExporter (
53- IFileSystem readFileSystem ,
54- IFileSystem writeFileSystem
55- ) : DocumentationFileExporterBase ( readFileSystem , writeFileSystem )
61+ public class DocumentationFileExporter ( IFileSystem readFileSystem , IFileSystem writeFileSystem )
62+ : DocumentationFileExporterBase ( readFileSystem , writeFileSystem )
5663{
57- public override string Name { get ; } = nameof ( DocumentationFileExporter ) ;
64+ public override string Name => nameof ( DocumentationFileExporter ) ;
5865
59- public override async Task ProcessFile ( BuildContext context , DocumentationFile file ,
60- IFileInfo outputFile ,
61- HtmlWriter htmlWriter ,
62- IConversionCollector ? conversionCollector ,
63- Cancel token )
66+ public override async ValueTask ProcessFile ( ProcessingFileContext context , Cancel ctx )
6467 {
65- if ( file is MarkdownFile markdown )
66- await htmlWriter . WriteAsync ( outputFile , markdown , conversionCollector , token ) ;
68+ if ( context . File is MarkdownFile markdown )
69+ context . MarkdownDocument = await context . HtmlWriter . WriteAsync ( context . OutputFile , markdown , context . ConversionCollector , ctx ) ;
6770 else
6871 {
69- if ( outputFile . Directory is { Exists : false } )
70- outputFile . Directory . Create ( ) ;
71- await CopyFileFsAware ( file , outputFile , token ) ;
72+ if ( context . OutputFile . Directory is { Exists : false } )
73+ context . OutputFile . Directory . Create ( ) ;
74+ await CopyFileFsAware ( context . File , context . OutputFile , ctx ) ;
7275 }
7376 }
7477}
0 commit comments