Skip to content

Commit

Permalink
Drop a lot of extra code from blockquotes
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
rlidwka committed May 25, 2022
1 parent e843acc commit 9ff460e
Showing 1 changed file with 9 additions and 67 deletions.
76 changes: 9 additions & 67 deletions lib/rules_block/blockquote.js
Expand Up @@ -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');

Expand All @@ -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:
//
Expand All @@ -148,26 +91,24 @@ 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 */) {
// ' > 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[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 '
Expand All @@ -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;

Expand Down

0 comments on commit 9ff460e

Please sign in to comment.