diff --git a/src/lib/markdownPlain.ts b/src/lib/markdownPlain.ts index 7c587e465..7571c8ad2 100644 --- a/src/lib/markdownPlain.ts +++ b/src/lib/markdownPlain.ts @@ -9,8 +9,12 @@ export function plainText(body: string): string { .replace(/`/gu, "") .replace(/~~(.+?)~~/gu, "$1") // Emphasis only where a marker sits on a word boundary, so `snake_case`, - // `MAX_SIZE` and `_private` survive being read as italics. - .replace(/(^|[^\w])[*_]{1,2}([^*_]+?)[*_]{1,2}(?=[^\w]|$)/gu, "$1$2") + // `MAX_SIZE` and `_private` survive being read as italics, and with no + // space just inside it, so `2 * 3 * 4` does too. + .replace( + /(^|[^\w])[*_]{1,2}(?=\S)([^*_]+?)(?<=\S)[*_]{1,2}(?=[^\w]|$)/gu, + "$1$2", + ) .replace(/^\s{0,3}#{1,6}\s+/gmu, "") .replace(/^\s{0,3}>\s?/gmu, "") .replace(/^\s{0,3}(?:[-+*]|\d+\.)\s+/gmu, "") diff --git a/tests/unit/markdownPlain.test.ts b/tests/unit/markdownPlain.test.ts index 8c6640b3c..b36165ee2 100644 --- a/tests/unit/markdownPlain.test.ts +++ b/tests/unit/markdownPlain.test.ts @@ -19,9 +19,13 @@ test.each([ expect(plainText(markdown)).toBe(expected); }); -test.each(["snake_case_name", "MAX_SIZE", "_private", "a*b*c"])( - "leaves %j alone", - text => { - expect(plainText(text)).toBe(text); - }, -); +test.each([ + "snake_case_name", + "MAX_SIZE", + "_private", + "see _foo_bar", + "a*b*c", + "2 * 3 * 4", +])("leaves %j alone", text => { + expect(plainText(text)).toBe(text); +});