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. 22
      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(''),
len = rules.length,
line = startLine,
hasEmptyLines = false;
hasEmptyLines = false,
maxNesting = state.md.options.maxNesting;
while (line < endLine) {
state.line = line = state.skipEmptyLines(line);
@ -59,6 +60,13 @@ ParserBlock.prototype.tokenize = function (state, startLine, endLine) {
// Nested calls currently used for blockquotes & lists
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.
// On success, rule should:
//

22
lib/parser_inline.js

@ -85,21 +85,30 @@ function ParserInline() {
ParserInline.prototype.skipToken = function (state) {
var i, cached_pos, pos = state.pos,
rules = this.ruler.getRules(''),
len = rules.length;
len = rules.length,
maxNesting = state.md.options.maxNesting;
if ((cached_pos = state.cacheGet(pos)) > 0) {
state.pos = cached_pos;
return;
}
if (state.level < maxNesting) {
for (i = 0; i < len; i++) {
if (rules[i](state, true)) {
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.cacheSet(pos, state.pos);
};
@ -110,10 +119,17 @@ ParserInline.prototype.tokenize = function (state) {
var ok, i,
rules = this.ruler.getRules(''),
len = rules.length,
end = state.posMax;
end = state.posMax,
maxNesting = state.md.options.maxNesting;
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.
// 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
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,
// so no point trying to find the end of it in silent mode
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);
if (contentStart < 0) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
// Start list
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 + 1) !== 0x5E/* ^ */) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
for (pos = start + 2; pos < max; pos++) {
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;
}
if (state.level >= state.md.options.maxNesting) { return false; }
// We should terminate list on style change. Remember first one to compare.
markerCharCode = state.src.charCodeAt(posAfterMarker - 1);

1
lib/rules_inline/del.js

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

2
lib/rules_inline/emphasis.js

@ -66,8 +66,6 @@ module.exports = function emphasis(state, silent) {
return true;
}
if (state.level >= state.md.options.maxNesting) { return false; }
state.pos = start + 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 (state.src.charCodeAt(start) !== 0x5E/* ^ */) { return false; }
if (state.src.charCodeAt(start + 1) !== 0x5B/* [ */) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
labelStart = start + 2;
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.src.charCodeAt(start) !== 0x5B/* [ */) { 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++) {
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;
}
if (state.level >= state.md.options.maxNesting) { return false; }
stack = Math.floor(startCount / 2);
if (stack <= 0) { return false; }
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 (state.level >= state.md.options.maxNesting) { return false; }
labelStart = start + 1;
labelEnd = parseLinkLabel(state, start, !isImage);

1
lib/rules_inline/mark.js

@ -51,7 +51,6 @@ module.exports = function(state, silent) {
return true;
}
if (state.level >= state.md.options.maxNesting) { return false; }
stack = Math.floor(startCount / 2);
if (stack <= 0) { return false; }
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 (silent) { return false; } // don't run any pairs in validation mode
if (start + 2 >= max) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
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 (silent) { return false; } // don't run any pairs in validation mode
if (start + 2 >= max) { return false; }
if (state.level >= state.md.options.maxNesting) { return false; }
state.pos = start + 1;

Loading…
Cancel
Save