@@ -42,16 +42,26 @@ public static void RenderBlockWithIndentation(LlmMarkdownRenderer renderer, Mark
4242 /// Converts relative URLs to absolute URLs using BuildContext.CanonicalBaseUrl for better LLM consumption
4343 /// </summary>
4444 public static string ? MakeAbsoluteUrl ( LlmMarkdownRenderer renderer , string ? url )
45+ {
46+ if ( renderer . BuildContext . CanonicalBaseUrl == null )
47+ return url ;
48+
49+ return MakeAbsoluteUrl ( renderer . BuildContext . CanonicalBaseUrl , url ) ;
50+ }
51+
52+ /// <summary>
53+ /// Converts relative URLs to absolute URLs for LLM consumption
54+ /// </summary>
55+ public static string ? MakeAbsoluteUrl ( Uri ? baseUri , string ? url )
4556 {
4657 if (
4758 string . IsNullOrEmpty ( url )
48- || renderer . BuildContext . CanonicalBaseUrl == null
59+ || baseUri == null
4960 || Uri . IsWellFormedUriString ( url , UriKind . Absolute )
5061 || ! Uri . IsWellFormedUriString ( url , UriKind . Relative ) )
5162 return url ;
5263 try
5364 {
54- var baseUri = renderer . BuildContext . CanonicalBaseUrl ;
5565 var absoluteUri = new Uri ( baseUri , url ) ;
5666 return absoluteUri . ToString ( ) ;
5767 }
@@ -62,24 +72,28 @@ public static void RenderBlockWithIndentation(LlmMarkdownRenderer renderer, Mark
6272 }
6373
6474 /// <summary>
65- /// Converts documentation URLs to absolute markdown URLs specifically for LLM consumption.
66- /// Transforms HTML paths to .md file paths and ensures they're absolute URLs.
75+ /// Converts documentation URLs to absolute markdown URLs for LLM consumption
6776 /// </summary>
68- /// <param name="url">The documentation URL to convert (e.g., "/docs/solutions/search/")</param>
69- /// <param name="baseUrl">The base URL to use (defaults to "https://www.elastic.co")</param>
70- /// <returns>Absolute markdown URL (e.g., "https://www.elastic.co/docs/solutions/search.md")</returns>
71- public static string ConvertToAbsoluteMarkdownUrl ( string url , string ? baseUrl = null )
77+ public static string MakeAbsoluteMarkdownUrl ( Uri baseUri , string ? url )
7278 {
7379 if ( string . IsNullOrEmpty ( url ) )
74- return url ;
80+ return string . Empty ;
81+
82+ // Convert to .md URL for LLM consumption
83+ var markdownUrl = ConvertToMarkdownUrl ( url ) ;
7584
76- baseUrl ??= "https://www.elastic.co" ;
85+ // Use the existing absolute URL logic
86+ return MakeAbsoluteUrl ( baseUri , markdownUrl ) ?? markdownUrl ;
87+ }
7788
78- // Convert HTML URLs to .md URLs for LLM consumption
79- // e.g., "/docs/solutions/search/" -> "https://www.elastic.co/docs/solutions/search.md"
89+ /// <summary>
90+ /// Converts documentation URL paths to .md file paths for LLM consumption
91+ /// </summary>
92+ private static string ConvertToMarkdownUrl ( string url )
93+ {
8094 var cleanUrl = url . TrimStart ( '/' ) ;
8195
82- // Remove "docs/" prefix if present for the markdown filename
96+ // Remove "docs/" prefix if present for the markdown filename, then add it back
8397 var markdownPath = cleanUrl ;
8498 if ( markdownPath . StartsWith ( "docs/" , StringComparison . Ordinal ) )
8599 markdownPath = markdownPath . Substring ( 5 ) ;
@@ -90,9 +104,9 @@ public static string ConvertToAbsoluteMarkdownUrl(string url, string? baseUrl =
90104 else if ( ! markdownPath . EndsWith ( ".md" , StringComparison . Ordinal ) )
91105 markdownPath += ".md" ;
92106
93- // Make absolute URL using the canonical base URL
94- return $ "{ baseUrl . TrimEnd ( '/' ) } /docs/{ markdownPath } ";
107+ return $ "/docs/{ markdownPath } ";
95108 }
109+
96110}
97111
98112/// <summary>
0 commit comments