Skip to content

fix(list): parse empty list items without trailing space#140

Merged
YousefHadder merged 1 commit intomainfrom
fix/empty-list-item-parsing
Nov 27, 2025
Merged

fix(list): parse empty list items without trailing space#140
YousefHadder merged 1 commit intomainfrom
fix/empty-list-item-parsing

Conversation

@YousefHadder
Copy link
Copy Markdown
Owner

Fixes #17

Summary

Fix list renumbering breaking when empty list items lose their trailing space (e.g., due to trim_trailing_whitespace or external formatters).

Problem

When a user creates an empty list item (e.g., pressing o on a list line), the plugin creates 3. (with trailing space). If an external formatter or editor setting removes trailing whitespace, the line becomes 3. which was not recognized as a valid list item, breaking list continuity and causing incorrect renumbering.

Before fix:

1. A
2. b
3.      ← Not parsed (no trailing space)
1. c    ← Incorrectly renumbered to 1 (new group)
5.

Solution

Added empty item patterns that match list markers at end of line without requiring trailing space:

  • ^(%s*)(%d+)%.$ for ordered lists (e.g., 3.)
  • ^(%s*)([a-z])%.$ for letter lists (e.g., a.)
  • Similar patterns for unordered, parenthesized, and uppercase variants

These patterns are checked after normal patterns, so we prefer matching with content when available. This avoids false positives like 3.14159 being parsed as a list item.

After fix:

1. A
2. b
3.      ← Now parsed correctly
4. c    ← Stays as item 4
5.

Testing

  • Added 6 new test cases covering empty item parsing and false positive prevention
  • All 106 tests pass
  • Manually tested 15 edge cases

Copilot AI review requested due to automatic review settings November 27, 2025 22:51
@YousefHadder YousefHadder force-pushed the fix/empty-list-item-parsing branch from b175b66 to ae93357 Compare November 27, 2025 22:53
Copy link
Copy Markdown
Contributor

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 issue #17 where list renumbering breaks when empty list items lose their trailing space due to formatters or editor settings like trim_trailing_whitespace.

Key changes:

  • Added 7 new empty item patterns that match list markers at end-of-line without requiring trailing space
  • Patterns use $ anchor to avoid false positives (e.g., "3.14159" is not matched)
  • Empty patterns are checked last to prefer matching with content when available
  • Added 6 new test cases covering empty item parsing and false positive prevention

Reviewed changes

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

File Description
lua/markdown-plus/list/parser.lua Adds 7 new patterns for empty list items (unordered, ordered, letter variants, parenthesized) that match markers at EOL without trailing space, plus corresponding pattern config entries
spec/markdown-plus/list_spec.lua Adds unit tests for parsing empty items without trailing space (ordered, unordered, letter, paren) and false positive prevention for decimals; adds integration test verifying empty items stay in same numbering group

@YousefHadder YousefHadder force-pushed the fix/empty-list-item-parsing branch from ae93357 to 46220a3 Compare November 27, 2025 22:56
@YousefHadder YousefHadder merged commit e151f19 into main Nov 27, 2025
14 checks passed
@YousefHadder YousefHadder deleted the fix/empty-list-item-parsing branch November 27, 2025 22:59
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.

[BUG] Auto formatting sometimes mess up list order

2 participants