From 5e900639542bb36501ee9e960c07bfaa529431c9 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Sun, 3 Mar 2024 00:20:57 +0400 Subject: [PATCH] simplify logic in scanDelims fix https://github.com/markdown-it/markdown-it/issues/1003 --- lib/rules_inline/state_inline.mjs | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/lib/rules_inline/state_inline.mjs b/lib/rules_inline/state_inline.mjs index 86a72d7..80cb3c5 100644 --- a/lib/rules_inline/state_inline.mjs +++ b/lib/rules_inline/state_inline.mjs @@ -86,9 +86,6 @@ StateInline.prototype.push = function (type, tag, nesting) { // - canSplitWord - determine if these markers can be found inside a word // StateInline.prototype.scanDelims = function (start, canSplitWord) { - let can_open, can_close - let left_flanking = true - let right_flanking = true const max = this.posMax const marker = this.src.charCodeAt(start) @@ -109,29 +106,13 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) { const isLastWhiteSpace = isWhiteSpace(lastChar) const isNextWhiteSpace = isWhiteSpace(nextChar) - if (isNextWhiteSpace) { - left_flanking = false - } else if (isNextPunctChar) { - if (!(isLastWhiteSpace || isLastPunctChar)) { - left_flanking = false - } - } - - if (isLastWhiteSpace) { - right_flanking = false - } else if (isLastPunctChar) { - if (!(isNextWhiteSpace || isNextPunctChar)) { - right_flanking = false - } - } + const left_flanking = + !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar) + const right_flanking = + !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar) - if (!canSplitWord) { - can_open = left_flanking && (!right_flanking || isLastPunctChar) - can_close = right_flanking && (!left_flanking || isNextPunctChar) - } else { - can_open = left_flanking - can_close = right_flanking - } + const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar) + const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar) return { can_open, can_close, length: count } }