From 1137c9bce813d3b7b817ff65946783e8cc4d7e30 Mon Sep 17 00:00:00 2001 From: Martin Tirion Date: Tue, 20 Aug 2024 16:58:19 +0200 Subject: [PATCH] Added handling for DocFx special #tabs --- .../DocLinkChecker.Test/HyperlinkTests.cs | 26 +++++++++++++++++++ .../DocLinkChecker/Enums/HyperlinkType.cs | 5 ++++ .../DocLinkChecker/Helpers/MarkdownHelper.cs | 7 +++++ .../Properties/launchSettings.json | 8 ++++++ 4 files changed, 46 insertions(+) create mode 100644 src/DocLinkChecker/DocLinkChecker/Properties/launchSettings.json diff --git a/src/DocLinkChecker/DocLinkChecker.Test/HyperlinkTests.cs b/src/DocLinkChecker/DocLinkChecker.Test/HyperlinkTests.cs index 9a20586..6a22fc1 100644 --- a/src/DocLinkChecker/DocLinkChecker.Test/HyperlinkTests.cs +++ b/src/DocLinkChecker/DocLinkChecker.Test/HyperlinkTests.cs @@ -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 objects, List 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() { diff --git a/src/DocLinkChecker/DocLinkChecker/Enums/HyperlinkType.cs b/src/DocLinkChecker/DocLinkChecker/Enums/HyperlinkType.cs index f7612d5..82080d7 100644 --- a/src/DocLinkChecker/DocLinkChecker/Enums/HyperlinkType.cs +++ b/src/DocLinkChecker/DocLinkChecker/Enums/HyperlinkType.cs @@ -35,6 +35,11 @@ public enum HyperlinkType /// Resource, + /// + /// A tab - DocFx special. See https://dotnet.github.io/docfx/docs/markdown.html?tabs=linux%2Cdotnet#tabs. + /// + Tab, + /// /// Empty link. /// diff --git a/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs b/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs index efb4a3b..29ec085 100644 --- a/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs +++ b/src/DocLinkChecker/DocLinkChecker/Helpers/MarkdownHelper.cs @@ -77,6 +77,13 @@ public static (List objects, List 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); } diff --git a/src/DocLinkChecker/DocLinkChecker/Properties/launchSettings.json b/src/DocLinkChecker/DocLinkChecker/Properties/launchSettings.json new file mode 100644 index 0000000..f7ca845 --- /dev/null +++ b/src/DocLinkChecker/DocLinkChecker/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "DocLinkChecker": { + "commandName": "Project", + "commandLineArgs": "-d \"c:\\temp\\docs\"" + } + } +} \ No newline at end of file