From 0447af2f79602c6a54029aec68368cd9b6673c9e Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 28 Jul 2023 23:52:30 -0600 Subject: [PATCH] replace String#split with String#substring when truncating head of string --- lib/index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index eeddfb7..b582535 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 @@ -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)) { @@ -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)) { @@ -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) { @@ -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'])) @@ -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] === '>') { @@ -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] }