Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static string RootPage(CliSchema schema, CliSupplementalDoc? supplemental
_ = sb.AppendLine("## Namespaces");
_ = sb.AppendLine();
foreach (var ns in schema.Namespaces)
AppendPageCard(sb, ns.Segment, $"./{ns.Segment}/index.md", ns.Summary);
AppendPageCard(sb, ns.Segment, $"./{ns.Segment}", ns.Summary);
}

if (schema.Environment?.Variables is { Count: > 0 } envVars)
Expand Down Expand Up @@ -129,7 +129,7 @@ public static string NamespacePage(
{
var depth = fullPath?.Length ?? 1;
var upPrefix = string.Concat(Enumerable.Repeat("../", depth));
var links = nsAliases.Select(a => $"[`{binaryName ?? a} {a}`]({upPrefix}{a}/index.md)");
var links = nsAliases.Select(a => $"[`{binaryName ?? a} {a}`]({upPrefix}{a})");
_ = sb.AppendLine($"Also accessible as {string.Join(", ", links)}.");
_ = sb.AppendLine();
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public static string NamespacePage(
_ = sb.AppendLine("## Sub-namespaces");
_ = sb.AppendLine();
foreach (var sub in subNamespaces)
AppendPageCard(sb, sub.Segment, $"./{sub.Segment}/index.md", sub.Summary);
AppendPageCard(sb, sub.Segment, $"./{sub.Segment}", sub.Summary);
}

var options = ns.Options ?? [];
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Markdown/Extensions/CliReference/CliRootFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public CliRootFile(
{
_schema = schema;
_supplementalDoc = supplementalDoc;
_title = string.IsNullOrWhiteSpace(title) ? schema.Name : title;
_navigationTitle = string.IsNullOrWhiteSpace(navigationTitle) ? $"{schema.Name} CLI" : navigationTitle;
_title = string.IsNullOrWhiteSpace(title) ? schema.Name : title.Trim();
_navigationTitle = string.IsNullOrWhiteSpace(navigationTitle) ? $"{schema.Name} CLI" : navigationTitle.Trim();
Title = _title;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public override void FinalizeAndValidate(ParserContext context)
: relativeToSource;

ResolvedUrl = "/" + withoutExtension.Replace('\\', '/');

// Apply URL path prefix so links work in preview/sub-path deployments (same logic as DiagnosticLinkInlineParser)
var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty;
if (!string.IsNullOrWhiteSpace(urlPathPrefix) && !ResolvedUrl.StartsWith(urlPathPrefix, StringComparison.OrdinalIgnoreCase))
ResolvedUrl = $"{urlPathPrefix.TrimEnd('/')}{ResolvedUrl}";
}

[GeneratedRegex(@"^\[([^\]]+)\]\(([^)]+)\)$")]
Expand Down
Loading