Skip to content

Commit 73108e3

Browse files
committed
Make method more general for all file extensions
1 parent bc50a2e commit 73108e3

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public static void RenderBlockWithIndentation(LlmMarkdownRenderer renderer, Mark
4848
return url;
4949

5050
// For documentation URLs (starting with /docs/), convert to .md format for LLM consistency
51-
// BUT exclude image files which should keep their original extensions
52-
if (!string.IsNullOrEmpty(url) && url.StartsWith("/docs/", StringComparison.Ordinal) && !IsImageFile(url))
51+
// BUT exclude files with extensions (images, PDFs, etc.) which should keep their original extensions
52+
if (!string.IsNullOrEmpty(url) && url.StartsWith("/docs/", StringComparison.Ordinal) && !HasFileExtension(url))
5353
{
5454
var markdownUrl = ConvertToMarkdownUrl(url);
5555
return MakeAbsoluteUrl(renderer.BuildContext.CanonicalBaseUrl, markdownUrl);
@@ -118,12 +118,30 @@ private static string ConvertToMarkdownUrl(string url)
118118
}
119119

120120
/// <summary>
121-
/// Checks if a URL path points to an image file
121+
/// Checks if a URL path points to a file with an extension (not a documentation page)
122122
/// </summary>
123-
private static bool IsImageFile(string path)
123+
private static bool HasFileExtension(string path)
124124
{
125-
var extension = Path.GetExtension(path).ToLowerInvariant();
126-
return extension is ".png" or ".jpg" or ".jpeg" or ".gif" or ".svg" or ".webp" or ".bmp" or ".ico";
125+
try
126+
{
127+
// Try to parse as URI to handle query parameters and fragments
128+
if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uri))
129+
{
130+
// Get the path component without query/fragment
131+
var pathOnly = uri.IsAbsoluteUri ? uri.AbsolutePath : uri.OriginalString.Split('?', '#')[0];
132+
var ext = Path.GetExtension(pathOnly);
133+
return !string.IsNullOrEmpty(ext);
134+
}
135+
136+
// Fallback to direct path parsing
137+
var extension = Path.GetExtension(path);
138+
return !string.IsNullOrEmpty(extension);
139+
}
140+
catch
141+
{
142+
// If parsing fails, assume it's a documentation page
143+
return false;
144+
}
127145
}
128146

129147
}

0 commit comments

Comments
 (0)