Skip to content

fix(parser): do not append a table row when a blank line closed the table - #402

Merged
leandrocp merged 1 commit into
mainfrom
fix-table-fragment-completion
Sep 4, 2026
Merged

fix(parser): do not append a table row when a blank line closed the table#402
leandrocp merged 1 commit into
mainfrom
fix-table-fragment-completion

Conversation

@leandrocp

@leandrocp leandrocp commented Sep 4, 2026

Copy link
Copy Markdown
Owner

The bug

MDEx.FragmentParser.complete/2 appended a phantom | - | row to a table that had already been closed by a trailing blank line.

maybe_complete_table/2 only checked that the trailing whitespace starts with \n. It never looked at the rest, so "...| 1 |\n\n" was treated the same as "...| 1 |\n" — an open table still being streamed.

Reproducer on main:

MDEx.FragmentParser.complete("| a |\n|---|\n| 1 |\n\n")
#=> "| a |\n|---|\n| 1 |\n| - |\n"    # phantom row

MDEx.FragmentParser.complete("| a | b |\n|---|---|\n| 1 | 2 |\n\n")
#=> "| a | b |\n|---|---|\n| 1 | 2 |\n| - | - |\n"

MDEx.FragmentParser.complete("# h\n\n| a |\n|---|\n| 1 |\n\n")
#=> "# h\n\n| a |\n|---|\n| 1 |\n| - |\n"

During streaming this meant every table rendered with an extra empty row until the end of input.

The change

maybe_complete_table/2 now bails out when the trailing whitespace contains a second newline, i.e. a blank line closed the block.

A table whose source ends immediately after a row (no blank line) is still considered open and keeps the existing behaviour of getting a separator/row appended.

Tests

Four regression tests in test/mdex/fragment_parser_test.exs covering the closed-by-blank-line cases (single column, multi column, after another block) plus an assertion that the still-open case is unchanged. Suite goes from 825 to 829 passing; no existing test asserted the old output.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Markdown table completion to avoid adding separator rows when a blank line follows the table.
    • Continued completing open tables that are not followed by a blank line.
    • Improved handling of single-column, multi-column, and tables following other content.
  • Tests

    • Added coverage for table completion behavior around blank-line boundaries.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: ec90a8c5-f8e4-45e8-ab4c-66c834b78a1e

📥 Commits

Reviewing files that changed from the base of the PR and between 20e850a and 3442865.

📒 Files selected for processing (2)
  • lib/mdex/fragment_parser.ex
  • test/mdex/fragment_parser_test.exs

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The fragment parser now avoids adding a table separator when a blank line follows the table header. Tests cover blank-line-terminated tables and open tables.

Changes

Table Completion

Layer / File(s) Summary
Conditional table completion
lib/mdex/fragment_parser.ex, test/mdex/fragment_parser_test.exs
maybe_complete_table checks for a following blank line before adding a separator. Tests cover single-column, multi-column, post-heading, and open-table cases.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 34428

This change prevents fragment completion from appending a phantom table row after a blank line while retaining completion for open tables. Covered boundary and unchanged behaviors leave no current merge-blocking risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main parser fix: it prevents a phantom table row after a blank line closes the table.
✨ 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 fix-table-fragment-completion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@leandrocp leandrocp changed the title fix: do not append a table row when a blank line closed the table fix(parser): do not append a table row when a blank line closed the table Sep 4, 2026
@leandrocp
leandrocp merged commit 7d7e11f into main Sep 4, 2026
6 checks passed
@leandrocp
leandrocp deleted the fix-table-fragment-completion branch September 4, 2026 02:02
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.

1 participant