Skip to content

Commit 1bbe5ba

Browse files
committed
Fix cross-link validation
1 parent 2ca63c9 commit 1bbe5ba

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/Elastic.Documentation.Links/CrossLinks/CrossLinkResolver.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ public static bool TryResolve(
8989
if (sourceLinkReference.Links.TryGetValue(originalLookupPath, out var directLinkMetadata))
9090
return ResolveDirectLink(errorEmitter, uriResolver, crossLinkUri, originalLookupPath, directLinkMetadata, out resolvedUri);
9191

92-
// For development docs or known repositories, allow links even if they don't exist in the link index
93-
if (isDeclaredRepo)
94-
{
95-
// Create a synthesized URL for development purposes
96-
var path = ToTargetUrlPath(originalLookupPath);
97-
resolvedUri = uriResolver.Resolve(crossLinkUri, path);
98-
return true;
99-
}
100-
101-
10292
var linksJson = $"https://elastic-docs-link-index.s3.us-east-2.amazonaws.com/elastic/{crossLinkUri.Scheme}/main/links.json";
10393
if (fetchedCrossLinks.LinkIndexEntries.TryGetValue(crossLinkUri.Scheme, out var indexEntry))
10494
linksJson = $"https://elastic-docs-link-index.s3.us-east-2.amazonaws.com/{indexEntry.Path}";

tests/authoring/Inline/CrossLinks.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ type ``link to repository that does not resolve yet`` () =
101101
[<Fact>]
102102
let ``has no warning`` () = markdown |> hasNoWarnings
103103

104+
type ``error when linking to non-existent file in declared repository`` () =
105+
106+
static let markdown = Setup.Markdown """
107+
[Non-existent file](docs-content://non-existent-file.md)
108+
"""
109+
110+
[<Fact>]
111+
let ``validate HTML`` () =
112+
// This link cannot be resolved, so we just output the link as-is
113+
markdown |> convertsToHtml """
114+
<p><a
115+
href="docs-content://non-existent-file.md">
116+
Non-existent file
117+
</a>
118+
</p>
119+
"""
120+
121+
[<Fact>]
122+
let ``error when file not found in links.json`` () =
123+
markdown |> hasError("'non-existent-file.md' is not a valid link in the 'docs-content' cross link index")
124+
125+
[<Fact>]
126+
let ``has no warning`` () = markdown |> hasNoWarnings
127+
104128
type ``Using double forward slashes`` () =
105129

106130
static let markdown = Setup.Markdown """

0 commit comments

Comments
 (0)