Skip to content

Use Markdig for Aspire CLI docs rendering#16342

Merged
JamesNK merged 22 commits intomainfrom
davidfowl/markdig-docs-rendering
Apr 24, 2026
Merged

Use Markdig for Aspire CLI docs rendering#16342
JamesNK merged 22 commits intomainfrom
davidfowl/markdig-docs-rendering

Conversation

@davidfowl
Copy link
Copy Markdown
Contributor

@davidfowl davidfowl commented Apr 20, 2026

Description

Replace the Aspire CLI docs rendering path with a Markdig-backed parser for DisplayMarkdown(...) so aspire docs can render richer markdown reliably in interactive terminals while still producing readable plain-text output for redirected/non-interactive streams.

This change keeps the scope narrow by routing only the docs display/plain-text conversion path through Markdig and leaving the older ConvertToSpectre(...) helper in place for unrelated callers. It also fixes nested list indentation, avoids duplicating bare URLs in plain-text output, preserves unsupported markdown as visible text instead of dropping it, adds broader regression coverage, adds a deterministic CLI E2E docs smoke test, and confirms the CLI still publishes and runs under NativeAOT. Follow-up work on the branch also adds a markdown feature showcase path in RenderCommand, reduces renderer allocations, fixes narrow plain-text table column widths, and strengthens the regression coverage for markup-sensitive link targets.

Fixes #16339

Validation:

  • dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj -- --filter-class "*.DocsCacheTests" --filter-class "*.DocsFetcherTests" --filter-class "*.DocsIndexServiceTests" --filter-class "*.ConsoleInteractionServiceTests" --filter-class "*.MarkdownToSpectreConverterTests" --filter-class "*.DocsCommandTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • ASPIRE_E2E_ARCHIVE=/tmp/aspire-e2e.tar.gz dotnet test tests/Aspire.Cli.EndToEnd.Tests/Aspire.Cli.EndToEnd.Tests.csproj -- --filter-method "*.DocsCommand_RendersInteractiveMarkdownFromLocalSource" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • dotnet publish src/Aspire.Cli/Aspire.Cli.csproj -r osx-arm64 -c Debug

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings April 20, 2026 20:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16342

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16342"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Aspire CLI’s docs/markdown display path to use a Markdig-based parser for DisplayMarkdown(...), improving fidelity for richer markdown (tables, nested lists, autolinks) in interactive terminals while keeping a readable plain-text fallback for redirected/non-interactive output.

Changes:

  • Add a Markdig-backed markdown parsing/rendering path via MarkdownToSpectreConverter.ConvertToRenderable(...) and route ConsoleInteractionService.DisplayMarkdown(...) through it.
  • Extend markdown conversion test coverage (tables, autolinks, nested list indentation, quoted structured content).
  • Add a deterministic CLI E2E smoke test for interactive aspire docs get rendering from a local docs source.
Show a summary per file
File Description
src/Aspire.Cli/Utils/MarkdownToSpectreConverter.cs Introduces Markdig parsing and a renderable-based Spectre output path (including table support).
src/Aspire.Cli/Interaction/ConsoleInteractionService.cs Switches DisplayMarkdown interactive rendering from markup strings to Spectre renderables.
src/Aspire.Cli/Aspire.Cli.csproj Adds Markdig dependency to Aspire CLI.
tests/Aspire.Cli.Tests/Utils/MarkdownToSpectreConverterTests.cs Adds regression coverage for tables, autolinks, nested lists, and quote/code/link scenarios.
tests/Aspire.Cli.Tests/Interaction/ConsoleInteractionServiceTests.cs Strengthens assertions for markdown display and adds an interactive table rendering test.
tests/Aspire.Cli.Tests/Commands/DocsCommandTests.cs Adds a rich-markdown docs regression test and makes the test docs index service more configurable.
tests/Aspire.Cli.EndToEnd.Tests/DocsCommandE2ETests.cs Adds an E2E interactive rendering smoke test for aspire docs get.

Copilot's findings

  • Files reviewed: 7/7 changed files
  • Comments generated: 3

Comment on lines +399 to +400
var linkText = string.IsNullOrEmpty(text) ? url.EscapeMarkup() : text;
return $"[cyan][link={url}]{linkText}[/][/]";
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When constructing Spectre hyperlink markup, the link target should be escaped (e.g., with Markup.Escape / EscapeMarkup) before placing it in the [link=...] attribute. Currently the raw URL is inserted, so a URL containing ']' (or other markup-sensitive characters) can break markup parsing or allow unintended markup injection from docs content.

