mirror of
https://seed.radicle.dev/rad:z4D5UCArafTzTQpDZNQRuqswh3ury.git
synced 2026-10-18 19:10:45 +08:00
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.
This commit is contained in:
@@ -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, "")
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user