Skip to content

Commit

Permalink
Added handling for DocFx special #tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtirionMSFT committed Aug 20, 2024
1 parent fe79d4e commit 1137c9b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/DocLinkChecker/DocLinkChecker.Test/HyperlinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,32 @@ public async void ValidateLocalLinkOutsideHierarchyWithConfigShouldNotHaveErrors
service.Errors.Where(x => x.Severity == MarkdownErrorSeverity.Error).Should().BeEmpty();
}

[Theory]
[InlineData("# [Linux](#tab/linux)")]
[InlineData("# [Windows](#tab/windows)")]
public async void ValidateTabHeadersShouldNotHaveErrors(string codeLink)
{
// Arrange
_config.DocumentationFiles.SourceFolder = _fileServiceMock.Root;

LinkValidatorService service = new LinkValidatorService(_serviceProvider, _config, _fileService, _console);

//Act
(List<MarkdownObjectBase> objects, List<MarkdownError> errors) result =
MarkdownHelper.ParseMarkdownString($"{_fileServiceMock.Root}/start-document.md", codeLink, false);

Heading heading = (Heading)result.objects.FirstOrDefault(result => result is Heading);
Hyperlink link = (Hyperlink)result.objects.FirstOrDefault(result => result is Hyperlink);
await service.VerifyHyperlink(link);

// Assert
heading.Should().NotBeNull();

link.LinkType.Should().Be(HyperlinkType.Tab);

service.Errors.Should().BeEmpty();
}

[Fact]
public async void ValidateLocalLinkHeadingShouldNotHaveErrors()
{
Expand Down
5 changes: 5 additions & 0 deletions src/DocLinkChecker/DocLinkChecker/Enums/HyperlinkType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public enum HyperlinkType
/// </summary>
Resource,

/// <summary>
/// A tab - DocFx special. See https://dotnet.github.io/docfx/docs/markdown.html?tabs=linux%2Cdotnet#tabs.
/// </summary>
Tab,

/// <summary>
/// Empty link.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public static (List<MarkdownObjectBase> objects, List<MarkdownError> errors)
videoref.LinkType = HyperlinkType.Webpage;
}

// Tabs
var tabrefs = links.Where(x => x.Url.StartsWith("#tab/"));
foreach (var tabref in tabrefs)
{
tabref.LinkType = HyperlinkType.Tab;
}

objects.AddRange(links);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"DocLinkChecker": {
"commandName": "Project",
"commandLineArgs": "-d \"c:\\temp\\docs\""
}
}
}

0 comments on commit 1137c9b

Please sign in to comment.