Skip to content

Commit 7600f1a

Browse files
committed
fixing mardown path navigation
1 parent 42dd3e1 commit 7600f1a

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

MarkdigAgg/AggMarkdownDocument.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

MarkdigAgg/MarkdownWidget.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)