Browse Source

Replace bqMarks logic with negative tShift

pull/14/head
Alex Kocharin 10 years ago
parent
commit
46402a32b4
  1. 1
      lib/parser_block.js
  2. 10
      lib/rules_block/blockquote.js
  3. 1
      lib/rules_block/code.js
  4. 1
      lib/rules_block/fences.js
  5. 1
      lib/rules_block/lheading.js
  6. 1
      lib/rules_block/list.js
  7. 14
      lib/rules_block/state_block.js
  8. 2
      lib/rules_block/table.js

1
lib/parser_block.js

@ -63,7 +63,6 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) {
// Termination condition for nested calls.
// Nested calls currently used for blockquotes & lists
if (state.tShift[line] < state.blkIndent) { break; }
if (state.bqMarks[line] < state.bqLevel) { break; }
// Try all possible rules.
// On success, rule should:

10
lib/rules_block/blockquote.js

@ -23,8 +23,6 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// skip one optional space after '>'
if (state.src.charCodeAt(pos) === 0x20) { pos++; }
state.bqMarks[startLine]++;
state.bqLevel++;
oldIndent = state.blkIndent;
state.blkIndent = 0;
@ -66,7 +64,6 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
}
if (state.src.charCodeAt(pos++) === 0x3E/* > */) {
state.bqMarks[nextLine]++;
// This line is inside the blockquote.
// skip one optional space after '>'
@ -98,6 +95,12 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
oldBMarks.push(state.bMarks[nextLine]);
oldTShift.push(state.tShift[nextLine]);
// A negative number means that this is a paragraph continuation;
//
// Any negative number will do the job here, but it's better for it
// to be large enough to make any bugs obvious.
state.tShift[nextLine] = -1337;
}
oldListMode = state.listMode;
@ -113,7 +116,6 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
state.bMarks[i + startLine] = oldBMarks[i];
state.tShift[i + startLine] = oldTShift[i];
}
state.bqLevel--;
state.blkIndent = oldIndent;
return true;

1
lib/rules_block/code.js

@ -11,7 +11,6 @@ module.exports = function code(state, startLine, endLine, silent) {
last = nextLine = startLine + 1;
while (nextLine < endLine) {
if (state.bqMarks[nextLine] < state.bqLevel) { break; }
if (state.isEmpty(nextLine)) {
nextLine++;
continue;

1
lib/rules_block/fences.js

@ -52,7 +52,6 @@ module.exports = function fences(state, startLine, endLine, silent) {
// test
break;
}
if (pos < max && state.bqMarks[nextLine] < state.bqLevel) { break; }
if (state.src.charCodeAt(pos) !== marker) { continue; }

1
lib/rules_block/lheading.js

@ -9,7 +9,6 @@ module.exports = function lheading(state, startLine, endLine, silent) {
if (next >= endLine) { return false; }
if (state.tShift[next] < state.blkIndent) { return false; }
if (state.bqMarks[next] < state.bqLevel) { return false; }
// Scan next line

1
lib/rules_block/list.js

@ -201,7 +201,6 @@ module.exports = function list(state, startLine, endLine, silent) {
// Try to check if list is terminated or continued.
//
if (state.tShift[nextLine] < state.blkIndent) { break; }
if (state.bqMarks[nextLine] < state.bqLevel) { break; }
// fail if terminating block found
terminate = false;

14
lib/rules_block/state_block.js

@ -29,7 +29,6 @@ function State(src, parser, tokens, options, env) {
this.bMarks = []; // line begin offsets for fast jumps
this.eMarks = []; // line end offsets for fast jumps
this.tShift = []; // indent for each line
this.bqMarks = []; // blockquote nesting level for each line (number of '>')
// block parser variables
this.blkIndent = 0; // required block content indent
@ -38,7 +37,6 @@ function State(src, parser, tokens, options, env) {
this.lineMax = 0; // lines count
this.tight = false; // loose/tight mode for lists
this.listMode = false; // if true, block parser stops on two newlines
this.bqLevel = 0; // blockquote nesting level for currently tokenized block
this.level = 0;
@ -89,10 +87,6 @@ function State(src, parser, tokens, options, env) {
this.tShift.push(0);
this.lineMax = this.bMarks.length - 1; // don't count last fake line
for (start = this.bMarks.length; start > 0; start--) {
this.bqMarks.push(0);
}
}
State.prototype.isEmpty = function isEmpty(line) {
@ -136,7 +130,7 @@ State.prototype.skipCharsBack = function skipCharsBack(pos, code, min) {
// cut lines range from source.
State.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
var i, first, last, queue,
var i, first, last, queue, shift,
line = begin;
if (begin >= end) {
@ -153,7 +147,11 @@ State.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
queue = new Array(end - begin);
for (i = 0; line < end; line++, i++) {
first = this.bMarks[line] + Math.min(this.tShift[line], indent);
shift = this.tShift[line];
if (shift > indent) { shift = indent; }
if (shift < 0) { shift = 0; }
first = this.bMarks[line] + shift;
if (line + 1 < end || keepLastLF) {
// No need for bounds check because we have fake entry on tail.

2
lib/rules_block/table.js

@ -21,7 +21,6 @@ module.exports = function table(state, startLine, endLine, silent) {
nextLine = startLine + 1;
if (state.tShift[nextLine] < state.blkIndent) { return false; }
if (state.bqMarks[nextLine] < state.bqLevel) { return false; }
// first character of the second line should be '|' or '-'
@ -75,7 +74,6 @@ module.exports = function table(state, startLine, endLine, silent) {
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) {
if (state.tShift[nextLine] < state.blkIndent) { break; }
if (state.bqMarks[nextLine] < state.bqLevel) { break; }
m = lineMatch(state, nextLine, /^ *\|?(.*?\|.*?)\|? *$/);
if (!m) { break; }

Loading…
Cancel
Save