Skip to content

fix: dedent <code> blocks in <example> elements before markdown rendering - #28

Merged
Malcolmnixon merged 2 commits into
mainfrom
fix/example-code-block-dedent
Jun 18, 2026
Merged

Malcolmnixon merged 2 commits into
mainfrom
fix/example-code-block-dedent

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

.Trim() on raw element content only stripped the leading newline and first line's indentation as one contiguous block, leaving all subsequent lines carrying their original XML indentation (typically 16 spaces). This caused multi-line code blocks to render with line 1 flush-left and all remaining lines over-indented.

Add DedentCode() helper that computes the minimum leading-whitespace across all non-blank lines, strips that prefix uniformly from every line, and removes leading/trailing blank lines. Replace both .Trim() calls on code content with DedentCode():

  • el.Value.Trim() (no--children fallback path)
  • codeElement.Value.Trim() (mixed-content loop)

Add five regression tests covering: uniform indent, mixed indent with preserved relative indentation, single-line code, blank lines in the middle, and the no-code-children fallback path.

Update design and verification docs for XmlDocReader to describe the dedent algorithm and the new acceptance criteria.

…ring

.Trim() on raw <code> element content only stripped the leading newline
and first line's indentation as one contiguous block, leaving all
subsequent lines carrying their original XML indentation (typically 16
spaces). This caused multi-line code blocks to render with line 1
flush-left and all remaining lines over-indented.

Add DedentCode() helper that computes the minimum leading-whitespace
across all non-blank lines, strips that prefix uniformly from every
line, and removes leading/trailing blank lines. Replace both .Trim()
calls on code content with DedentCode():
- el.Value.Trim() (no-<code>-children fallback path)
- codeElement.Value.Trim() (mixed-content loop)

Add five regression tests covering: uniform indent, mixed indent with
preserved relative indentation, single-line code, blank lines in the
middle, and the no-code-children fallback path.

Update design and verification docs for XmlDocReader to describe the
dedent algorithm and the new acceptance criteria.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves how XmlDocReader.GetExampleParts normalizes XML doc <example> content by dedenting multi-line <code> blocks before Markdown rendering, preventing over-indented lines caused by XML formatting whitespace.

Changes:

  • Replace .Trim() usage on extracted <code> text with a new DedentCode() helper for consistent multi-line dedentation.
  • Add regression tests covering uniform/mixed indentation, single-line code, blank lines, and the no-<code> fallback path.
  • Update design/verification documentation and extend cspell dictionary for the new terminology.

Reviewed changes

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

Show a summary per file
File Description
src/ApiMark.DotNet/XmlDocReader.cs Introduces DedentCode() and applies it to <code> blocks and the no-<code> fallback path in GetExampleParts.
test/ApiMark.DotNet.Tests/XmlDocReaderTests.cs Adds 5 regression tests validating dedentation behavior and edge cases.
docs/design/api-mark-dot-net/xml-doc-reader.md Documents the dedentation algorithm and where it is applied.
docs/verification/api-mark-dot-net/xml-doc-reader.md Expands acceptance criteria and test scenarios for dedentation behavior.
.cspell.yaml Adds “dedentation” and “dedented” to the project dictionary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ApiMark.DotNet/XmlDocReader.cs Outdated
After stripping the common indent, lines that originally carried only
indentation (more spaces than minIndent) could be left as whitespace-
only strings rather than truly empty lines. This introduced trailing
spaces into fenced code block output, contradicting the comment that
blank lines are preserved as empty.

Add a second .Select() pass that maps any whitespace-only line to
string.Empty after the prefix-strip step.

Add regression test: BlankLineWithExtraIndent_NormalizesToEmptyLine.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Malcolmnixon
Malcolmnixon merged commit 84dcaea into main Jun 18, 2026
15 checks passed
@Malcolmnixon
Malcolmnixon deleted the fix/example-code-block-dedent branch June 18, 2026 13:36
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.

2 participants