Skip to content

Improve CLI docs markdown rendering and simplify DocsGetCommand#16428

Open
JamesNK wants to merge 6 commits intomainfrom
jamesnk/docs-markdown
Open

Improve CLI docs markdown rendering and simplify DocsGetCommand#16428
JamesNK wants to merge 6 commits intomainfrom
jamesnk/docs-markdown

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Apr 24, 2026

Description

Improve how the CLI renders documentation markdown fetched from aspire.dev.

Changes

Simplify DocsGetCommand: Replace the manual WrapMarkdownForConsole / SplitMarkdownBlocks logic with a single DisplayMarkdown call using maxWidth: 100. The old code manually word-wrapped, split blocks, and re-assembled markdown — all of which is now handled by the markdown converter and Spectre.Console.

Add maxWidth parameter to DisplayMarkdown: The IInteractionService.DisplayMarkdown method now accepts an optional maxWidth parameter so callers can cap the rendering width (e.g., for wide tables in docs or resource commands).

Fix paragraph trailing newline in MarkdownToSpectreConverter: Trim trailing \n from paragraph blocks so that a paragraph followed by a table produces exactly one blank line instead of two when rendered via ConvertToRenderable.

Improve NormalizeContent in DocsIndexService: The llms.txt format strips most whitespace from markdown. Added regex passes to insert blank lines after headings, tables, and list items so the content parses as valid markdown. Made the method internal for testability and added xmldoc explaining its purpose.

Resource command markdown: Set maxWidth: 100 when displaying markdown from resource command results.

Cleanup: Removed a leftover Debugger.Launch() call from DocsGetCommand.

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
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

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

github-actions Bot commented Apr 24, 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 -- 16428

Or

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

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 targets improved markdown rendering in the Aspire CLI by tightening paragraph/table spacing and introducing a width cap for markdown rendering in certain command outputs.

Changes:

  • Trim trailing newlines when converting markdown paragraphs to Spectre markup to avoid extra blank lines before tables.
  • Add an optional maxWidth parameter to IInteractionService.DisplayMarkdown and apply it when rendering resource command markdown output.
  • Expand docs content normalization logic and add unit tests covering normalization and a heading+paragraph+table rendering scenario.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Utils/MarkdownToSpectreConverterTests.cs Stabilizes Spectre console output and adds an exact-output test for paragraph+table spacing.
tests/Aspire.Cli.Tests/TestServices/TestInteractionService.cs Updates test stub to match new DisplayMarkdown(..., maxWidth) signature.
tests/Aspire.Cli.Tests/TestServices/TestExtensionInteractionService.cs Updates test stub to match new DisplayMarkdown(..., maxWidth) signature.
tests/Aspire.Cli.Tests/Templating/DotNetTemplateFactoryTests.cs Updates local test interaction stub to match new DisplayMarkdown signature.
tests/Aspire.Cli.Tests/Projects/ExtensionGuestLauncherTests.cs Updates local test interaction stub to match new DisplayMarkdown signature.
tests/Aspire.Cli.Tests/Mcp/Docs/DocsIndexServiceTests.cs Adds extensive unit tests for docs markdown normalization behavior.
tests/Aspire.Cli.Tests/Commands/UpdateCommandTests.cs Updates wrapper to forward maxWidth to the inner interaction service.
tests/Aspire.Cli.Tests/Commands/PublishCommandPromptingIntegrationTests.cs Updates test interaction implementation to match new DisplayMarkdown signature.
tests/Aspire.Cli.Tests/Commands/DocsCommandTests.cs Removes tests for markdown wrapping logic that was deleted from DocsGetCommand.
src/Aspire.Cli/Utils/Markdown/MarkdownToSpectreConverter.Markup.cs Trims trailing newlines after paragraph conversion to avoid double-blank-line output.
src/Aspire.Cli/Interaction/IInteractionService.cs Adds optional maxWidth parameter to DisplayMarkdown.
src/Aspire.Cli/Interaction/ExtensionInteractionService.cs Updates signature to accept maxWidth (but currently doesn’t forward it to console rendering).
src/Aspire.Cli/Interaction/ConsoleInteractionService.cs Implements maxWidth by temporarily adjusting the target console profile width.
src/Aspire.Cli/Documentation/Docs/DocsIndexService.cs Makes NormalizeContent internal and adds normalization rules for spacing after headings/tables/lists.
src/Aspire.Cli/Commands/ResourceCommandHelper.cs Uses maxWidth: 100 when displaying markdown results from resource commands.
src/Aspire.Cli/Commands/DocsGetCommand.cs Removes prior wrapping/splitting logic, but currently contains debugger launch + hard-coded markdown output.
Comments suppressed due to low confidence (3)

src/Aspire.Cli/Commands/DocsGetCommand.cs:104

  • This command currently prints a hard-coded markdown block (the API table) before printing doc.Content, which will duplicate/override the actual docs output and doesn't match the PR description. It looks like debugging/test scaffolding—please remove and only display the fetched document content (optionally with any intended formatting/wrapping).

        return ExitCodeConstants.Success;
    }
}

src/Aspire.Cli/Interaction/ExtensionInteractionService.cs:435

  • maxWidth is accepted by this method but not forwarded to the console renderer (_consoleInteractionService.DisplayMarkdown), so width limiting is ignored in extension mode. Pass maxWidth through (and ensure consoleOverride/maxWidth semantics stay consistent across modes).
    public void DisplayMarkdown(string markdown, ConsoleOutput? consoleOverride = null, int? maxWidth = null)
    {
        // Send raw markdown to extension (it can handle markdown natively)
        // Convert to Spectre markup for console display
        var result = _extensionTaskChannel.Writer.TryWrite(() => Backchannel.LogMessageAsync(LogLevel.Information, markdown, _cancellationToken));
        Debug.Assert(result);
        _consoleInteractionService.DisplayMarkdown(markdown, consoleOverride);
    }

src/Aspire.Cli/Commands/DocsGetCommand.cs:63

  • Debugger.Launch() should not be present in a shipped CLI command; it will prompt/attach a debugger every time aspire docs get runs (and can hang CI or user sessions). Remove this call before merging.
        using var activity = Telemetry.StartDiagnosticActivity(Name);

Comment thread src/Aspire.Cli/Interaction/ConsoleInteractionService.cs
@JamesNK JamesNK changed the title Fix paragraph spacing in markdown rendering and set maxWidth for resource commands Improve CLI docs markdown rendering and simplify DocsGetCommand Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 75 recordings uploaded (commit 15f5ee8)

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 #24877400952

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants