Skip to content

Commit

Permalink
refactor: optimize splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Jan 20, 2025
1 parent 69dbd92 commit 7abb3b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-rice-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'markdown-to-jsx': patch
---

Further optimize the plain text splitting regex.
7 changes: 5 additions & 2 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,11 @@ const TEXT_STRIKETHROUGHED_R = new RegExp(`^~~${INLINE_SKIP_R}~~`)

const TEXT_ESCAPED_R = /^\\([^0-9A-Za-z\s])/

const TEXT_PLAIN_R =
/^[\s\S]+?(?=[^0-9A-Z\s\u00c0-\uffff&#;.()'"]|\d+\.|\n\n| {2,}\n|\w+:\S|$)/i
/**
* Always take the first character, then eagerly take text until a double space
* (potential line break) or some markdown-like punctuation is reached.
*/
const TEXT_PLAIN_R = /^([\s\S](?:(?! |[0-9]\.)[^*_~\-\n<`\\\[!])*)/

const TRIM_STARTING_NEWLINES = /^\n+/

Expand Down

0 comments on commit 7abb3b6

Please sign in to comment.