Skip to content

fix(remend): don't complete emphasis/strikethrough markers inside complete inline code spans#426

Merged
haydenbleasel merged 3 commits intovercel:mainfrom
sleitor:fix-424
Mar 3, 2026
Merged

fix(remend): don't complete emphasis/strikethrough markers inside complete inline code spans#426
haydenbleasel merged 3 commits intovercel:mainfrom
sleitor:fix-424

Conversation

@sleitor
Copy link
Contributor

@sleitor sleitor commented Mar 2, 2026

Summary

Fixes #424

Bold, italic, and strikethrough handlers were using isWithinCodeBlock() which only detects triple-backtick fenced code blocks. Markers inside single-backtick inline code spans (e.g. **bold — user has both backticks): emphasis inside should NOT be completed → new correct behavior ✅

  • Incomplete inline code (e.g. **bold *italic `code ~~strike — streaming, closing backtick not yet arrived): the existing streaming behavior is preserved (inline code handler closes the backtick first, then handlers after it append their closers outside)

Applied the check in:

  • handleIncompleteBold
  • handleIncompleteBoldItalic
  • handleIncompleteDoubleUnderscoreItalic
  • handleIncompleteSingleAsteriskItalic
  • handleIncompleteStrikethrough

Tests

Added new test cases in __tests__/inline-code.test.ts:

expect(remend("`**bold`")).toBe("`**bold`");
expect(remend("`*italic`")).toBe("`*italic`");
expect(remend("`~~strikethrough`")).toBe("`~~strikethrough`");

All 331 tests pass.

… inline code spans

Bold, italic, and strikethrough handlers were using isWithinCodeBlock()
which only detects triple-backtick fenced code blocks. Markers inside
single-backtick inline code spans (e.g. `**bold`) were incorrectly
completed, leaking outside the code span.

Fix:
- Add isWithinCompleteInlineCode() to code-block-utils.ts that returns
  true only when a position is inside a *complete* (both delimiters
  present) inline code span. This preserves the existing streaming
  behavior where emphasis inside an *incomplete* inline code span
  (still being streamed) continues to be closed correctly.
- Apply the check in handleIncompleteBold, handleIncompleteBoldItalic,
  handleIncompleteDoubleUnderscoreItalic, handleIncompleteSingleAsterisk-
  Italic, and handleIncompleteStrikethrough.

Fixes vercel#424
@vercel
Copy link
Contributor

vercel bot commented Mar 2, 2026

Someone is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

handleIncompleteSingleUnderscoreItalic is missing the isInsideCodeBlock || isWithinCompleteInlineCode guard, causing single underscore markers inside complete inline code spans to be incorrectly completed (e.g., `_italic` becomes `_italic`_).

Fix on Vercel

@haydenbleasel
Copy link
Contributor

@sleitor Nice fix! Appreciate it. Can you create a patch changeset file? (run pnpm changeset)

@sleitor
Copy link
Contributor Author

sleitor commented Mar 3, 2026

Done — added a patch changeset file in the latest commit.

@haydenbleasel
Copy link
Contributor

amazing, nice work 👍

@haydenbleasel haydenbleasel merged commit a725579 into vercel:main Mar 3, 2026
3 of 6 checks passed
@sleitor sleitor deleted the fix-424 branch March 4, 2026 01:45
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.

Starting tags for bold/italics/strikethrough inside a inline code block leaks outside when using remend

2 participants