Skip to content

fix: handleincompletesingleunderscoreitalic is not accounting for the usage inside math equations#38

Merged
haydenbleasel merged 2 commits intomainfrom
1-handleincompletesingleunderscoreitalic-is-not-accounting-for-the-usage-inside-math-equations
Aug 25, 2025
Merged

fix: handleincompletesingleunderscoreitalic is not accounting for the usage inside math equations#38
haydenbleasel merged 2 commits intomainfrom
1-handleincompletesingleunderscoreitalic-is-not-accounting-for-the-usage-inside-math-equations

Conversation

@haydenbleasel
Copy link
Contributor

This pull request addresses a bug in the markdown parser related to handling single underscores used for italics when they appear inside math equations. The core improvement ensures that underscores inside math blocks (delimited by $... or $...$`) are not incorrectly interpreted as markdown italics, while underscores outside math blocks continue to be handled as before. Comprehensive tests have been added to verify correct behavior for various edge cases in math and markdown parsing.

Bug fix for markdown parsing in math blocks:

  • Updated the logic in countSingleUnderscores within parse-incomplete-markdown.ts to skip underscores that are inside math blocks, using a new helper function isWithinMathBlock. This prevents underscores inside $... or $...$` from being treated as markdown italics. [1] [2]
  • Added the helper function isWithinMathBlock to detect whether a character position is inside an inline or block math region, correctly handling escaped dollar signs and precedence between inline and block math.

Expanded test coverage:

  • Added a new test suite in parse-incomplete-markdown.test.ts to verify that underscores inside math blocks are not completed as italics, while underscores outside math blocks are handled normally. The tests cover inline math, block math, incomplete math blocks, mixed content, and escaped dollar signs.

Documentation and changelog:

  • Added a changeset entry documenting the patch fix for handling incomplete single underscore italics inside math equations.

@vercel
Copy link
Contributor

vercel bot commented Aug 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
streamdown Ready Ready Preview Comment Aug 25, 2025 10:21pm

@haydenbleasel haydenbleasel merged commit 045907f into main Aug 25, 2025
5 checks passed
@haydenbleasel haydenbleasel deleted the 1-handleincompletesingleunderscoreitalic-is-not-accounting-for-the-usage-inside-math-equations branch August 25, 2025 23:30
own-boldsbrain pushed a commit to own-boldsbrain/streamdown that referenced this pull request Sep 22, 2025
… usage inside math equations (vercel#38)

* Fix underscores in math equations

* Create cuddly-goats-warn.md
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.

handleIncompleteSingleUnderscoreItalic is not accounting for the usage inside math equations.

1 participant