Skip to content

fix(MD013): preserve nested tables during list reflow#603

Closed
mattiasgronlund wants to merge 4 commits intorvben:mainfrom
mattiasgronlund:fix-md013-preserve-indented-tables
Closed

fix(MD013): preserve nested tables during list reflow#603
mattiasgronlund wants to merge 4 commits intorvben:mainfrom
mattiasgronlund:fix-md013-preserve-indented-tables

Conversation

@mattiasgronlund
Copy link
Copy Markdown
Contributor

Description

Fixes MD013 semantic reflow so potential table rows nested inside list items are treated as structural lines, like fenced code markers. This prevents the fixer from merging nested table rows into paragraph text.

The regression test and bug fix were created in cooperation with Codex.

Fixes: #598

Type of Change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update

Testing

  • Tests added/updated
  • All tests passing (make test-dev)
  • Manual testing performed

Added regression test:

  • test_reflow_preserves_tables_nested_in_list_items

Validated locally:

make test-dev
make fmt
make lint

Checklist

  • Code follows project style (make fmt && make lint)
  • Conventional commit messages used
  • Documentation updated (if needed)
  • CHANGELOG.md updated (if user-facing)

@rvben
Copy link
Copy Markdown
Owner

rvben commented May 2, 2026

Thanks for digging into this. Two things I'd like to flag before merging:

1. The regression test doesn't catch the bug.

I reverted only the src/rules/md013_line_length/mod.rs change on this branch and re-ran test_reflow_preserves_tables_nested_in_list_items — it still passes. Running the issue's exact reproducer through rumdl check --fix on current main (without this PR) also preserves the table rows.

A different input does reproduce the underlying bug on main:

- A long sentence about something interesting that describes how pipes appear in command-line examples.
  cell a | cell b

On main, cell a | cell b gets merged into the previous sentence:

- A long sentence about something interesting
  that describes how pipes appear in command-line examples. cell a | cell b

With this PR, it stays on its own line. So the fix is real, but the current test is a smoke test against a case that already passes on main.

Per the project's testing philosophy, could you replace or supplement the test with a reproducer that genuinely fails before the fix?

2. Fix placement.

The change is at line 1693 in the is_fence_marker branch, which fires before the careful table-detection at lines 1718–1727. After this PR, any TableUtils::is_potential_table_row(&content) matches first and routes everything through LineType::CodeBlock, so the LineType::Table classification path becomes unreachable for indented table content under list items.

The Table variant exists for a reason (downstream formatting and table-aware behaviour). I'd suggest broadening the existing branch at line 1718 instead — extend its predicate to also catch orphan pipe-shaped lines (e.g. drop the pipe_bordered || next_is_delim || prev_was_table requirement when there's clearly enough pipe structure), so the result is still classified as Table. That keeps LineType semantics consistent.

Happy to chat through the design if helpful.

@mattiasgronlund mattiasgronlund force-pushed the fix-md013-preserve-indented-tables branch from 53ccbac to f88aa65 Compare May 2, 2026 10:59
@mattiasgronlund
Copy link
Copy Markdown
Contributor Author

- A long sentence about something interesting that describes how pipes appear in command-line examples.
  cell a | cell b

Is not a nested table, I think this issue was actually fixed in 0.1.85, but I will try to understand the above issue, and provide a new pull request for that one.

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.

MD013 Reflow Collapses Tables Nested In List Items

2 participants