Skip to content

Keep link reference definitions verbatim during wrap (#292) - #294

Merged
leynos merged 15 commits into
mainfrom
issue-292-reflow-mangles-markdown-link-reference-definitions
May 27, 2026
Merged

Keep link reference definitions verbatim during wrap (#292)#294
leynos merged 15 commits into
mainfrom
issue-292-reflow-mangles-markdown-link-reference-definitions

Conversation

@leynos

@leynos leynos commented May 27, 2026

Copy link
Copy Markdown
Owner

Summary

This branch keeps CommonMark link reference definitions verbatim during the
--wrap reflow pass. The wrap pipeline now recognises [label]: url lines as
a distinct block type and routes them through passthrough handling so they are
not collapsed into prose paragraphs or split across lines.

Closes #292.

Review walkthrough

  • Start with src/wrap/block.rs for the LINK_REF_RE regex, BlockKind::LinkReferenceDefinition, and classification order after footnote definitions.
  • Then review src/wrap.rs to confirm link reference definitions are passthrough blocks.
  • Finish with tests/wrap/link_reference_definitions.rs for regression coverage of single definitions, consecutive collections, mixed paragraphs, and optional titles.

Validation

  • make check-fmt: passed
  • make lint: passed
  • make test: passed
  • coderabbit review --agent: 0 findings

Summary by Sourcery

Preserve CommonMark link reference definitions verbatim during the wrapping pass so they are not reflowed as prose.

New Features:

  • Detect link reference definition lines as a distinct block kind during wrapping and treat them as passthrough blocks.

Tests:

  • Add regression tests ensuring single, multiple, and mixed link reference definitions remain unchanged by wrapping, including cases with bare URLs, titles, and document boundaries.

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 60d3bcf4-1452-479d-8ce2-945ac9539096

📥 Commits

Reviewing files that changed from the base of the PR and between 1940aa6 and 630f6c3.

📒 Files selected for processing (7)
  • docs/developers-guide.md
  • src/process.rs
  • src/wrap.rs
  • src/wrap/block.rs
  • src/wrap/link_reference.rs
  • src/wrap/tests/classify_block.rs
  • src/wrap/tests/link_ref_regex.rs

This PR fixes issue #292 by ensuring CommonMark link reference definitions are preserved verbatim during the --wrap reflow pass. Previously, mdtablefix --wrap could collapse single-line link reference definitions into prose, split labels from their URLs, and introduce spurious leading spaces.

Changes

Core implementation

  • src/wrap/link_reference.rs
    • New module adding LINK_REF_RE and LINK_TITLE_RE, a LinkReferenceMatcher (production / is_definition / standalone_title_need / is_standalone_title_line), and a LinkTitleWindow state machine (LinkTitleWindow, LinkTitleWindowOutcome) to track optional standalone title continuation lines per CommonMark and decide when the next line must be emitted verbatim.
  • src/wrap/block.rs
    • Added BlockKind::LinkReferenceDefinition and updated classify_block to accept a LinkReferenceMatcher and detect link reference definition lines with correct precedence and the existing indent gating.
    • classify_block signature updated to take the matcher.
  • src/wrap.rs
    • is_passthrough_block now accepts a precomputed Option and treats LinkReferenceDefinition as a passthrough block so such lines are emitted verbatim.
    • wrap_text integrates LinkReferenceMatcher and LinkTitleWindow: it primes awaiting-link-title state on bare definitions, emits an immediately-following valid standalone title line verbatim, clears the state on blank lines/fence openers/interrupts, and otherwise reprocesses the next line for normal wrapping.
  • src/process.rs
    • Updated internal classification used while buffering table rows to use LinkReferenceMatcher::production() so table flushing respects the new link-definition detection.

Tests

  • Unit/property tests
    • src/wrap/tests/link_ref_regex.rs: proptest suite validating LINK_REF_RE / LINK_TITLE_RE, standalone-title indentation rules, and LinkTitleWindow state transitions.
    • src/wrap/tests/classify_block.rs: tests that classify_block detects the new BlockKind and other Markdown prefixes.
    • src/wrap/tests/link_reference_definitions.rs and src/wrap/tests/link_reference_definitions.rs (extracted module): unit tests covering inline titles, standalone next-line titles, awaiting-title transitions (blank lines, fences, in-fence suppression), and subsequent paragraph reflow.
  • Integration & snapshot tests
    • tests/wrap/link_reference_definitions.rs: integration tests for single, consecutive, mixed-paragraph and document-boundary cases.
    • tests/wrap/link_ref_snapshots.rs with insta snapshots to assert preservation of representative cases (single/multiple refs, inline title, next-line title, mixed paragraph). (Final outstanding item noted in reviews was committing snapshot files; snapshots are reported as added in this PR summary.)

Documentation

  • CHANGELOG.md: Added [Unreleased] → Fixed entry documenting that --wrap preserves link reference definitions verbatim (labels, URLs, optional titles).
  • docs/users-guide.md: Notes link reference definitions and optional standalone next-line titles are excluded from reflow and preserved verbatim.
  • docs/developers-guide.md: Documents BlockKind::LinkReferenceDefinition, LINK_REF_/LINK_TITLE_ regexes, helper functions, and the awaiting-link-title / LinkTitleWindow behaviour and limitations.

Validation and review

  • Formatting, linting and tests reported passing (make check-fmt, make lint, make test).
  • Automated CodeRabbit (coderabbitai) review prompts (missing docs, proptests, additional unit tests, snapshot guidance, minor refactor to avoid duplicate classification calls) were addressed iteratively: docs and property tests were added, classification was refactored to accept a matcher (avoids duplicate work), additional unit tests for awaiting-title edge cases were added, and insta snapshots were provided.
  • No public API changes; changes are internal to wrap/classification logic.
  • Change closes issue #292.

Design/notes

  • The LINK_REF_RE intentionally avoids complex nested/escaped-bracket label parsing; this documented limitation is considered acceptable for the scope of #292 and is noted in the developer guide.
  • No execplan document was added; work is linked to issue #292 and documented in the user and developer guides.

Walkthrough

Recognise CommonMark link reference definitions and optional standalone titles, classify them as passthrough BlockKind::LinkReferenceDefinition, integrate a LinkTitleWindow FSM into wrap_text to emit required title lines verbatim, add unit/property/integration tests, update docs and changelog, and wire classification into table-flush logic.

Changes

Link reference definition passthrough support

Layer / File(s) Summary
Detection, matcher and FSM
src/wrap/link_reference.rs
Add LINK_REF_RE and LINK_TITLE_RE, implement LinkReferenceMatcher and LinkTitleWindow with unit tests for detection and window outcomes.
Block classification
src/wrap/block.rs, src/wrap/tests/classify_block.rs
Add BlockKind::LinkReferenceDefinition, change classify_block to accept a LinkReferenceMatcher and detect definitions when indent < 4; extend tests to use LinkReferenceMatcher::production().
Wrap integration and passthrough handling
src/wrap.rs
Re-export LinkReferenceMatcher, refactor is_passthrough_block to accept Option<BlockKind>, integrate LinkTitleWindow into wrap_text to observe fences and to emit or reprocess the following line based on outcome; prime window for definitions needing standalone titles.
Source tests
src/wrap/tests/*, src/wrap/tests/link_reference_definitions.rs
Add tests for inline titles, next-line titles, awaiting-title clearing at fences, bare-definition behaviour, fenced content immunity, and classify_block prefix coverage; update test wiring.
Integration tests and snapshots
tests/wrap/*
Add integration and insta snapshot tests covering single/multiple/bare/titled definitions and mixed-content wrapping; add tests/wrap.rs entry and tests/wrap/mod.rs wiring.
Process wiring
src/process.rs
Import LinkReferenceMatcher and use classify_block(line, LinkReferenceMatcher::production()) when deciding to flush buffered table content.
Docs and changelog
docs/developers-guide.md, docs/users-guide.md, CHANGELOG.md
Document block classification, LinkReferenceMatcher/LinkTitleWindow behaviour, note that link reference definitions and valid standalone titles are preserved verbatim, and add changelog entry under Unreleased → Fixed.
Property tests
src/wrap/tests/link_ref_regex.rs
Add proptest-driven cases validating parsing of bare/inline-title definitions, standalone-title indentation rules, and LinkTitleWindow FSM transitions and outcomes.

Possibly related issues

  • #291: Recognise and preserve link reference definitions to prevent incorrect reflow and spurious leading-space behaviour described in the issue.

Suggested labels

bug, enhancement

Poem

Keep the refs intact and smart,
Let each single line play its part,
Titles follow, verbatim kept,
Wrapping leaves those lines unwept,
Snapshots guard what was adept.

🚥 Pre-merge checks | ✅ 5 | ❌ 15

❌ Failed checks (15 inconclusive)

Check name Status Explanation Resolution
Testing (Overall) ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
User-Facing Documentation ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Developer Documentation ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Module-Level Documentation ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Testing (Unit And Behavioural) ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Testing (Property / Proof) ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Testing (Compile-Time / Ui) ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Unit Architecture ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Domain Architecture ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Observability ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Security And Privacy ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Performance And Resource Use ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Concurrency And State ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Architectural Complexity And Maintainability ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
Rust Compiler Lint Integrity ❓ Inconclusive Repository clone failed, so this custom check could not run with code access. Retry the review run. If this persists, inspect pre-merge custom-check logs for infrastructure or agent runtime failures.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and accurately summarises the main change: preserving link reference definitions verbatim during wrap operations, with the issue reference (#292) included.
Description check ✅ Passed The PR description is comprehensive and directly related to the changeset, explaining the problem, solution approach, and validation steps taken.
Linked Issues check ✅ Passed All coding requirements from #292 are fulfilled: link reference definitions are detected via regex [src/wrap/link_reference.rs], classified as a distinct BlockKind [src/wrap/block.rs], treated as passthrough blocks [src/wrap.rs], and tested comprehensively [tests/wrap/link_reference_definitions.rs, src/wrap/tests/link_reference_definitions.rs, src/wrap/tests/link_ref_regex.rs].
Out of Scope Changes check ✅ Passed All code changes remain strictly focused on link reference definition handling. Documentation updates (CHANGELOG.md, docs/users-guide.md, docs/developers-guide.md) are directly related to explaining the new feature.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #292

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-292-reflow-mangles-markdown-link-reference-definitions

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai

sourcery-ai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds explicit detection and passthrough handling for CommonMark link reference definitions in the wrapping pipeline so they are preserved verbatim, along with targeted unit and integration tests.

Flow diagram for passthrough handling of link reference definitions

flowchart TD
    A[Input line] --> B[classify_block]
    B -->|matches LINK_REF_RE| C[BlockKind::LinkReferenceDefinition]
    B -->|other match| D[Other BlockKind]
    B -->|no match| E[None]

    C --> F[is_passthrough_block]
    D --> F
    E --> F

    F -->|BlockKind::LinkReferenceDefinition| G[Pass through verbatim]
    F -->|Heading or MarkdownlintDirective| G
    F -->|Other| H[Subject to wrapping]
Loading

File-Level Changes

Change Details Files
Recognize link reference definitions as a distinct block kind during classification.
  • Introduce LINK_REF_RE regex to capture link reference definition lines with optional indentation, label, URL, and trailing content.
  • Extend BlockKind enum with LinkReferenceDefinition variant and update block detection precedence comments to include it after footnote definitions.
  • Update classify_block to detect non-indented link reference definitions using LINK_REF_RE and return the new block kind, with unit tests covering various link-ref syntaxes and indentation behavior.
src/wrap/block.rs
src/wrap/tests.rs
Treat link reference definitions as passthrough blocks in the wrap pipeline so they are not reflowed.
  • Update is_passthrough_block to consider BlockKind::LinkReferenceDefinition alongside headings and markdownlint directives.
  • Ensure link reference definition lines bypass prose wrapping but still participate correctly in stream processing (e.g., mixed with paragraphs).
src/wrap.rs
Add regression tests to ensure link reference definitions remain verbatim across scenarios.
  • Add new link_reference_definitions test module to the wrap test suite.
  • Cover single, multiple, bare-URL, and titled link reference definitions, including cases at document start/end and interleaved with paragraphs to verify wrapping behavior and line length constraints.
tests/wrap/mod.rs
tests/wrap/link_reference_definitions.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#292 Ensure that Markdown link reference definitions (lines like [label]: <url> or [label]: url, optionally with a title) are recognized as a distinct block type during mdtablefix --wrap and left completely untouched by the reflow pass (i.e., not concatenated into paragraphs, not wrapped across lines, and without introducing leading spaces).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@leynos
leynos marked this pull request as ready for review May 27, 2026 10:50

@sourcery-ai sourcery-ai Bot 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.

Sorry @leynos, you have reached your weekly rate limit of 2500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai coderabbitai Bot added the Issue label May 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b6d42debca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/wrap.rs

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/wrap/block.rs`:
- Line 44: Add a short comment above the LINK_REF_RE declaration in
src/wrap/block.rs documenting its limitation: explain that the regex
r"^(\s*)(\[[^\]]+\]:\s*)(.*)$" does not handle balanced nested brackets or
escaped brackets in link labels (e.g., "[label [nested]]" or "[\[escaped\]]"),
and note that this is acceptable for issue `#292` and current tests; keep the
regex unchanged but include the explanatory comment for future maintainers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 162e6e8b-404c-48c6-949e-b7c047acfdf2

📥 Commits

Reviewing files that changed from the base of the PR and between 08a7c07 and b6d42de.

📒 Files selected for processing (5)
  • src/wrap.rs
  • src/wrap/block.rs
  • src/wrap/tests.rs
  • tests/wrap/link_reference_definitions.rs
  • tests/wrap/mod.rs

Comment thread src/wrap/block.rs Outdated
@leynos

leynos commented May 27, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/wrap/block.rs`:
- Around line 139-148: The function link_ref_needs_title currently infers an
inline title by checking the last character of remainder, which misclassifies
destinations that legitimately end with ')' (e.g., path_(v1)). Change it to
explicitly detect an inline title from the LINK_REF_RE captures instead of the
trailing-character heuristic: use the appropriate capture group(s) produced by
LINK_REF_RE (not the remainder variable) to determine if a title token is
present (quotes, parentheses or single quotes per CommonMark) and return false
only when no title capture exists; remove the matches!(remainder.chars().last(),
...) check and base the boolean on the explicit title capture.

In `@src/wrap/tests.rs`:
- Around line 403-453: Move the link-reference related tests (the functions
wrap_text_preserves_inline_link_reference_title,
wrap_text_preserves_link_reference_title_on_next_line,
wrap_text_reflows_paragraph_after_link_reference_title,
wrap_text_treats_title_after_blank_line_as_prose) out of tests.rs into a new
test submodule file named link_reference_definitions.rs; copy the test functions
and any required imports/attributes (e.g., #[test], #[rstest]) into that new
file, remove the original copies from tests.rs, and then add a module
declaration in the tests.rs test module (e.g., mod link_reference_definitions;)
so the new file is compiled as part of the test suite while keeping files under
400 lines. Ensure function names and attributes remain unchanged so wrap_text is
still referenced correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d3911e19-9773-476a-a98f-8bf31defe34b

📥 Commits

Reviewing files that changed from the base of the PR and between e8c45ef and 1aaa348.

📒 Files selected for processing (3)
  • src/wrap.rs
  • src/wrap/block.rs
  • src/wrap/tests.rs

Comment thread src/wrap/block.rs Outdated
Comment thread src/wrap/tests.rs Outdated
@leynos

leynos commented May 27, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (1)
src/wrap/tests.rs (1)

404-404: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reduce this file below the 400-line ceiling.

Line 404 still leaves src/wrap/tests.rs at 406 lines, which breaches the repository limit. Move at least one additional test block into an existing or new submodule.

As per coding guidelines, "Files must not exceed 400 lines in length."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/wrap/tests.rs` at line 404, The file exceeds the 400-line limit; move at
least one test block out of src/wrap/tests.rs into a submodule to reduce its
length. Either relocate a full #[test] function or a related test block into the
existing submodule mod link_reference_definitions or create a new #[cfg(test)]
submodule (e.g., mod extra_tests) and paste the test(s) there, updating any
use/imports or visibility (pub(crate)) so the moved tests compile; run cargo
test to verify everything still builds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/wrap/tests.rs`:
- Line 404: The file exceeds the 400-line limit; move at least one test block
out of src/wrap/tests.rs into a submodule to reduce its length. Either relocate
a full #[test] function or a related test block into the existing submodule mod
link_reference_definitions or create a new #[cfg(test)] submodule (e.g., mod
extra_tests) and paste the test(s) there, updating any use/imports or visibility
(pub(crate)) so the moved tests compile; run cargo test to verify everything
still builds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b4c9066b-df25-4b2b-96e9-eafb34fecb5a

📥 Commits

Reviewing files that changed from the base of the PR and between 1aaa348 and 641c6a8.

📒 Files selected for processing (3)
  • src/wrap/block.rs
  • src/wrap/tests.rs
  • src/wrap/tests/link_reference_definitions.rs

@leynos

leynos commented May 27, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai Have the following failed checks now been resolved?

If further work is required, please provide an AI agent prompt for the remaining work to be done to address these failures.

Do not treat warnings as optional or aspirational. Where a change is out of scope for this PR, propose a GitHub issue unless one exists already.

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
User-Facing Documentation ⚠️ Warning PR adds user-facing --wrap behaviour change (preserving link reference definitions) but does not update docs/users-guide.md or CHANGELOG.md to document the fix. Update docs/users-guide.md to document that link reference definitions are preserved verbatim during wrapping; add entry to CHANGELOG.md under Fixed section referencing issue #292.
Developer Documentation ⚠️ Warning Link reference definition support was added to wrap module without updating developers-guide.md. New block kind, regexes, and helper functions lack documentation. Update docs/developers-guide.md to document LinkReferenceDefinition block kind, link_ref_needs_title state tracking, and regex limitations.
Testing (Property / Proof) ⚠️ Warning PR introduces invariants over regex-matchable inputs (various URL formats, title styles, whitespace) but lacks property-based testing for regex correctness and edge cases. Add proptest tests validating: (1) all valid CommonMark link reference definitions match LINK_REF_RE; (2) invalid forms rejected; (3) title capture groups correctly identify optional titles.

@coderabbitai

This comment was marked as resolved.

@leynos

This comment was marked as resolved.

@lodyai
lodyai Bot force-pushed the issue-292-reflow-mangles-markdown-link-reference-definitions branch from f93a367 to 1663fcc Compare May 27, 2026 11:47
@coderabbitai

This comment was marked as resolved.

leynos and others added 8 commits May 27, 2026 13:51
Recognise CommonMark link reference definitions as a distinct block
type and route them through passthrough handling so the reflow pass
leaves each definition on its own line.

Add regression tests for single and consecutive definitions, mixed
paragraphs, and optional titles.

Co-authored-by: Cursor <cursoragent@cursor.com>
Note that the link reference regex does not handle nested or escaped
brackets in labels, which is acceptable for the current scope.

Co-authored-by: Cursor <cursoragent@cursor.com>
Recognise standalone title lines that follow a bare link reference
definition per CommonMark spec §4.7 and emit them verbatim alongside
the definition URL line.

Co-authored-by: Cursor <cursoragent@cursor.com>
Extend LINK_REF_RE with an optional title capture group so
link_ref_needs_title no longer misclassifies destinations ending in ')'.
Move link reference wrap tests into a dedicated submodule.

Co-authored-by: Cursor <cursoragent@cursor.com>
Extract classify_block_detects_markdown_prefixes so tests.rs stays
under the 400-line file limit.

Co-authored-by: Cursor <cursoragent@cursor.com>
Record the fix in CHANGELOG and users-guide, document block
classification helpers in developers-guide, and add proptest coverage
for LINK_REF_RE and LINK_TITLE_RE.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the proptest 1.6 entry from main and regenerate Cargo.lock.

Co-authored-by: Cursor <cursoragent@cursor.com>
Alphabetise module declarations in tests.rs to satisfy rustfmt.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lodyai
lodyai Bot force-pushed the issue-292-reflow-mangles-markdown-link-reference-definitions branch from 1663fcc to 96b4073 Compare May 27, 2026 11:54
leynos and others added 2 commits May 27, 2026 13:56
Cover awaiting_link_title edge cases, add insta snapshot tests for
link reference preservation, and cache classify_block per line in
wrap_text.

Co-authored-by: Cursor <cursoragent@cursor.com>
Fix MD012/no-multiple-blanks before the block classification section.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
echo "=== src/wrap/block.rs: classify_block signature and internal instantiation ==="
cat src/wrap/block.rs 2>/dev/null || echo "NOT FOUND"

echo ""
echo "=== docs/developers-guide.md: lines 155-195 ==="
sed -n '155,195p' docs/developers-guide.md 2>/dev/null || echo "NOT FOUND"

echo ""
echo "=== docs/developers-guide.md: LinkReferenceMatcher/LinkTitleWindow in API reference table ==="
rg -n "LinkReferenceMatcher|LinkTitleWindow|API reference|Internal API" docs/developers-guide.md 2>/dev/null || echo "NOT FOUND or no matches"

echo ""
echo "=== src/wrap/tests/link_ref_regex.rs: full content ==="
cat src/wrap/tests/link_ref_regex.rs 2>/dev/null || echo "NOT FOUND"

echo ""
echo "=== src/wrap.rs: classify_block calls to see if matcher is injected ==="
grep -n "classify_block\|LinkReferenceMatcher\|link_matcher\|block_kind" src/wrap.rs 2>/dev/null || echo "NOT FOUND"

echo ""
echo "=== src/wrap/block.rs: check for internal LinkReferenceMatcher::production() call ==="
rg -n "LinkReferenceMatcher\|production()" src/wrap/block.rs 2>/dev/null || echo "no matches"

Length of output: 22149



@leynos All three checks are now resolved.

Check Status Evidence
Unit Architecture ✅ Resolved classify_block accepts LinkReferenceMatcher as a parameter; no internal production() call inside block.rs. wrap.rs instantiates the matcher once (line 141) and injects it. is_passthrough_block accepts a pre-computed Option<BlockKind>, eliminating the duplicate call. Documentation uses "Centralizes" (Oxford -ize) and the comma before "so" is present.
Developer Documentation ✅ Resolved "Centralizes" confirmed on line 165; "closing the window, so the caller reflows it" confirms the comma on the LinkTitleWindow paragraph; LinkReferenceMatcher and LinkTitleWindow appear in the Internal API reference table at lines 208–209.
Testing (Property / Proof) ✅ Resolved src/wrap/tests/link_ref_regex.rs now contains generators for all title forms (arb_sq_title, arb_paren_title, arb_title_form), angle-bracketed URLs (arb_angle_url), escaped content (arb_escaped_dq_title), indentation bounds (definition_indentation_bounds, indent 0–6), and state-machine property tests (closed_window_is_inert, fence_context_resets_window, awaiting_title_line_emits_verbatim, awaiting_blank_line_emits_verbatim, awaiting_prose_reprocesses).

@leynos

leynos commented May 27, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos
leynos merged commit 2fe5c54 into main May 27, 2026
3 checks passed
@leynos
leynos deleted the issue-292-reflow-mangles-markdown-link-reference-definitions branch May 27, 2026 17:42
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.

Reflow mangles Markdown link reference definitions

1 participant