Suggested change
var linkText = string.IsNullOrEmpty(text) ? url.EscapeMarkup() : text;
return $"[cyan][link={url}]{linkText}[/][/]";
var escapedUrl = url.EscapeMarkup();
var linkText = string.IsNullOrEmpty(text) ? escapedUrl : text;
return $"[cyan][link={escapedUrl}]{linkText}[/][/]";

Copilot uses AI. Check for mistakes.
{
var repoRoot = CliE2ETestHelpers.GetRepoRoot();
var strategy = CliInstallStrategy.Detect();
var workspace = TemporaryWorkspace.Create(output);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TemporaryWorkspace implements IDisposable and is responsible for deleting the on-disk workspace on success. This test creates a workspace without disposing it, which will leak temp directories across runs (unless preserved). Use a using declaration or otherwise ensure it gets disposed at the end of the test.

Suggested change
var workspace = TemporaryWorkspace.Create(output);
using var workspace = TemporaryWorkspace.Create(output);

Copilot uses AI. Check for mistakes.
Comment on lines +210 to +211
var executionContext = new CliExecutionContext(new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo("."), new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-runtimes")), new DirectoryInfo(Path.Combine(Path.GetTempPath(), "aspire-test-logs")), "test.log");
var interactionService = CreateInteractionService(console, executionContext);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test uses fixed paths under Path.GetTempPath() ("aspire-test-runtimes" / "aspire-test-logs"). Using shared fixed temp directories can cause cross-test interference when tests run in parallel or when prior runs leave state behind. Prefer a unique temp subdirectory per test run (e.g., Directory.CreateTempSubdirectory()) and create runtime/log directories under it.

Copilot uses AI. Check for mistakes.
ListBlock list => RenderListToPlainText(list),
CodeBlock codeBlock => GetRawCodeText(codeBlock).TrimEnd('\r', '\n'),
MarkdigTable table => RenderTableToPlainText(table),
_ => string.Empty
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all the types that need to be handled?

Is the list complete? Is skipping unknown items the right thing to do?

Comment thread src/Aspire.Cli/Utils/MarkdownToSpectreConverter.cs Outdated
}
}

private static string IndentBlock(string content, string prefix)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IndentedTextWriter?

davidfowl and others added 3 commits April 22, 2026 12:03
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl davidfowl force-pushed the davidfowl/markdig-docs-rendering branch from 1ac5703 to 012347d Compare April 22, 2026 19:56
davidfowl and others added 2 commits April 22, 2026 20:35
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the Markdig-backed markdown rendering changes. Found 2 issues: 1 test weakness (markup-sensitive link target test doesn't verify output correctness) and 1 correctness issue (plain-text table column misalignment with narrow columns).

Comment thread src/Aspire.Cli/Utils/MarkdownToSpectreConverter.cs Outdated
Comment thread tests/Aspire.Cli.Tests/Utils/MarkdownToSpectreConverterTests.cs Outdated
JamesNK and others added 4 commits April 23, 2026 15:01
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JamesNK
Copy link
Copy Markdown
Member

JamesNK commented Apr 23, 2026

I added the same showcase I use to test markdown in the dashboard.

For reference, this is what it looks like in GitHub: https://gist.github.com/JamesNK/75d2acb11dcb187983ea89446e3b2b00

Output:
image
image
image
image

@JamesNK JamesNK force-pushed the davidfowl/markdig-docs-rendering branch from 3d45e31 to 0c86732 Compare April 24, 2026 00:48
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 75 recordings uploaded (commit 2810ef6)

View all recordings
Status Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterAppCore ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24871444043

@JamesNK JamesNK merged commit 3ddbf1c into main Apr 24, 2026
560 of 563 checks passed
@github-actions github-actions Bot added this to the 13.3 milestone Apr 24, 2026
@JamesNK JamesNK deleted the davidfowl/markdig-docs-rendering branch April 24, 2026 05:00
@aspire-repo-bot
Copy link
Copy Markdown
Contributor

No documentation PR is needed for this change.

This PR replaces the internal markdown rendering engine for the aspire docs command with Markdig, improving rendering quality in interactive terminals and plain-text output in non-interactive streams. Since this is an internal implementation refactoring with no new public APIs, no new user-facing features, and no changes to documented behavior or commands, the existing docs coverage remains accurate. The PR author also confirmed this in the checklist.

Generated by PR Documentation Check for issue #16342 · ● 119.9K ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using Markdig for Aspire CLI docs rendering

4 participants