File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -418,6 +418,16 @@ public void UpdateCurrentDirectory(string newPath)
418418 }
419419 }
420420
421+ /// <summary>
422+ /// Directly sets the working directory for relative link resolution without modifying basePath.
423+ /// Used when navigating between articles within a known-safe document root.
424+ /// </summary>
425+ public void SetCurrentDirectory ( string directory )
426+ {
427+ directory = directory . Replace ( '/' , Path . DirectorySeparatorChar ) . TrimEnd ( Path . DirectorySeparatorChar ) ;
428+ currentDirectory = Path . GetFullPath ( directory ) ;
429+ }
430+
421431 public string GetRelativePath ( string fullPath )
422432 {
423433 return Path . GetRelativePath ( currentDirectory , fullPath ) ;
Original file line number Diff line number Diff line change @@ -210,12 +210,21 @@ public void SetContentUri(string contentUri)
210210 {
211211 if ( ! string . IsNullOrWhiteSpace ( contentUri ) )
212212 {
213- // Use the directory containing the file as the base path so relative links resolve correctly.
214- // If contentUri is already a directory, GetDirectoryName returns the parent, so check first.
215213 var directory = File . Exists ( contentUri )
216214 ? Path . GetDirectoryName ( contentUri )
217215 : contentUri ;
218- pathHandler = new MarkdownPathHandler ( directory ) ;
216+
217+ if ( pathHandler == null )
218+ {
219+ pathHandler = new MarkdownPathHandler ( directory ) ;
220+ }
221+ else
222+ {
223+ // Preserve the existing basePath (set at construction to the doc root) so that
224+ // cross-directory relative links don't throw "outside base directory".
225+ // Only shift currentDirectory to resolve links relative to the new article.
226+ pathHandler . SetCurrentDirectory ( directory ) ;
227+ }
219228 }
220229 }
221230
You can’t perform that action at this time.
0 commit comments