From c03be9b3bdc2214e1a78808b0a9dea436018106b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 13 Nov 2023 21:33:00 -0700 Subject: [PATCH] clean up emstrong --- src/rules.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/rules.ts b/src/rules.ts index 5250650912..5d93cb76ab 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -178,15 +178,27 @@ const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[pun .replace(/punct/g, _punctuation) .getRegex(); -// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right. -// | Skip orphan inside strong | Consume to delim | (1) #*** | (2) a***#, a*** | (3) #***a, ***a | (4) ***# | (5) #***# | (6) a***a -let emStrongRDelimAst = /^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[punct](\*+)(?=[\s]|$)|[^punct\s](\*+)(?!\*)(?=[punct\s]|$)|(?!\*)[punct\s](\*+)(?=[^punct\s])|[\s](\*+)(?!\*)(?=[punct])|(?!\*)[punct](\*+)(?!\*)(?=[punct])|[^punct\s](\*+)(?=[^punct\s])/; -let emStrongRDelimUnd = /^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/; // ^- Not allowed for _ -emStrongRDelimAst = edit(emStrongRDelimAst, 'gu') +const emStrongRDelimAst = edit( + '^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong ++ '|[^*]+(?=[^*])' // Consume to delim ++ '|(?!\\*)[punct](\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter ++ '|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)' // (2) a***#, a*** can only be a Right Delimiter ++ '|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])' // (3) #***a, ***a can only be Left Delimiter ++ '|[\\s](\\*+)(?!\\*)(?=[punct])' // (4) ***# can only be Left Delimiter ++ '|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])' // (5) #***# can be either Left or Right Delimiter ++ '|[^punct\\s](\\*+)(?=[^punct\\s])', 'gu') // (6) a***a can be either Left or Right Delimiter .replace(/punct/g, _punctuation) .getRegex(); -emStrongRDelimUnd = edit(emStrongRDelimUnd, 'gu') +// (6) Not allowed for _ +const emStrongRDelimUnd = edit( + '^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong ++ '|[^_]+(?=[^_])' // Consume to delim ++ '|(?!_)[punct](_+)(?=[\\s]|$)' // (1) #___ can only be a Right Delimiter ++ '|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)' // (2) a___#, a___ can only be a Right Delimiter ++ '|(?!_)[punct\\s](_+)(?=[^punct\\s])' // (3) #___a, ___a can only be Left Delimiter ++ '|[\\s](_+)(?!_)(?=[punct])' // (4) ___# can only be Left Delimiter ++ '|(?!_)[punct](_+)(?!_)(?=[punct])', 'gu') // (5) #___# can be either Left or Right Delimiter .replace(/punct/g, _punctuation) .getRegex();