Skip to content

Commit

Permalink
replace String#split with String#substring when truncating head of st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
mojavelinux committed Jul 30, 2023
1 parent db2723d commit 0447af2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function downdoc (asciidoc, { attributes: initialAttrs = {} } =
return accum[accum.length - 1] && (accum[accum.length] = line) ? accum : accum
} else if (((grab = (chr0 = line[0]) === '\\') || (chr0 === 'i' && line[1] !== 'm')) &&
((grab && line === '\\endif::[]') || (line[line.length - 1] === ']' && ~line.indexOf('::') &&
(match = PreprocessorDirectiveRx.exec(line)))) && (line = grab ? line.slice(1) : undefined) === undefined) {
(match = PreprocessorDirectiveRx.exec(line)))) && !(line = grab ? line.substring(1) : undefined)) {
if (match[1]) {
const [,, negated, name, text, drop = attrs.has(name) ? !!negated : !negated] = match
if (text ? (drop ? false : (line = text)) : !skipStack.push(drop && 'endif::[]')) continue // redo
Expand All @@ -70,7 +70,7 @@ module.exports = function downdoc (asciidoc, { attributes: initialAttrs = {} } =
if (line === inContainer.delimiter) {
;({ cap: line, indent, inList, listStack } = inContainer)
if (inContainer.outdent && (grab = inContainer.outdent + indent.length) && ~(match = inContainer.at)) {
for (let i = match, l = accum.length; ++i < l;) accum[i] = (indent + accum[i].slice(grab)).trimEnd()
for (let i = match, l = accum.length; ++i < l;) accum[i] = (indent + accum[i].substring(grab)).trimEnd()
}
inContainer = containerStack.length ? containerStack.pop() : false
} else if ((match = line.length)) {
Expand Down Expand Up @@ -177,7 +177,7 @@ module.exports = function downdoc (asciidoc, { attributes: initialAttrs = {} } =
const row = inTable.row
const cells = ~line.indexOf('|', 1)
? line.split(CellDelimiterRx)
: chr0 === '|' ? ['', line.slice(line[1] === ' ' ? 2 : 1)] : [line]
: chr0 === '|' ? ['', line.substring(line[1] === ' ' ? 2 : 1)] : [line]
if (row) {
if (cells[0]) {
if (row.length && (row.wrapped = true)) {
Expand Down Expand Up @@ -233,19 +233,19 @@ module.exports = function downdoc (asciidoc, { attributes: initialAttrs = {} } =
subs = NORMAL_SUBS
if (verbatim) {
if (indented ? undef((subs = verbatim.subs)) : !(inPara = verbatim = verbatim.close())) continue // redo
line = line.slice(verbatim.outdent)
line = line.substring(verbatim.outdent)
} else if (hardbreakNext || inPara === 'hardbreaks') {
accum[accum.length - 1] += attrs.get('markdown-line-break')
} else if ((grab = accum[accum.length - 1])?.[grab.length - 1] === '+' && grab[grab.length - 2] === ' ') {
accum[accum.length - 1] = hardbreak(grab, attrs.get('markdown-line-break'), true)
} else if (attrs.has('markdown-unwrap-prose')) {
;(inPara !== '> ' || ((line = line.trimEnd()) !== '>' && accum[accum.length - 1] !== '>' &&
(line = line.slice(2)))) && (indent = accum.pop() + ' ')
(line = line.substring(2)))) && (indent = accum.pop() + ' ')
}
} else if (chr0 === '.') {
subs = NORMAL_SUBS
if (line.length > 1 && !(line[1] === '.' && line[2] === '.')) {
const text = line[1] === '*' && line[line.length - 1] === '*' ? line.slice(2, -1) : line.slice(1)
const text = line[1] === '*' && line[line.length - 1] === '*' ? line.slice(2, -1) : line.substring(1)
blockTitle = (line = undefined) || { indent, text, subs }
}
} else if (indented) {
Expand All @@ -259,8 +259,8 @@ module.exports = function downdoc (asciidoc, { attributes: initialAttrs = {} } =
indent = ((inList || inContainer).childIndent || '') + ' '
verbatim = { close: undef, outdent, subs }
}
} else if (~(match = line.indexOf(': ')) && match < 10 && (style = line.slice(0, match)) in ADMONS) {
next = (inPara = true) && line.slice(match + 2)
} else if (~(match = line.indexOf(': ')) && match < 10 && (style = line.substring(0, match)) in ADMONS) {
next = (inPara = true) && line.substring(match + 2)
line = '**' + ADMONS[style] + ' ' + style + '**'
} else if (chr0 === 'i' && line.startsWith('image::') && (match = BlockImageMacroRx.exec(line))) {
line = image.apply(attrs, match, (subs = ['attributes']))
Expand Down Expand Up @@ -299,7 +299,7 @@ function applySubs (str, subs = NORMAL_SUBS) {
}

function attributes (str) {
return ~str.indexOf('{') ? str.replace(AttributeRefRx, (m, bs, name) => (bs ? m.slice(1) : this.get(name) ?? m)) : str
return ~str.indexOf('{') ? str.replace(AttributeRefRx, (m, bs, n) => (bs ? m.substring(1) : this.get(n) ?? m)) : str
}

function callouts (str, apply = str[str.length - 1] === '>') {
Expand All @@ -320,7 +320,7 @@ function isAnyListItem (chr0, str, mode = 'test', match = chr0 in LIST_MARKERS &

function isHeading (str, acceptAll, blockAttrs, marker, title, spaceIdx = str.indexOf(' ')) {
if (!(~spaceIdx && str.startsWith((marker = ['=', '==', '===', '====', '=====', '======'][spaceIdx - 1])))) return
if (!(title = str.slice(spaceIdx + 1)) || (title[0] === ' ' && !(title = title.trimStart()))) return
if (!(title = str.substring(spaceIdx + 1)) || (title[0] === ' ' && !(title = title.trimStart()))) return
if (acceptAll || (blockAttrs && blockAttrs.get(1) === 'discrete')) return [marker, title]
}

Expand Down

0 comments on commit 0447af2

Please sign in to comment.