@@ -289,11 +289,14 @@ private static IFileInfo ResolveFile(ParserContext context, string url) =>
289
289
private static void ValidateAnchor ( InlineProcessor processor , MarkdownFile markdown , string anchor , LinkInline link )
290
290
{
291
291
if ( ! markdown . Anchors . Contains ( anchor ) )
292
- processor . EmitError ( link , $ "`{ anchor } ` does not exist in { markdown . FileName } .") ;
292
+ processor . EmitError ( link , $ "`{ anchor } ` does not exist in { markdown . RelativePath } .") ;
293
293
}
294
294
295
295
private static void UpdateLinkUrl ( LinkInline link , string url , ParserContext context , string ? anchor )
296
296
{
297
+ // TODO revisit when we refactor our documentation set graph
298
+ // This method grew too complex, we need to revisit our documentation set graph generation so we can ask these questions
299
+ // on `DocumentationFile` that are mostly precomputed
297
300
var urlPathPrefix = context . Build . UrlPathPrefix ?? string . Empty ;
298
301
299
302
if ( ! url . StartsWith ( '/' ) && ! string . IsNullOrEmpty ( url ) )
@@ -303,16 +306,19 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
303
306
? context . CurrentUrlPath [ urlPathPrefix . Length ..]
304
307
: urlPathPrefix ;
305
308
306
- var markdownPath = context . MarkdownSourcePath . Name ;
309
+ // if we are trying to resolve a relative url from a _snippet folder ensure we eat the _snippet folder
310
+ // as it's not part of url by chopping of the extra parent navigation
311
+ if ( url . StartsWith ( "../" ) && context . DocumentationFileLookup ( context . MarkdownSourcePath ) is SnippetFile snippetFile )
312
+ url = url . Substring ( 3 ) ;
307
313
314
+ // TODO check through context.DocumentationFileLookup if file is index vs "index.md" check
315
+ var markdownPath = context . MarkdownSourcePath ;
308
316
// if the current path is an index e.g /reference/cloud-k8s/
309
317
// './' current path lookups should be relative to sub-path.
310
318
// If it's not e.g /reference/cloud-k8s/api-docs/ these links should resolve on folder up.
311
- var siblingsGoToCurrent = url . StartsWith ( "./" ) && markdownPath == "index.md" ;
312
319
var lastIndexPath = subPrefix . LastIndexOf ( '/' ) ;
313
- if ( lastIndexPath >= 0 && ! siblingsGoToCurrent )
320
+ if ( lastIndexPath >= 0 && markdownPath . Name != "index.md" )
314
321
subPrefix = subPrefix [ ..lastIndexPath ] ;
315
-
316
322
var combined = '/' + Path . Combine ( subPrefix , url ) . TrimStart ( '/' ) ;
317
323
url = Path . GetFullPath ( combined ) ;
318
324
}
@@ -341,6 +347,7 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
341
347
url = url [ ..^ 5 ] ;
342
348
343
349
link . Url = string . IsNullOrEmpty ( anchor ) ? url : $ "{ url } #{ anchor } ";
350
+
344
351
}
345
352
346
353
private static bool IsCrossLink ( [ NotNullWhen ( true ) ] Uri ? uri ) =>
0 commit comments