From 9ff460ef878e762443954fc9776743f60db031f3 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Sat, 21 May 2022 17:32:04 +0300 Subject: [PATCH] Drop a lot of extra code from blockquotes 1st iteration before the loop is exactly the same as a part of that loop this effectively replaces: ``` do(0) for (i = 1; i < x; i++) do(i) ``` with: ``` for (i = 0; i < x; i++) do(i) ``` --- lib/rules_block/blockquote.js | 76 +++++------------------------------ 1 file changed, 9 insertions(+), 67 deletions(-) diff --git a/lib/rules_block/blockquote.js b/lib/rules_block/blockquote.js index a02699a..e4044cb 100644 --- a/lib/rules_block/blockquote.js +++ b/lib/rules_block/blockquote.js @@ -34,73 +34,16 @@ module.exports = function blockquote(state, startLine, endLine, silent) { if (state.sCount[startLine] - state.blkIndent >= 4) { return false; } // check the block quote marker - if (state.src.charCodeAt(pos++) !== 0x3E/* > */) { return false; } + if (state.src.charCodeAt(pos) !== 0x3E/* > */) { return false; } // we know that it's going to be a valid blockquote, // so no point trying to find the end of it in silent mode if (silent) { return true; } - // set offset past spaces and ">" - initial = offset = state.sCount[startLine] + 1; - - // skip one optional space after '>' - if (state.src.charCodeAt(pos) === 0x20 /* space */) { - // ' > test ' - // ^ -- position start of line here: - pos++; - initial++; - offset++; - adjustTab = false; - spaceAfterMarker = true; - } else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { - spaceAfterMarker = true; - - if ((state.bsCount[startLine] + offset) % 4 === 3) { - // ' >\t test ' - // ^ -- position start of line here (tab has width===1) - pos++; - initial++; - offset++; - adjustTab = false; - } else { - // ' >\t test ' - // ^ -- position start of line here + shift bsCount slightly - // to make extra space appear - adjustTab = true; - } - } else { - spaceAfterMarker = false; - } - - oldBMarks = [ state.bMarks[startLine] ]; - state.bMarks[startLine] = pos; - - while (pos < max) { - ch = state.src.charCodeAt(pos); - - if (isSpace(ch)) { - if (ch === 0x09) { - offset += 4 - (offset + state.bsCount[startLine] + (adjustTab ? 1 : 0)) % 4; - } else { - offset++; - } - } else { - break; - } - - pos++; - } - - oldBSCount = [ state.bsCount[startLine] ]; - state.bsCount[startLine] = state.sCount[startLine] + 1 + (spaceAfterMarker ? 1 : 0); - - lastLineEmpty = pos >= max; - - oldSCount = [ state.sCount[startLine] ]; - state.sCount[startLine] = offset - initial; - - oldTShift = [ state.tShift[startLine] ]; - state.tShift[startLine] = pos - state.bMarks[startLine]; + oldBMarks = []; + oldBSCount = []; + oldSCount = []; + oldTShift = []; terminatorRules = state.md.block.ruler.getRules('blockquote'); @@ -125,7 +68,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { // > test // - - - // ``` - for (nextLine = startLine + 1; nextLine < endLine; nextLine++) { + for (nextLine = startLine; nextLine < endLine; nextLine++) { // check if it's outdented, i.e. it's inside list item and indented // less than said list item: // @@ -148,7 +91,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { // This line is inside the blockquote. // set offset past spaces and ">" - initial = offset = state.sCount[nextLine] + 1; + initial = state.sCount[nextLine] + 1; // skip one optional space after '>' if (state.src.charCodeAt(pos) === 0x20 /* space */) { @@ -156,18 +99,16 @@ module.exports = function blockquote(state, startLine, endLine, silent) { // ^ -- position start of line here: pos++; initial++; - offset++; adjustTab = false; spaceAfterMarker = true; } else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { spaceAfterMarker = true; - if ((state.bsCount[nextLine] + offset) % 4 === 3) { + if ((state.bsCount[nextLine] + initial) % 4 === 3) { // ' >\t test ' // ^ -- position start of line here (tab has width===1) pos++; initial++; - offset++; adjustTab = false; } else { // ' >\t test ' @@ -179,6 +120,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) { spaceAfterMarker = false; } + offset = initial; oldBMarks.push(state.bMarks[nextLine]); state.bMarks[nextLine] = pos;