Browse Source

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)
```
pull/879/head
Alex Kocharin 3 years ago
parent
commit
9ff460ef87
  1. 76
      lib/rules_block/blockquote.js

76
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; } if (state.sCount[startLine] - state.blkIndent >= 4) { return false; }
// check the block quote marker // 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, // we know that it's going to be a valid blockquote,
// so no point trying to find the end of it in silent mode // so no point trying to find the end of it in silent mode
if (silent) { return true; } if (silent) { return true; }
// set offset past spaces and ">" oldBMarks = [];
initial = offset = state.sCount[startLine] + 1; oldBSCount = [];
oldSCount = [];
// skip one optional space after '>' oldTShift = [];
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];
terminatorRules = state.md.block.ruler.getRules('blockquote'); terminatorRules = state.md.block.ruler.getRules('blockquote');
@ -125,7 +68,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// > test // > 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 // check if it's outdented, i.e. it's inside list item and indented
// less than said list item: // less than said list item:
// //
@ -148,7 +91,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// This line is inside the blockquote. // This line is inside the blockquote.
// set offset past spaces and ">" // set offset past spaces and ">"
initial = offset = state.sCount[nextLine] + 1; initial = state.sCount[nextLine] + 1;
// skip one optional space after '>' // skip one optional space after '>'
if (state.src.charCodeAt(pos) === 0x20 /* space */) { if (state.src.charCodeAt(pos) === 0x20 /* space */) {
@ -156,18 +99,16 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// ^ -- position start of line here: // ^ -- position start of line here:
pos++; pos++;
initial++; initial++;
offset++;
adjustTab = false; adjustTab = false;
spaceAfterMarker = true; spaceAfterMarker = true;
} else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { } else if (state.src.charCodeAt(pos) === 0x09 /* tab */) {
spaceAfterMarker = true; spaceAfterMarker = true;
if ((state.bsCount[nextLine] + offset) % 4 === 3) { if ((state.bsCount[nextLine] + initial) % 4 === 3) {
// ' >\t test ' // ' >\t test '
// ^ -- position start of line here (tab has width===1) // ^ -- position start of line here (tab has width===1)
pos++; pos++;
initial++; initial++;
offset++;
adjustTab = false; adjustTab = false;
} else { } else {
// ' >\t test ' // ' >\t test '
@ -179,6 +120,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
spaceAfterMarker = false; spaceAfterMarker = false;
} }
offset = initial;
oldBMarks.push(state.bMarks[nextLine]); oldBMarks.push(state.bMarks[nextLine]);
state.bMarks[nextLine] = pos; state.bMarks[nextLine] = pos;

Loading…
Cancel
Save