microsoft / microsoft/aspire.dev

CLI: `docs get` command displays code blocks without indentation

Open
#900 1 comment 0 reactions 1 assignee View on GitHub

@IEvangelist is already working on this.

Since Jun 2, 2026.

bug
Dominant language
MDX
Stars
193
Forks
87
Avg merge
1d 22h
Merged PRs (30d)
73

Description

Description

When running aspire docs get <slug>, the rendered markdown output displays code blocks with all internal indentation/whitespace stripped. This makes code examples difficult to read.

Root Cause

The documentation content is sourced from the llms.txt file (from aspire.dev), which appears to deliver code blocks in a minified/compacted single-line format with internal whitespace removed.

The NormalizeContent method in DocsIndexService.cs attempts to reconstruct proper markdown structure from this compacted form. For multi-line code blocks it preserves the content as-is, but for single-line code blocks (where the entire block is collapsed onto one line), the NormalizeCodeBlock method splits on the first whitespace to detect the language identifier and wraps the remaining content — but it cannot restore the original indentation since that information is already lost in the source data.

Additionally, the LeadingWhitespaceRegex ((?m)^[ \t]+) in NormalizeMarkdownSegment strips all leading whitespace from lines that are not inside fenced code blocks as detected by MarkdownFenceBlockRegex. If any code block is not properly detected as fenced (e.g., edge cases in the regex matching), its indentation would also be stripped.

Relevant Code

  • src/Aspire.Cli/Documentation/Docs/DocsIndexService.csNormalizeContent, NormalizeCodeBlock, NormalizeMarkdownSegment
  • MarkdownFenceBlockRegex: ```.*?``` with RegexOptions.Singleline
  • LeadingWhitespaceRegex: (?m)^[ \t]+

Steps to Reproduce

  1. Run aspire docs get <any-slug-with-code-examples>
  2. Observe that code blocks in the output have no indentation

Expected Behavior

Code blocks should display with proper indentation preserved, making them readable and copy-paste friendly.

Possible Solutions

  1. Fix the upstream llms.txt source to preserve whitespace in code blocks
  2. Add heuristic re-indentation in NormalizeCodeBlock for single-line code blocks (e.g., insert newlines before {, after ;, and apply indentation based on brace depth)
  3. Ensure MarkdownFenceBlockRegex correctly identifies all fenced code blocks before LeadingWhitespaceRegex is applied

Area

area-cli

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.