Skip to content

Fix indentation not being preserved on first line in code fences#1672

Merged
st0012 merged 1 commit intoruby:masterfrom
extern-c:bugfix-1633-code-block-in-markdown-trims-leading-spaces-issue
Apr 9, 2026
Merged

Fix indentation not being preserved on first line in code fences#1672
st0012 merged 1 commit intoruby:masterfrom
extern-c:bugfix-1633-code-block-in-markdown-trims-leading-spaces-issue

Conversation

@extern-c
Copy link
Copy Markdown
Contributor

@extern-c extern-c commented Apr 6, 2026

Fix indentation not being preserved on first line in code fences (see issue #1633).

@extern-c extern-c requested a deployment to fork-preview-protection April 6, 2026 02:36 — with GitHub Actions Waiting
@extern-c extern-c force-pushed the bugfix-1633-code-block-in-markdown-trims-leading-spaces-issue branch from 055ac38 to b1f58b5 Compare April 6, 2026 02:41
@extern-c extern-c deployed to fork-preview-protection April 6, 2026 02:41 — with GitHub Actions Active
@st0012 st0012 requested a review from Copilot April 9, 2026 17:11
@matzbot
Copy link
Copy Markdown
Collaborator

matzbot commented Apr 9, 2026

🚀 Preview deployment available at: https://5ba05e5b.rdoc-6cd.pages.dev (commit: b1f58b5)

Copy link
Copy Markdown

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 fixes a GitHub-flavored Markdown parsing bug in RDoc where leading spaces on the first line of a fenced code block were being consumed, causing inconsistent indentation compared to subsequent lines (as reported in #1633).

Changes:

  • Adjust the CodeFence grammar to stop consuming post-newline indentation whitespace at the start of the fenced block content.
  • Regenerate/update the corresponding parser implementation in lib/rdoc/markdown.rb.
  • Add a regression test to ensure indentation is preserved on the first line of fenced code blocks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/rdoc/rdoc_markdown_test.rb Adds a regression test asserting first-line indentation inside code fences is preserved.
lib/rdoc/markdown.kpeg Updates the CodeFence rule to avoid eating indentation after the opening fence newline.
lib/rdoc/markdown.rb Updates the generated parser code and rule metadata to reflect the new CodeFence grammar.

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

@st0012 st0012 added the bug label Apr 9, 2026
Copy link
Copy Markdown
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Thank you!

@st0012 st0012 merged commit 799e551 into ruby:master Apr 9, 2026
45 checks passed
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.

4 participants