@@ -168,10 +168,10 @@ private static void ProcessInternalLink(InlineProcessor processor, LinkInline li
168168 {
169169 var ( url , anchor ) = SplitUrlAndAnchor ( link . Url ?? string . Empty ) ;
170170 var includeFrom = GetIncludeFromPath ( url , context ) ;
171-
171+ var file = ResolveFile ( context , url ) ;
172172 ValidateInternalUrl ( processor , url , includeFrom , line , column , length , context ) ;
173- ProcessLinkText ( processor , link , context , url , anchor , line , column , length ) ;
174- UpdateLinkUrl ( link , url , anchor , context . Build . UrlPathPrefix ?? string . Empty ) ;
173+ ProcessLinkText ( processor , link , context , url , anchor , line , column , length , file ) ;
174+ UpdateLinkUrl ( link , url , context , anchor , file ) ;
175175 }
176176
177177 private static ( string url , string ? anchor ) SplitUrlAndAnchor ( string fullUrl )
@@ -195,12 +195,11 @@ private static void ValidateInternalUrl(InlineProcessor processor, string url, s
195195 processor . EmitError ( line , column , length , $ "`{ url } ` does not exist. resolved to `{ pathOnDisk } ") ;
196196 }
197197
198- private static void ProcessLinkText ( InlineProcessor processor , LinkInline link , ParserContext context , string url , string ? anchor , int line , int column , int length )
198+ private static void ProcessLinkText ( InlineProcessor processor , LinkInline link , ParserContext context , string url , string ? anchor , int line , int column , int length , IFileInfo file )
199199 {
200200 if ( link . FirstChild != null && string . IsNullOrEmpty ( anchor ) )
201201 return ;
202202
203- var file = ResolveFile ( context , url ) ;
204203 var markdown = context . GetDocumentationFile ? . Invoke ( file ) as MarkdownFile ;
205204
206205 if ( markdown == null )
@@ -236,15 +235,26 @@ private static void ValidateAnchor(InlineProcessor processor, MarkdownFile markd
236235 processor . EmitError ( line , column , length , $ "`{ anchor } ` does not exist in { markdown . FileName } .") ;
237236 }
238237
239- private static void UpdateLinkUrl ( LinkInline link , string url , string ? anchor , string urlPathPrefix )
238+ private static void UpdateLinkUrl ( LinkInline link , string url , ParserContext context , string ? anchor , IFileInfo file )
240239 {
240+ var urlPathPrefix = context . Build . UrlPathPrefix ?? string . Empty ;
241+
242+ if ( ! url . StartsWith ( '/' ) && ! string . IsNullOrEmpty ( url ) )
243+ url = GetRootRelativePath ( context , file ) ;
244+
241245 if ( url . EndsWith ( ".md" ) )
242246 url = Path . ChangeExtension ( url , ".html" ) ;
243247
244- if ( url . StartsWith ( "/" ) && ! string . IsNullOrWhiteSpace ( urlPathPrefix ) )
248+ if ( ! string . IsNullOrWhiteSpace ( url ) && ! string . IsNullOrWhiteSpace ( urlPathPrefix ) )
245249 url = $ "{ urlPathPrefix . TrimEnd ( '/' ) } { url } ";
246250
247- link . Url = ! string . IsNullOrEmpty ( anchor ) ? $ "{ url } #{ anchor } " : url ;
251+ link . Url = string . IsNullOrEmpty ( anchor ) ? url : $ "{ url } #{ anchor } ";
252+ }
253+
254+ private static string GetRootRelativePath ( ParserContext context , IFileInfo file )
255+ {
256+ var docsetDirectory = context . Configuration . SourceFile . Directory ;
257+ return file . FullName . Replace ( docsetDirectory ! . FullName , string . Empty ) ;
248258 }
249259
250260 private static bool IsCrossLink ( Uri ? uri ) =>
0 commit comments