Browse Source

Moved nesting check from rules to upper level

pull/24/head
Vitaly Puzrin 10 years ago
parent
commit
e72603af70
  1. 10
      lib/parser_block.js
  2. 30
      lib/parser_inline.js
  3. 2
      lib/rules_block/blockquote.js
  4. 2
      lib/rules_block/deflist.js
  5. 1
      lib/rules_block/footnote.js
  6. 2
      lib/rules_block/list.js
  7. 1
      lib/rules_inline/del.js
  8. 2
      lib/rules_inline/emphasis.js
  9. 1
      lib/rules_inline/footnote_inline.js
  10. 1
      lib/rules_inline/footnote_ref.js
  11. 1
      lib/rules_inline/ins.js
  12. 1
      lib/rules_inline/links.js
  13. 1
      lib/rules_inline/mark.js
  14. 1
      lib/rules_inline/sub.js
  15. 1
      lib/rules_inline/sup.js

10
lib/parser_block.js

@ -49,7 +49,8 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) {
rules = this.ruler.getRules(''), rules = this.ruler.getRules(''),
len = rules.length, len = rules.length,
line = startLine, line = startLine,
hasEmptyLines = false; hasEmptyLines = false,
maxNesting = state.md.options.maxNesting;
while (line < endLine) { while (line < endLine) {
state.line = line = state.skipEmptyLines(line); state.line = line = state.skipEmptyLines(line);
@ -59,6 +60,13 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) {
// Nested calls currently used for blockquotes & lists // Nested calls currently used for blockquotes & lists
if (state.tShift[line] < state.blkIndent) { break; } if (state.tShift[line] < state.blkIndent) { break; }
// If nesting level exceeded - skip tail to the end. That's not ordinary
// situation and we should not care about content.
if (state.level >= maxNesting) {
state.line = endLine;
break;
}
// Try all possible rules. // Try all possible rules.
// On success, rule should: // On success, rule should:
// //

30
lib/parser_inline.js

@ -85,21 +85,30 @@ function ParserInline() {
ParserInline.prototype.skipToken = function (state) { ParserInline.prototype.skipToken = function (state) {
var i, cached_pos, pos = state.pos, var i, cached_pos, pos = state.pos,
rules = this.ruler.getRules(''), rules = this.ruler.getRules(''),
len = rules.length; len = rules.length,
maxNesting = state.md.options.maxNesting;
if ((cached_pos = state.cacheGet(pos)) > 0) { if ((cached_pos = state.cacheGet(pos)) > 0) {
state.pos = cached_pos; state.pos = cached_pos;
return; return;
} }
for (i = 0; i < len; i++) { if (state.level < maxNesting) {
if (rules[i](state, true)) { for (i = 0; i < len; i++) {
state.cacheSet(pos, state.pos); if (rules[i](state, true)) {
return; state.cacheSet(pos, state.pos);
return;
}
} }
state.pos++;
} else {
// If nesting level exceeded - skip tail to the end. That's not ordinary
// situation and we should not care about content.
state.pos = state.max;
} }
state.pos++;
state.cacheSet(pos, state.pos); state.cacheSet(pos, state.pos);
}; };
@ -110,10 +119,17 @@ ParserInline.prototype.tokenize = function (state) {
var ok, i, var ok, i,
rules = this.ruler.getRules(''), rules = this.ruler.getRules(''),
len = rules.length, len = rules.length,
end = state.posMax; end = state.posMax,
maxNesting = state.md.options.maxNesting;
while (state.pos < end) { while (state.pos < end) {
// If nesting level exceeded - skip tail to the end. That's not ordinary
// situation and we should not care about content.
if (state.level >= maxNesting) {
state.pos = end;
break;
}
// Try all possible rules. // Try all possible rules.
// On success, rule should: // On success, rule should:
// //

2
lib/rules_block/blockquote.js

@ -15,8 +15,6 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
// 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; }
if (state.level >= state.md.options.maxNesting) { 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; }

2
lib/rules_block/deflist.js

@ -71,8 +71,6 @@ module.exports = function deflist(state, startLine, endLine, silent) {
contentStart = skipMarker(state, nextLine); contentStart = skipMarker(state, nextLine);
if (contentStart < 0) { return false; } if (contentStart < 0) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
// Start list // Start list
listTokIdx = state.tokens.length; listTokIdx = state.tokens.length;

1
lib/rules_block/footnote.js

@ -13,7 +13,6 @@ module.exports = function footnote(state, startLine, endLine, silent) {
if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; } if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; } if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
for (pos = start + 2; pos < max; pos++) { for (pos = start + 2; pos < max; pos++) {
if (state.src.charCodeAt(pos) === 0x20) { return false; } if (state.src.charCodeAt(pos) === 0x20) { return false; }

2
lib/rules_block/list.js

@ -114,8 +114,6 @@ module.exports = function list(state, startLine, endLine, silent) {
return false; return false;
} }
if (state.level >= state.md.options.maxNesting) { return false; }
// We should terminate list on style change. Remember first one to compare. // We should terminate list on style change. Remember first one to compare.
markerCharCode = state.src.charCodeAt(posAfterMarker - 1); markerCharCode = state.src.charCodeAt(posAfterMarker - 1);

1
lib/rules_inline/del.js

@ -51,7 +51,6 @@ module.exports = function(state, silent) {
return true; return true;
} }
if (state.level >= state.md.options.maxNesting) { return false; }
stack = Math.floor(startCount / 2); stack = Math.floor(startCount / 2);
if (stack <= 0) { return false; } if (stack <= 0) { return false; }
state.pos = start + startCount; state.pos = start + startCount;

2
lib/rules_inline/emphasis.js

@ -66,8 +66,6 @@ module.exports = function emphasis(state, silent) {
return true; return true;
} }
if (state.level >= state.md.options.maxNesting) { return false; }
state.pos = start + startCount; state.pos = start + startCount;
stack = [ startCount ]; stack = [ startCount ];

1
lib/rules_inline/footnote_inline.js

@ -16,7 +16,6 @@ module.exports = function footnote_inline(state, silent) {
if (start + 2 >= max) { return false; } if (start + 2 >= max) { return false; }
if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; } if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x5B/* [ */) { return false; } if (state.src.charCodeAt(start + 1) !== 0x5B/* [ */) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
labelStart = start + 2; labelStart = start + 2;
labelEnd = parseLinkLabel(state, start + 1); labelEnd = parseLinkLabel(state, start + 1);

1
lib/rules_inline/footnote_ref.js

@ -17,7 +17,6 @@ module.exports = function footnote_ref(state, silent) {
if (!state.env.footnotes || !state.env.footnotes.refs) { return false; } if (!state.env.footnotes || !state.env.footnotes.refs) { return false; }
if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; } if (state.src.charCodeAt(start) !== 0x5B/* [ */) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; } if (state.src.charCodeAt(start + 1) !== 0x5E/* ^ */) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
for (pos = start + 2; pos < max; pos++) { for (pos = start + 2; pos < max; pos++) {
if (state.src.charCodeAt(pos) === 0x20) { return false; } if (state.src.charCodeAt(pos) === 0x20) { return false; }

1
lib/rules_inline/ins.js

@ -51,7 +51,6 @@ module.exports = function(state, silent) {
return true; return true;
} }
if (state.level >= state.md.options.maxNesting) { return false; }
stack = Math.floor(startCount / 2); stack = Math.floor(startCount / 2);
if (stack <= 0) { return false; } if (stack <= 0) { return false; }
state.pos = start + startCount; state.pos = start + startCount;

1
lib/rules_inline/links.js

@ -30,7 +30,6 @@ module.exports = function links(state, silent) {
} }
if (marker !== 0x5B/* [ */) { return false; } if (marker !== 0x5B/* [ */) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
labelStart = start + 1; labelStart = start + 1;
labelEnd = parseLinkLabel(state, start, !isImage); labelEnd = parseLinkLabel(state, start, !isImage);

1
lib/rules_inline/mark.js

@ -51,7 +51,6 @@ module.exports = function(state, silent) {
return true; return true;
} }
if (state.level >= state.md.options.maxNesting) { return false; }
stack = Math.floor(startCount / 2); stack = Math.floor(startCount / 2);
if (stack <= 0) { return false; } if (stack <= 0) { return false; }
state.pos = start + startCount; state.pos = start + startCount;

1
lib/rules_inline/sub.js

@ -14,7 +14,6 @@ module.exports = function sub(state, silent) {
if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; } if (state.src.charCodeAt(start) !== 0x7E/* ~ */) { return false; }
if (silent) { return false; } // don't run any pairs in validation mode if (silent) { return false; } // don't run any pairs in validation mode
if (start + 2 >= max) { return false; } if (start + 2 >= max) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
state.pos = start + 1; state.pos = start + 1;

1
lib/rules_inline/sup.js

@ -14,7 +14,6 @@ module.exports = function sup(state, silent) {
if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; } if (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; }
if (silent) { return false; } // don't run any pairs in validation mode if (silent) { return false; } // don't run any pairs in validation mode
if (start + 2 >= max) { return false; } if (start + 2 >= max) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
state.pos = start + 1; state.pos = start + 1;

Loading…
Cancel
Save