@@ -168,10 +168,10 @@ private static void ProcessInternalLink(InlineProcessor processor, LinkInline li
168
168
{
169
169
var ( url , anchor ) = SplitUrlAndAnchor ( link . Url ?? string . Empty ) ;
170
170
var includeFrom = GetIncludeFromPath ( url , context ) ;
171
-
171
+ var file = ResolveFile ( context , url ) ;
172
172
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 ) ;
175
175
}
176
176
177
177
private static ( string url , string ? anchor ) SplitUrlAndAnchor ( string fullUrl )
@@ -195,12 +195,11 @@ private static void ValidateInternalUrl(InlineProcessor processor, string url, s
195
195
processor . EmitError ( line , column , length , $ "`{ url } ` does not exist. resolved to `{ pathOnDisk } ") ;
196
196
}
197
197
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 )
199
199
{
200
200
if ( link . FirstChild != null && string . IsNullOrEmpty ( anchor ) )
201
201
return ;
202
202
203
- var file = ResolveFile ( context , url ) ;
204
203
var markdown = context . GetDocumentationFile ? . Invoke ( file ) as MarkdownFile ;
205
204
206
205
if ( markdown == null )
@@ -236,15 +235,26 @@ private static void ValidateAnchor(InlineProcessor processor, MarkdownFile markd
236
235
processor . EmitError ( line , column , length , $ "`{ anchor } ` does not exist in { markdown . FileName } .") ;
237
236
}
238
237
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 )
240
239
{
240
+ var urlPathPrefix = context . Build . UrlPathPrefix ?? string . Empty ;
241
+
242
+ if ( ! url . StartsWith ( '/' ) && ! string . IsNullOrEmpty ( url ) )
243
+ url = GetRootRelativePath ( context , file ) ;
244
+
241
245
if ( url . EndsWith ( ".md" ) )
242
246
url = Path . ChangeExtension ( url , ".html" ) ;
243
247
244
- if ( url . StartsWith ( "/" ) && ! string . IsNullOrWhiteSpace ( urlPathPrefix ) )
248
+ if ( ! string . IsNullOrWhiteSpace ( url ) && ! string . IsNullOrWhiteSpace ( urlPathPrefix ) )
245
249
url = $ "{ urlPathPrefix . TrimEnd ( '/' ) } { url } ";
246
250
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 ) ;
248
258
}
249
259
250
260
private static bool IsCrossLink ( Uri ? uri ) =>
0 commit comments