From b133b7eb98c8007044c813fc2c6d9c9e010476ae Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 3 Dec 2024 16:10:06 +0100 Subject: [PATCH 1/4] Relax version directive argument, allow for major.minor format --- .../Myst/Directives/VersionBlock.cs | 7 +++-- .../Directives/VersionTests.cs | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs b/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs index ad225e7e..c3a21380 100644 --- a/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information using Elastic.Markdown.Helpers; +using static System.StringSplitOptions; namespace Elastic.Markdown.Myst.Directives; @@ -17,7 +18,7 @@ public class VersionBlock(DirectiveBlockParser parser, string directive, Diction public override void FinalizeAndValidate(ParserContext context) { - var tokens = Arguments?.Split(" ", 2, StringSplitOptions.RemoveEmptyEntries) ?? []; + var tokens = Arguments?.Split(" ", 2, RemoveEmptyEntries) ?? []; if (tokens.Length < 1) { EmitError(context, $"{directive} needs exactly 2 arguments: "); @@ -26,7 +27,9 @@ public override void FinalizeAndValidate(ParserContext context) if (!SemVersion.TryParse(tokens[0], out var version)) { - EmitError(context, $"{tokens[0]} is not a valid version"); + var numbers = tokens[0].Split('.', RemoveEmptyEntries); + if (numbers.Length != 2 || !SemVersion.TryParse($"{numbers[0]}.{numbers[1]}", out version)) + EmitError(context, $"'{tokens[0]}' is not a valid version"); return; } diff --git a/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs b/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs index 8e0573ec..e3d3a141 100644 --- a/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs @@ -50,3 +50,32 @@ public class VersionDeprectatedTests(ITestOutputHelper output) : VersionTests(ou [Fact] public void SetsTitle() => Block!.Title.Should().Be("Deprecated (1.0.1-beta1): more information"); } + +public abstract class VersionValidationTests(ITestOutputHelper output, string version) : DirectiveTest<VersionBlock>(output, +$$""" +```{versionchanged} {{version}} more information +Version brief summary +``` +A regular paragraph. +""" +); + +public class SimpleVersion(ITestOutputHelper output) : VersionValidationTests(output, "7.17") +{ + [Fact] + public void SetsVersion() => Block!.Version.Should().Be(new SemVersion(7, 17, 0)); +} + +public class MajorVersionOnly(ITestOutputHelper output) : VersionValidationTests(output, "8") +{ + [Fact] + public void HasError() => Collector.Diagnostics.Should().HaveCount(1) + .And.Contain(d => d.Message.Contains("'8' is not a valid version")); +} + +public class BranchVersion(ITestOutputHelper output) : VersionValidationTests(output, "8.x") +{ + [Fact] + public void HasError() => Collector.Diagnostics.Should().HaveCount(1) + .And.Contain(d => d.Message.Contains("'8.x' is not a valid version")); +} From fada00ebd5d09758c84dd8bdd1d6c6dee0c3cee5 Mon Sep 17 00:00:00 2001 From: Martijn Laarman <Mpdreamz@gmail.com> Date: Tue, 3 Dec 2024 16:17:12 +0100 Subject: [PATCH 2/4] Fix failing test --- src/Elastic.Markdown/Myst/Directives/VersionBlock.cs | 3 +-- tests/Elastic.Markdown.Tests/Directives/VersionTests.cs | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs b/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs index c3a21380..9fda232a 100644 --- a/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/VersionBlock.cs @@ -28,9 +28,8 @@ public override void FinalizeAndValidate(ParserContext context) if (!SemVersion.TryParse(tokens[0], out var version)) { var numbers = tokens[0].Split('.', RemoveEmptyEntries); - if (numbers.Length != 2 || !SemVersion.TryParse($"{numbers[0]}.{numbers[1]}", out version)) + if (numbers.Length != 2 || !SemVersion.TryParse($"{numbers[0]}.{numbers[1]}.0", out version)) EmitError(context, $"'{tokens[0]}' is not a valid version"); - return; } Version = version; diff --git a/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs b/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs index e3d3a141..f5fc59cd 100644 --- a/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/VersionTests.cs @@ -54,7 +54,7 @@ public class VersionDeprectatedTests(ITestOutputHelper output) : VersionTests(ou public abstract class VersionValidationTests(ITestOutputHelper output, string version) : DirectiveTest<VersionBlock>(output, $$""" ```{versionchanged} {{version}} more information -Version brief summary +Version brief summary ``` A regular paragraph. """ @@ -64,6 +64,9 @@ public class SimpleVersion(ITestOutputHelper output) : VersionValidationTests(ou { [Fact] public void SetsVersion() => Block!.Version.Should().Be(new SemVersion(7, 17, 0)); + + [Fact] + public void HasNoError() => Collector.Diagnostics.Should().BeEmpty(); } public class MajorVersionOnly(ITestOutputHelper output) : VersionValidationTests(output, "8") From 754686a6bae78caaeea66860458c4f67ed77d1b7 Mon Sep 17 00:00:00 2001 From: Martijn Laarman <Mpdreamz@gmail.com> Date: Tue, 3 Dec 2024 16:42:11 +0100 Subject: [PATCH 3/4] Fallback to relative path for title and navigation title --- docs/source/docset.yml | 1 + src/Elastic.Markdown/IO/MarkdownFile.cs | 5 +++++ src/docs-builder/Http/ReloadGeneratorService.cs | 2 ++ 3 files changed, 8 insertions(+) diff --git a/docs/source/docset.yml b/docs/source/docset.yml index 7ff94268..9d1e5678 100644 --- a/docs/source/docset.yml +++ b/docs/source/docset.yml @@ -45,4 +45,5 @@ toc: children: - folder: content - file: index.md + - file: test.md - folder: versioning diff --git a/src/Elastic.Markdown/IO/MarkdownFile.cs b/src/Elastic.Markdown/IO/MarkdownFile.cs index 87333ae7..27820531 100644 --- a/src/Elastic.Markdown/IO/MarkdownFile.cs +++ b/src/Elastic.Markdown/IO/MarkdownFile.cs @@ -72,6 +72,11 @@ private void ReadDocumentInstructions(MarkdownDocument document) Title = YamlFrontMatter.Title; NavigationTitle = YamlFrontMatter.NavigationTitle; } + else + { + Title = RelativePath; + NavigationTitle = RelativePath; + } var contents = document .Where(block => block is HeadingBlock { Level: 2 }) diff --git a/src/docs-builder/Http/ReloadGeneratorService.cs b/src/docs-builder/Http/ReloadGeneratorService.cs index 118681fd..11ad5e84 100644 --- a/src/docs-builder/Http/ReloadGeneratorService.cs +++ b/src/docs-builder/Http/ReloadGeneratorService.cs @@ -66,6 +66,8 @@ private void OnChanged(object sender, FileSystemEventArgs e) if (e.FullPath.EndsWith("docset.yml")) Reload(); + if (e.FullPath.EndsWith(".md")) + Reload(); Logger.LogInformation($"Changed: {e.FullPath}"); } From c2f18e356293f0be033ed1a937e3db0af88cc02e Mon Sep 17 00:00:00 2001 From: Martijn Laarman <Mpdreamz@gmail.com> Date: Tue, 3 Dec 2024 16:44:05 +0100 Subject: [PATCH 4/4] Remove temporary file from docset.yml --- docs/source/docset.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/docset.yml b/docs/source/docset.yml index 9d1e5678..7ff94268 100644 --- a/docs/source/docset.yml +++ b/docs/source/docset.yml @@ -45,5 +45,4 @@ toc: children: - folder: content - file: index.md - - file: test.md - folder: versioning