1818
1919namespace Elastic . Markdown ;
2020
21+ /// Used primarily for testing, do not use in production paths since it might keep references alive to long
2122public interface IConversionCollector
2223{
2324 void Collect ( MarkdownFile file , MarkdownDocument document , string html ) ;
@@ -40,6 +41,7 @@ public class DocumentationGenerator
4041 private readonly ILogger _logger ;
4142 private readonly IFileSystem _writeFileSystem ;
4243 private readonly IDocumentationFileExporter _documentationFileExporter ;
44+ private readonly IMarkdownExporter [ ] _markdownExporters ;
4345 private HtmlWriter HtmlWriter { get ; }
4446
4547 public DocumentationSet DocumentationSet { get ; }
@@ -51,12 +53,14 @@ public DocumentationGenerator(
5153 ILoggerFactory logger ,
5254 INavigationHtmlWriter ? navigationHtmlWriter = null ,
5355 IDocumentationFileOutputProvider ? documentationFileOutputProvider = null ,
56+ IMarkdownExporter [ ] ? markdownExporters = null ,
5457 IDocumentationFileExporter ? documentationExporter = null ,
5558 IConversionCollector ? conversionCollector = null ,
5659 ILegacyUrlMapper ? legacyUrlMapper = null ,
5760 IPositionalNavigation ? positionalNavigation = null
5861 )
5962 {
63+ _markdownExporters = markdownExporters ?? [ ] ;
6064 _documentationFileOutputProvider = documentationFileOutputProvider ;
6165 _conversionCollector = conversionCollector ;
6266 _writeFileSystem = docSet . Context . WriteFileSystem ;
@@ -100,7 +104,7 @@ public async Task<GenerationResult> GenerateAll(Cancel ctx)
100104
101105 var generationState = Context . SkipDocumentationState ? null : GetPreviousGenerationState ( ) ;
102106
103- // clear output directory if force is true but never for assembler builds since these build multiple times to the output.
107+ // clear the output directory if force is true but never for assembler builds since these build multiple times to the output.
104108 if ( Context is { AssemblerBuild : false , Force : true }
105109 // clear the output directory if force is false but generation state is null, except for assembler builds.
106110 || ( Context is { AssemblerBuild : false , Force : false } && generationState == null ) )
@@ -209,7 +213,7 @@ private async Task ExtractEmbeddedStaticResources(Cancel ctx)
209213 }
210214 }
211215
212- private async Task ProcessFile ( HashSet < string > offendingFiles , DocumentationFile file , DateTimeOffset outputSeenChanges , Cancel token )
216+ private async Task ProcessFile ( HashSet < string > offendingFiles , DocumentationFile file , DateTimeOffset outputSeenChanges , Cancel ctx )
213217 {
214218 if ( ! Context . Force )
215219 {
@@ -220,10 +224,27 @@ private async Task ProcessFile(HashSet<string> offendingFiles, DocumentationFile
220224 }
221225
222226 _logger . LogTrace ( "--> {FileFullPath}" , file . SourceFile . FullName ) ;
223- //TODO send file to OutputFile() so we can validate its scope is defined in navigation.yml
224227 var outputFile = OutputFile ( file . RelativePath ) ;
225228 if ( outputFile is not null )
226- await _documentationFileExporter . ProcessFile ( Context , file , outputFile , HtmlWriter , _conversionCollector , token ) ;
229+ {
230+ var context = new ProcessingFileContext
231+ {
232+ BuildContext = Context ,
233+ OutputFile = outputFile ,
234+ ConversionCollector = _conversionCollector ,
235+ File = file ,
236+ HtmlWriter = HtmlWriter
237+ } ;
238+ await _documentationFileExporter . ProcessFile ( context , ctx ) ;
239+ if ( file is MarkdownFile markdown )
240+ {
241+ foreach ( var exporter in _markdownExporters )
242+ {
243+ var document = context . MarkdownDocument ??= await markdown . ParseFullAsync ( ctx ) ;
244+ _ = await exporter . ExportAsync ( new MarkdownExportContext { Document = document , File = markdown } , ctx ) ;
245+ }
246+ }
247+ }
227248 }
228249
229250 private IFileInfo ? OutputFile ( string relativePath )
0 commit comments