Skip to content

Commit

Permalink
fix(autoformatting): prevent autoformatting when the first underscore…
Browse files Browse the repository at this point in the history
… is preceded by a non-whitespace character (#262)
  • Loading branch information
giamir committed Jan 30, 2024
1 parent 3b55b95 commit 5e45ac2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/rich-text/inputrules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const strongRegexAsterisks = /\*\*(\S(?:|.*?\S))\*\*$/;
// matches: *some text*, but not **text* or * text *
export const emphasisRegexAsterisk = /\*([^*\s]([^*])*[^*\s]|[^*\s])\*$/;
// matches: __some text__, but not __ text __
const strongRegexUnderscores = /__(\S(?:|.*?\S))__$/;
const strongRegexUnderscores = /(?<!\S)__(\S(?:|.*?\S))__$/;
// matches: _some text_, but not __text_ or _ text _
const emphasisRegexUnderscore = /_([^_\s]([^_])*[^_\s]|[^_\s])_$/;
const emphasisRegexUnderscore = /(?<!\S)_([^_\s]([^_])*[^_\s]|[^_\s])_$/;
// matches: [ *any* thing ]( any thing )
const linkRegex = /\[(.+)\]\((.+)\)$/;

Expand Down
2 changes: 2 additions & 0 deletions test/rich-text/inputrules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe("mark input rules", () => {
["__not a match_", false],
["_ no-match_", false],
["_no-match _", false],
["text_no-match_", false],
];
// eslint-disable-next-line jest/expect-expect
it.each(emphasisUnderlineTests)(
Expand All @@ -123,6 +124,7 @@ describe("mark input rules", () => {
["__should match__", true],
["__ no-match__", false],
["__no-match __", false],
["text__no-match__", false],
];
// eslint-disable-next-line jest/expect-expect
it.each(boldUnderlineTests)(
Expand Down

0 comments on commit 5e45ac2

Please sign in to comment.