From c7387ac540609689851927d79a6006296e99b1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 30 Sep 2026 15:12:12 +0200 Subject: [PATCH] Keep asterisks between spaces in comment previews "2 * 3 * 4" read as emphasis and lost its asterisks. Markdown doesn't treat a marker with a space just inside it as emphasis. --- src/lib/markdownPlain.ts | 8 ++++++-- tests/unit/markdownPlain.test.ts | 16 ++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) 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); +});