Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Elastic.Documentation/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum Exporter
DocumentationState,
LinkMetadata,
Redirects,
MarkdownValidation
}
public static class ExportOptions
{
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.Markdown/Exporters/ExporterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ string indexNamespace
markdownExporters.Add(new ElasticsearchMarkdownSemanticExporter(logFactory, context.Collector, indexNamespace, context.Endpoints));
if (exportOptions.Contains(Exporter.ElasticsearchNoSemantic))
markdownExporters.Add(new ElasticsearchMarkdownExporter(logFactory, context.Collector, indexNamespace, context.Endpoints));
markdownExporters.Add(new MarkdownValidationExporter());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
markdownExporters.Add(new MarkdownValidationExporter());
markdownExporters.Add(new MarkdownValidationExporter(context.Collector));

return markdownExporters;
}
}
Expand Down
57 changes: 57 additions & 0 deletions src/Elastic.Markdown/Exporters/MarkdownValidationExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using Elastic.Markdown.Exporters;
using Elastic.Markdown.IO;

namespace Elastic.Markdown.Exporters;

public class MarkdownValidationExporter : IMarkdownExporter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class MarkdownValidationExporter : IMarkdownExporter
public class MarkdownValidationExporter(IDiagnosticsCollector collector) : IMarkdownExporter

{
private readonly List<MarkdownFile> _files = [];

/// <inheritdoc />
public ValueTask StartAsync(Cancel ctx = default) => default;

/// <inheritdoc />
public ValueTask StopAsync(Cancel ctx = default)
{
var titleMap = new Dictionary<string, List<MarkdownFile>>(StringComparer.OrdinalIgnoreCase);
foreach (var file in _files)
{
if (string.IsNullOrWhiteSpace(file.Title))
{
Console.WriteLine($"Error: File {file.FilePath} has no title");
continue;
}
if (!titleMap.TryGetValue(file.Title, out var list))
titleMap[file.Title] = [];
titleMap[file.Title].Add(file);
}
foreach (var kv in titleMap)
{
var files = kv.Value;
if (files.Count > 1)
{
var title = kv.Key;
var filePaths = string.Join(", ", files.Select(f => f.FilePath));
Console.WriteLine($"Error: Title '{title}' is used in multiple files: {filePaths}");
Copy link
Member

@Mpdreamz Mpdreamz Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Console.WriteLine($"Error: Title '{title}' is used in multiple files: {filePaths}");
collector.EmitError(filePaths.First(), $"Title '{title}' is used in multiple files: {filePaths}");

}
}
return default;
}

/// <inheritdoc />
public ValueTask<bool> ExportAsync(MarkdownExportFileContext fileContext, Cancel ctx)
{
var markdownFile = fileContext.SourceFile;
_files.Add(markdownFile);
Console.WriteLine($"+++ MarkdownValidationExporter: document.Title: {markdownFile.Title}");
return ValueTask.FromResult(true);
}

/// <inheritdoc />
public ValueTask<bool> FinishExportAsync(IDirectoryInfo outputFolder, Cancel ctx) => ValueTask.FromResult(true);
}
Loading