Fix markdown not supporting absolute resource paths

Enhanced the logic for resolving image and file paths in MarkdownPanel to better handle both absolute and relative paths, ensuring compatibility with Windows path formats and improving file existence checks.
This commit is contained in:
ema
2026-01-16 11:40:56 +08:00
parent d7be2aad13
commit aaf78abf3c

View File

@@ -124,7 +124,19 @@ public class MarkdownPanel : WebpagePanel
}
else
{
var localPath = _fallbackPath + Uri.UnescapeDataString(requestedUri.AbsolutePath).Replace('/', '\\');
// URL path is encoded, e.g. "%20" for spaces.
var unescapedAbsolutePath = Uri.UnescapeDataString(requestedUri.AbsolutePath);
// Convert URL path to Windows path format (e.g. "/C:/Users/..." -> "C:\Users\...")
var potentialAbsolutePath = unescapedAbsolutePath.TrimStart('/').Replace('/', '\\');
string localPath;
// Check if it is an absolute path (e.g. ![Alt](C:\Path\To\Image.png))
if (Path.IsPathRooted(potentialAbsolutePath) && File.Exists(potentialAbsolutePath))
localPath = potentialAbsolutePath;
else
// Treat as relative path (e.g. ![Alt](Image.png))
localPath = _fallbackPath + unescapedAbsolutePath.Replace('/', '\\');
if (File.Exists(localPath))
{