From 83c37d2730ae69fa0a33ddacc57505245cc54016 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 6 Feb 2025 21:49:43 +0100 Subject: [PATCH 1/6] Fix relative links --- .../InlineParsers/DiagnosticLinkInlineParser.cs | 17 +++++++++++------ .../Inline/AnchorLinkTests.cs | 3 +-- .../Inline/InlineImageTest.cs | 2 +- .../Inline/InlineLinkTests.cs | 10 +++++++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index eafdd0c2..8bfe6d45 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -168,10 +168,10 @@ private static void ProcessInternalLink(InlineProcessor processor, LinkInline li { var (url, anchor) = SplitUrlAndAnchor(link.Url ?? string.Empty); var includeFrom = GetIncludeFromPath(url, context); - + var file = ResolveFile(context, url); ValidateInternalUrl(processor, url, includeFrom, line, column, length, context); - ProcessLinkText(processor, link, context, url, anchor, line, column, length); - UpdateLinkUrl(link, url, anchor, context.Build.UrlPathPrefix ?? string.Empty); + ProcessLinkText(processor, link, context, url, anchor, line, column, length, file); + UpdateLinkUrl(link, url, context, anchor, file); } private static (string url, string? anchor) SplitUrlAndAnchor(string fullUrl) @@ -195,12 +195,11 @@ private static void ValidateInternalUrl(InlineProcessor processor, string url, s processor.EmitError(line, column, length, $"`{url}` does not exist. resolved to `{pathOnDisk}"); } - private static void ProcessLinkText(InlineProcessor processor, LinkInline link, ParserContext context, string url, string? anchor, int line, int column, int length) + private static void ProcessLinkText(InlineProcessor processor, LinkInline link, ParserContext context, string url, string? anchor, int line, int column, int length, IFileInfo file) { if (link.FirstChild != null && string.IsNullOrEmpty(anchor)) return; - var file = ResolveFile(context, url); var markdown = context.GetDocumentationFile?.Invoke(file) as MarkdownFile; if (markdown == null) @@ -236,13 +235,19 @@ private static void ValidateAnchor(InlineProcessor processor, MarkdownFile markd processor.EmitError(line, column, length, $"`{anchor}` does not exist in {markdown.FileName}."); } - private static void UpdateLinkUrl(LinkInline link, string url, string? anchor, string urlPathPrefix) + private static void UpdateLinkUrl(LinkInline link, string url, ParserContext context, string? anchor, IFileInfo file) { + var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty; if (url.EndsWith(".md")) url = Path.ChangeExtension(url, ".html"); if (url.StartsWith("/") && !string.IsNullOrWhiteSpace(urlPathPrefix)) url = $"{urlPathPrefix.TrimEnd('/')}{url}"; + else + { + var docsetDirectory = context.Configuration.SourceFile.Directory; + url = file.FullName.Replace(docsetDirectory!.FullName, string.Empty); + } link.Url = !string.IsNullOrEmpty(anchor) ? $"{url}#{anchor}" : url; } diff --git a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs index d3a935fa..28012470 100644 --- a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs @@ -166,9 +166,8 @@ [Heading inside dropdown](testing/req.md#heading-inside-dropdown) public void GeneratesHtml() => // language=html Html.Should().Contain( - """Heading inside dropdown""" + """Heading inside dropdown""" ); - [Fact] public void HasError() => Collector.Diagnostics.Should().HaveCount(0); } diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs index 1fea4fed..508e1e6d 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs @@ -37,6 +37,6 @@ public class RelativeInlineImageTest(ITestOutputHelper output) : InlineTest // language=html Html.Should().Contain( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs index 33a902b4..d23ac47a 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs @@ -58,7 +58,11 @@ public class LinkToPageTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( +<<<<<<< Updated upstream """

Requirements

""" +======= + """

Requirements

""" +>>>>>>> Stashed changes ); [Fact] @@ -81,7 +85,7 @@ public class InsertPageTitleTests(ITestOutputHelper output) : LinkTestBase(outpu public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Special Requirements

""" + """

Special Requirements

""" ); [Fact] @@ -106,7 +110,11 @@ public class LinkReferenceTest(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( +<<<<<<< Updated upstream """

test

""" +======= + """

test

""" +>>>>>>> Stashed changes ); [Fact] From d92266f5754820b7d97cf087671693dc3da46309 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 6 Feb 2025 21:59:59 +0100 Subject: [PATCH 2/6] fix --- .../InlineParsers/DiagnosticLinkInlineParser.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index 8bfe6d45..b6527155 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -241,17 +241,22 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con if (url.EndsWith(".md")) url = Path.ChangeExtension(url, ".html"); - if (url.StartsWith("/") && !string.IsNullOrWhiteSpace(urlPathPrefix)) + + if (!url.StartsWith('/')) + url = GetRootRelativePath(context, file); + + if (!string.IsNullOrWhiteSpace(urlPathPrefix)) url = $"{urlPathPrefix.TrimEnd('/')}{url}"; - else - { - var docsetDirectory = context.Configuration.SourceFile.Directory; - url = file.FullName.Replace(docsetDirectory!.FullName, string.Empty); - } link.Url = !string.IsNullOrEmpty(anchor) ? $"{url}#{anchor}" : url; } + private static string GetRootRelativePath(ParserContext context, IFileInfo file) + { + var docsetDirectory = context.Configuration.SourceFile.Directory; + return file.FullName.Replace(docsetDirectory!.FullName, string.Empty); + } + private static bool IsCrossLink(Uri? uri) => uri != null // This means it's not a local && !ExcludedSchemes.Contains(uri.Scheme) From c313647a12fe6382aab1f77fed515f18793bddea Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 6 Feb 2025 22:08:59 +0100 Subject: [PATCH 3/6] test --- .../Myst/InlineParsers/DiagnosticLinkInlineParser.cs | 10 +++++----- tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index b6527155..fab99062 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -237,18 +237,18 @@ private static void ValidateAnchor(InlineProcessor processor, MarkdownFile markd private static void UpdateLinkUrl(LinkInline link, string url, ParserContext context, string? anchor, IFileInfo file) { + var newUrl = url; var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty; if (url.EndsWith(".md")) - url = Path.ChangeExtension(url, ".html"); - + newUrl = Path.ChangeExtension(newUrl, ".html"); if (!url.StartsWith('/')) - url = GetRootRelativePath(context, file); + newUrl = GetRootRelativePath(context, file); if (!string.IsNullOrWhiteSpace(urlPathPrefix)) - url = $"{urlPathPrefix.TrimEnd('/')}{url}"; + newUrl = $"{urlPathPrefix.TrimEnd('/')}{newUrl}"; - link.Url = !string.IsNullOrEmpty(anchor) ? $"{url}#{anchor}" : url; + link.Url = !string.IsNullOrEmpty(anchor) ? $"{newUrl}#{anchor}" : newUrl; } private static string GetRootRelativePath(ParserContext context, IFileInfo file) diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs index d23ac47a..0eee1822 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs @@ -58,11 +58,7 @@ public class LinkToPageTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( -<<<<<<< Updated upstream - """

Requirements

""" -======= """

Requirements

""" ->>>>>>> Stashed changes ); [Fact] @@ -110,11 +106,7 @@ public class LinkReferenceTest(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( -<<<<<<< Updated upstream - """

test

""" -======= """

test

""" ->>>>>>> Stashed changes ); [Fact] From 2f3b26c97d8b7756de2be26cd6c401c6071b69cb Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 6 Feb 2025 23:41:21 +0100 Subject: [PATCH 4/6] fixes --- .../Myst/InlineParsers/DiagnosticLinkInlineParser.cs | 9 ++++++--- tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs | 10 +++++----- .../Inline/DirectiveBlockLinkTests.cs | 2 +- .../Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs | 2 +- tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs | 6 +++--- tests/authoring/Inline/InlineImages.fs | 10 +++++----- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index fab99062..ae1e38e1 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -239,11 +239,14 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con { var newUrl = url; var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty; - if (url.EndsWith(".md")) - newUrl = Path.ChangeExtension(newUrl, ".html"); - if (!url.StartsWith('/')) + if (!url.StartsWith('/') && !string.IsNullOrEmpty(url)) + { newUrl = GetRootRelativePath(context, file); + } + + if (url.EndsWith(".md")) + newUrl = Path.ChangeExtension(newUrl, ".html"); if (!string.IsNullOrWhiteSpace(urlPathPrefix)) newUrl = $"{urlPathPrefix.TrimEnd('/')}{newUrl}"; diff --git a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs index 28012470..c072d957 100644 --- a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs @@ -76,7 +76,7 @@ [Sub Requirements](testing/req.md#sub-requirements) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] @@ -94,7 +94,7 @@ [Sub Requirements](testing/req.md#new-reqs) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] @@ -111,7 +111,7 @@ public class ExternalPageAnchorAutoTitleTests(ITestOutputHelper output) : Anchor public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Special Requirements > Sub Requirements

""" + """

Special Requirements > Sub Requirements

""" ); [Fact] @@ -147,7 +147,7 @@ [Sub Requirements](testing/req.md#sub-requirements2) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] @@ -166,7 +166,7 @@ [Heading inside dropdown](testing/req.md#heading-inside-dropdown) public void GeneratesHtml() => // language=html Html.Should().Contain( - """Heading inside dropdown""" + """Heading inside dropdown""" ); [Fact] public void HasError() => Collector.Diagnostics.Should().HaveCount(0); diff --git a/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs index 500e8bc5..318ca59a 100644 --- a/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs @@ -67,7 +67,7 @@ [Sub Requirements](testing/req.md#hint_ref) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs index 8fdde44c..c13625ba 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs @@ -203,7 +203,7 @@ [Sub Requirements](testing/req.md#custom-anchor) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs index 0eee1822..4207b259 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs @@ -58,7 +58,7 @@ public class LinkToPageTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Requirements

""" + """

Requirements

""" ); [Fact] @@ -81,7 +81,7 @@ public class InsertPageTitleTests(ITestOutputHelper output) : LinkTestBase(outpu public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Special Requirements

""" + """

Special Requirements

""" ); [Fact] @@ -106,7 +106,7 @@ public class LinkReferenceTest(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

test

""" + """

test

""" ); [Fact] diff --git a/tests/authoring/Inline/InlineImages.fs b/tests/authoring/Inline/InlineImages.fs index 8320b9fd..e9258fb3 100644 --- a/tests/authoring/Inline/InlineImages.fs +++ b/tests/authoring/Inline/InlineImages.fs @@ -26,7 +26,7 @@ type ``relative path to image`` () = [] let ``validate HTML: preserves relative path`` () = markdown |> convertsToHtml """ -

Elasticsearch

+

Elasticsearch

""" type ``supplying a tittle`` () = @@ -37,7 +37,7 @@ type ``supplying a tittle`` () = [] let ``validate HTML: includes title`` () = markdown |> convertsToHtml """ -

Elasticsearch

+

Elasticsearch

""" type ``supplying a tittle with width and height`` () = @@ -48,7 +48,7 @@ type ``supplying a tittle with width and height`` () = [] let ``validate HTML: does not include width and height in title`` () = markdown |> convertsToHtml """ -

o

+

o

""" type ``supplying a tittle with width and height in percentage`` () = @@ -59,7 +59,7 @@ type ``supplying a tittle with width and height in percentage`` () = [] let ``validate HTML: does not include width and height in title`` () = markdown |> convertsToHtml """ -

o

+

o

""" type ``supplying a tittle with width only`` () = static let markdown = Setup.Markdown """ @@ -69,5 +69,5 @@ type ``supplying a tittle with width only`` () = [] let ``validate HTML: sets height to width if not supplied`` () = markdown |> convertsToHtml """ -

o

+

o

""" From eecd4cc3de37e03d69a960952c423f9cdcd6ed5a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 6 Feb 2025 23:52:09 +0100 Subject: [PATCH 5/6] Set url path prefix for tests --- .../Myst/InlineParsers/DiagnosticLinkInlineParser.cs | 2 +- .../Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs | 10 +++++----- .../Inline/DirectiveBlockLinkTests.cs | 2 +- .../Inline/InlineAnchorTests.cs | 2 +- .../Elastic.Markdown.Tests/Inline/InlineImageTest.cs | 4 ++-- .../Elastic.Markdown.Tests/Inline/InlineLinkTests.cs | 12 ++++++------ .../Elastic.Markdown.Tests/Inline/InlneBaseTests.cs | 5 +++-- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index ae1e38e1..bc4c52d5 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -248,7 +248,7 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con if (url.EndsWith(".md")) newUrl = Path.ChangeExtension(newUrl, ".html"); - if (!string.IsNullOrWhiteSpace(urlPathPrefix)) + if (!string.IsNullOrWhiteSpace(newUrl) && !string.IsNullOrWhiteSpace(urlPathPrefix)) newUrl = $"{urlPathPrefix.TrimEnd('/')}{newUrl}"; link.Url = !string.IsNullOrEmpty(anchor) ? $"{newUrl}#{anchor}" : newUrl; diff --git a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs index c072d957..a070dd9d 100644 --- a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs @@ -76,7 +76,7 @@ [Sub Requirements](testing/req.md#sub-requirements) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] @@ -94,7 +94,7 @@ [Sub Requirements](testing/req.md#new-reqs) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] @@ -111,7 +111,7 @@ public class ExternalPageAnchorAutoTitleTests(ITestOutputHelper output) : Anchor public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Special Requirements > Sub Requirements

""" + """

Special Requirements > Sub Requirements

""" ); [Fact] @@ -147,7 +147,7 @@ [Sub Requirements](testing/req.md#sub-requirements2) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] @@ -166,7 +166,7 @@ [Heading inside dropdown](testing/req.md#heading-inside-dropdown) public void GeneratesHtml() => // language=html Html.Should().Contain( - """Heading inside dropdown""" + """Heading inside dropdown""" ); [Fact] public void HasError() => Collector.Diagnostics.Should().HaveCount(0); diff --git a/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs index 318ca59a..77f9e978 100644 --- a/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs @@ -67,7 +67,7 @@ [Sub Requirements](testing/req.md#hint_ref) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs index c13625ba..12e29802 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs @@ -203,7 +203,7 @@ [Sub Requirements](testing/req.md#custom-anchor) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Sub Requirements

""" + """

Sub Requirements

""" ); [Fact] diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs index 508e1e6d..339f3a47 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineImageTest.cs @@ -20,7 +20,7 @@ public class InlineImageTest(ITestOutputHelper output) : InlineTest( public void GeneratesAttributesInHtml() => // language=html Html.Should().Contain( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } @@ -37,6 +37,6 @@ public class RelativeInlineImageTest(ITestOutputHelper output) : InlineTest // language=html Html.Should().Contain( - """

Elasticsearch

""" + """

Elasticsearch

""" ); } diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs index 4207b259..0e46c2cd 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs @@ -41,7 +41,7 @@ public class InlineLinkTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Elasticsearch

""" + """

Elasticsearch

""" ); [Fact] @@ -58,7 +58,7 @@ public class LinkToPageTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Requirements

""" + """

Requirements

""" ); [Fact] @@ -81,7 +81,7 @@ public class InsertPageTitleTests(ITestOutputHelper output) : LinkTestBase(outpu public void GeneratesHtml() => // language=html Html.Should().Contain( - """

Special Requirements

""" + """

Special Requirements

""" ); [Fact] @@ -106,7 +106,7 @@ public class LinkReferenceTest(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

test

""" + """

test

""" ); [Fact] @@ -225,10 +225,10 @@ public void GeneratesHtml() => Html.TrimEnd().Should().Be("""

Links:

"""); diff --git a/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs index 4d794a85..8c3cc863 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs @@ -100,7 +100,7 @@ protected InlineTest( { "docs/index.md", new MockFileData(documentContents) } }, new MockFileSystemOptions { - CurrentDirectory = Paths.Root.FullName + CurrentDirectory = Paths.Root.FullName, }); // ReSharper disable once VirtualMemberCallInConstructor // nasty but sub implementations won't use class state. @@ -112,7 +112,8 @@ protected InlineTest( Collector = new TestDiagnosticsCollector(output); var context = new BuildContext(FileSystem) { - Collector = Collector + Collector = Collector, + UrlPathPrefix = "/docs" }; Set = new DocumentationSet(context); File = Set.GetMarkdownFile(FileSystem.FileInfo.New("docs/index.md")) ?? throw new NullReferenceException(); From dac0a61258e322fc0299c7fec163c4618d8340a0 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Fri, 7 Feb 2025 00:05:39 +0100 Subject: [PATCH 6/6] ok --- .../InlineParsers/DiagnosticLinkInlineParser.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs index bc4c52d5..0900fdcf 100644 --- a/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs +++ b/src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs @@ -237,21 +237,18 @@ private static void ValidateAnchor(InlineProcessor processor, MarkdownFile markd private static void UpdateLinkUrl(LinkInline link, string url, ParserContext context, string? anchor, IFileInfo file) { - var newUrl = url; var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty; if (!url.StartsWith('/') && !string.IsNullOrEmpty(url)) - { - newUrl = GetRootRelativePath(context, file); - } + url = GetRootRelativePath(context, file); if (url.EndsWith(".md")) - newUrl = Path.ChangeExtension(newUrl, ".html"); + url = Path.ChangeExtension(url, ".html"); - if (!string.IsNullOrWhiteSpace(newUrl) && !string.IsNullOrWhiteSpace(urlPathPrefix)) - newUrl = $"{urlPathPrefix.TrimEnd('/')}{newUrl}"; + if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(urlPathPrefix)) + url = $"{urlPathPrefix.TrimEnd('/')}{url}"; - link.Url = !string.IsNullOrEmpty(anchor) ? $"{newUrl}#{anchor}" : newUrl; + link.Url = string.IsNullOrEmpty(anchor) ? url : $"{url}#{anchor}"; } private static string GetRootRelativePath(ParserContext context, IFileInfo file)