Skip to content

fix(MD013): preserve wildcard asterisks during reflow#604

Merged
rvben merged 4 commits intorvben:mainfrom
mattiasgronlund:fix-md013-wildcard-asterisk-reflow
May 4, 2026
Merged

fix(MD013): preserve wildcard asterisks during reflow#604
rvben merged 4 commits intorvben:mainfrom
mattiasgronlund:fix-md013-wildcard-asterisk-reflow

Conversation

@mattiasgronlund
Copy link
Copy Markdown
Contributor

Description

Fixes MD013 semantic reflow so the emphasis sentence-split path does not insert a space after a hyphen before a literal wildcard asterisk. This preserves identifiers like TICKET-* during reflow.

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

Fixes: #597

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_literal_wildcard_asterisks

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 the fix — the wildcard case is real and reproduces on main.

One concern before merging: the change patches two of three sibling sites in src/utils/text_reflow.rs. The same pattern at line 1477 (the general element-joining path) doesn't get the new !current_line.ends_with('-') check, so a hyphen-attached emphasis going through that path will reintroduce the bug.

Could you either:

  • (a) Apply the same && !current_line.ends_with('-') at line 1477, or

  • (b) Extract a shared helper, e.g.:

    fn should_insert_space_before_join(current: &str) -> bool {
        !current.is_empty()
            && !current.ends_with(' ')
            && !current.ends_with('(')
            && !current.ends_with('[')
            && !current.ends_with('-')
    }

    and call it at all three sites?

I tested dash-*emphasis* (no space) on this branch and it now produces the correct output, so the fix itself is sound — just want to keep the three sibling conditionals consistent.

Also worth noting: the fix actually addresses a broader class than wildcards specifically — any hyphen-attached emphasis-like construct. The PR title and test could mention that, but not a blocker.

@mattiasgronlund mattiasgronlund force-pushed the fix-md013-wildcard-asterisk-reflow branch from 8f3abcd to b036dd6 Compare May 2, 2026 21:47
@mattiasgronlund
Copy link
Copy Markdown
Contributor Author

I fixed the code according to your comment, using fn should_insert_space_before_join(current: &str) -> bool.

I tried to create a test case which would fail unless I added the fix on line 1477 also, but I had to give up.
I am quite sure that if is_adjacent is false, current_line can not end with '-'.

@rvben rvben merged commit 012c477 into rvben:main May 4, 2026
6 checks passed
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 Inserts Space Before Literal Wildcard Asterisks

2 participants