@@ -289,11 +289,14 @@ private static IFileInfo ResolveFile(ParserContext context, string url) =>
289289 private static void ValidateAnchor ( InlineProcessor processor , MarkdownFile markdown , string anchor , LinkInline link )
290290 {
291291 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 } .") ;
293293 }
294294
295295 private static void UpdateLinkUrl ( LinkInline link , string url , ParserContext context , string ? anchor )
296296 {
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
297300 var urlPathPrefix = context . Build . UrlPathPrefix ?? string . Empty ;
298301
299302 if ( ! url . StartsWith ( '/' ) && ! string . IsNullOrEmpty ( url ) )
@@ -303,16 +306,19 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
303306 ? context . CurrentUrlPath [ urlPathPrefix . Length ..]
304307 : urlPathPrefix ;
305308
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 ) ;
307313
314+ // TODO check through context.DocumentationFileLookup if file is index vs "index.md" check
315+ var markdownPath = context . MarkdownSourcePath ;
308316 // if the current path is an index e.g /reference/cloud-k8s/
309317 // './' current path lookups should be relative to sub-path.
310318 // 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" ;
312319 var lastIndexPath = subPrefix . LastIndexOf ( '/' ) ;
313- if ( lastIndexPath >= 0 && ! siblingsGoToCurrent )
320+ if ( lastIndexPath >= 0 && markdownPath . Name != "index.md" )
314321 subPrefix = subPrefix [ ..lastIndexPath ] ;
315-
316322 var combined = '/' + Path . Combine ( subPrefix , url ) . TrimStart ( '/' ) ;
317323 url = Path . GetFullPath ( combined ) ;
318324 }
@@ -341,6 +347,7 @@ private static void UpdateLinkUrl(LinkInline link, string url, ParserContext con
341347 url = url [ ..^ 5 ] ;
342348
343349 link . Url = string . IsNullOrEmpty ( anchor ) ? url : $ "{ url } #{ anchor } ";
350+
344351 }
345352
346353 private static bool IsCrossLink ( [ NotNullWhen ( true ) ] Uri ? uri ) =>
0 commit comments