Skip to content

Commit

Permalink
simplify logic in scanDelims
Browse files Browse the repository at this point in the history
fix #1003
  • Loading branch information
rlidwka committed Mar 2, 2024
1 parent d7ce5ec commit 5e90063
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions lib/rules_inline/state_inline.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 }
}
Expand Down

0 comments on commit 5e90063

Please sign in to comment.