Skip to content

Commit

Permalink
Remove erroneous warning for link text generation on missing page (#592)
Browse files Browse the repository at this point in the history
* Remove erroneous warning for link text generation on missing page

* dotnet format
  • Loading branch information
Mpdreamz authored Feb 24, 2025
1 parent 29e6435 commit 9f7256d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,20 @@ private static void ProcessLinkText(InlineProcessor processor, LinkInline link,

var markdown = context.GetDocumentationFile?.Invoke(file) as MarkdownFile;

if (markdown == null)
if (markdown == null && link.FirstChild == null)
{
processor.EmitWarning(link,
$"'{url}' could not be resolved to a markdown file while creating an auto text link, '{file.FullName}' does not exist.");
return;
}

var title = markdown.Title;
var title = markdown?.Title;

if (!string.IsNullOrEmpty(anchor))
{
ValidateAnchor(processor, markdown, anchor, link);
if (link.FirstChild == null && markdown.TableOfContents.TryGetValue(anchor, out var heading))
if (markdown is not null)
ValidateAnchor(processor, markdown, anchor, link);
if (link.FirstChild == null && (markdown?.TableOfContents.TryGetValue(anchor, out var heading) ?? false))
title += " > " + heading.Heading;
}

Expand Down
20 changes: 19 additions & 1 deletion tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using System.IO.Abstractions.TestingHelpers;
using Elastic.Markdown.Diagnostics;
using FluentAssertions;
using JetBrains.Annotations;
using Markdig.Syntax.Inlines;
Expand Down Expand Up @@ -177,11 +178,28 @@ public void GeneratesHtml() =>
public void HasWarnings()
{
Collector.Diagnostics.Should().HaveCount(1);
Collector.Diagnostics.First().Severity.Should().Be(Diagnostics.Severity.Warning);
Collector.Diagnostics.First().Severity.Should().Be(Severity.Warning);
Collector.Diagnostics.First().Message.Should().Contain("The url contains a template expression. Please do not use template expressions in links. See https://github.com/elastic/docs-builder/issues/182 for further information.");
}
}

public class NonExistingLinks(ITestOutputHelper output) : LinkTestBase(output,
"""
[Non Existing Link](/non-existing.md)
"""
)
{
[Fact]
public void HasErrors() => Collector.Diagnostics
.Where(d => d.Severity == Severity.Error)
.Should().HaveCount(1);

[Fact]
public void HasNoWarning() => Collector.Diagnostics
.Where(d => d.Severity == Severity.Warning)
.Should().HaveCount(0);
}

public class CommentedNonExistingLinks(ITestOutputHelper output) : LinkTestBase(output,
"""
% [Non Existing Link](/non-existing.md)
Expand Down

0 comments on commit 9f7256d

Please sign in to comment.