Browse Source

simplify logic in scanDelims

fix https://github.com/markdown-it/markdown-it/issues/1003
pull/1015/head
Alex Kocharin 10 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
//
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 }
}

Loading…
Cancel
Save