Browse Source

simplify logic in scanDelims

fix https://github.com/markdown-it/markdown-it/issues/1003
pull/1015/head
Alex Kocharin 3 months ago
parent
commit
5e90063954
  1. 31
      lib/rules_inline/state_inline.mjs

31
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 // - canSplitWord - determine if these markers can be found inside a word
// //
StateInline.prototype.scanDelims = function (start, canSplitWord) { StateInline.prototype.scanDelims = function (start, canSplitWord) {
let can_open, can_close
let left_flanking = true
let right_flanking = true
const max = this.posMax const max = this.posMax
const marker = this.src.charCodeAt(start) const marker = this.src.charCodeAt(start)
@ -109,29 +106,13 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) {
const isLastWhiteSpace = isWhiteSpace(lastChar) const isLastWhiteSpace = isWhiteSpace(lastChar)
const isNextWhiteSpace = isWhiteSpace(nextChar) const isNextWhiteSpace = isWhiteSpace(nextChar)
if (isNextWhiteSpace) { const left_flanking =
left_flanking = false !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar)
} else if (isNextPunctChar) { const right_flanking =
if (!(isLastWhiteSpace || isLastPunctChar)) { !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar)
left_flanking = false
}
}
if (isLastWhiteSpace) {
right_flanking = false
} else if (isLastPunctChar) {
if (!(isNextWhiteSpace || isNextPunctChar)) {
right_flanking = false
}
}
if (!canSplitWord) { const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar)
can_open = left_flanking && (!right_flanking || isLastPunctChar) const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar)
can_close = right_flanking && (!left_flanking || isNextPunctChar)
} else {
can_open = left_flanking
can_close = right_flanking
}
return { can_open, can_close, length: count } return { can_open, can_close, length: count }
} }

Loading…
Cancel
Save