Browse Source

StateInline props rename

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
2040c4f02e
  1. 1
      Makefile
  2. 22
      lib/links.js
  3. 6
      lib/parser_inline.js
  4. 4
      lib/parser_ref.js
  5. 2
      lib/rules_inline/emphasis.js
  6. 4
      lib/rules_inline/links.js
  7. 21
      lib/rules_inline/state_inline.js
  8. 2
      lib/rules_inline/strikethrough.js
  9. 2
      support/specsplit.js

1
Makefile

@ -25,6 +25,7 @@ lint:
test: lint test: lint
NODE_ENV=test mocha -R spec NODE_ENV=test mocha -R spec
echo "CommonMark stat:\n"
./support/specsplit.js test/fixtures/stmd/spec.txt ./support/specsplit.js test/fixtures/stmd/spec.txt

22
lib/links.js

@ -11,17 +11,17 @@ function parseLinkLabel(state, start) {
labelEnd = -1, labelEnd = -1,
max = state.posMax, max = state.posMax,
oldPos = state.pos, oldPos = state.pos,
oldFlag = state.validateInsideLink; oldFlag = state.isInLabel;
if (state.validateInsideLink) { return -1; } if (state.isInLabel) { return -1; }
if (state.label_nest_level) { if (state.labelUnmatchedScopes) {
state.label_nest_level--; state.labelUnmatchedScopes--;
return -1; return -1;
} }
state.pos = start + 1; state.pos = start + 1;
state.validateInsideLink = true; state.isInLabel = true;
level = 1; level = 1;
while (state.pos < max) { while (state.pos < max) {
@ -43,14 +43,14 @@ function parseLinkLabel(state, start) {
if (found) { if (found) {
labelEnd = state.pos; labelEnd = state.pos;
state.label_nest_level = 0; state.labelUnmatchedScopes = 0;
} else { } else {
state.label_nest_level = level - 1; state.labelUnmatchedScopes = level - 1;
} }
// restore old state // restore old state
state.pos = oldPos; state.pos = oldPos;
state.validateInsideLink = oldFlag; state.isInLabel = oldFlag;
return labelEnd; return labelEnd;
} }
@ -72,7 +72,7 @@ function parseLinkDestination(state, pos) {
if (code === 0x0A /* \n */) { return false; } if (code === 0x0A /* \n */) { return false; }
if (code === 0x3E /* > */) { if (code === 0x3E /* > */) {
state.pos = pos + 1; state.pos = pos + 1;
state.link_content = href; state.linkContent = href;
return true; return true;
} }
if (code === 0x5C /* \ */ && pos + 1 < max) { if (code === 0x5C /* \ */ && pos + 1 < max) {
@ -123,7 +123,7 @@ function parseLinkDestination(state, pos) {
if (!state.parser.validateLink(href)) { return false; } if (!state.parser.validateLink(href)) { return false; }
state.pos = pos; state.pos = pos;
state.link_content = href; state.linkContent = href;
return true; return true;
} }
@ -149,7 +149,7 @@ function parseLinkTitle(state, pos) {
code = state.src.charCodeAt(pos); code = state.src.charCodeAt(pos);
if (code === marker) { if (code === marker) {
state.pos = pos + 1; state.pos = pos + 1;
state.link_content = title; state.linkContent = title;
return true; return true;
} }
if (code === 0x5C /* \ */ && pos + 1 < max) { if (code === 0x5C /* \ */ && pos + 1 < max) {

6
lib/parser_inline.js

@ -65,14 +65,14 @@ ParserInline.prototype.skipToken = function (state) {
rules = this._rules, rules = this._rules,
len = this._rules.length; len = this._rules.length;
if (state.memo[pos] !== undefined) { if (state.cache[pos] !== undefined) {
state.pos = state.memo[pos]; state.pos = state.cache[pos];
return true; return true;
} }
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (rules[i](state, true)) { if (rules[i](state, true)) {
state.memo[pos] = state.pos; state.cache[pos] = state.pos;
return true; return true;
} }
} }

4
lib/parser_ref.js

@ -35,7 +35,7 @@ module.exports = function parse_reference(str, parser, options, env) {
// [label]: destination 'title' // [label]: destination 'title'
// ^^^^^^^^^^^ parse this // ^^^^^^^^^^^ parse this
if (!parseLinkDestination(state, pos)) { return -1; } if (!parseLinkDestination(state, pos)) { return -1; }
href = state.link_content; href = state.linkContent;
pos = state.pos; pos = state.pos;
// [label]: destination 'title' // [label]: destination 'title'
@ -49,7 +49,7 @@ module.exports = function parse_reference(str, parser, options, env) {
// [label]: destination 'title' // [label]: destination 'title'
// ^^^^^^^ parse this // ^^^^^^^ parse this
if (pos < max && start !== pos && parseLinkTitle(state, pos)) { if (pos < max && start !== pos && parseLinkTitle(state, pos)) {
title = state.link_content; title = state.linkContent;
pos = state.pos; pos = state.pos;
} else { } else {
title = ''; title = '';

2
lib/rules_inline/emphasis.js

@ -65,7 +65,7 @@ module.exports = function emphasis(state, silent) {
// skip emphasis in links because it has lower priority, compare: // skip emphasis in links because it has lower priority, compare:
// [foo *bar]()* // [foo *bar]()*
// [foo `bar]()` // [foo `bar]()`
if (state.validateInsideLink) { return false; } if (silent && state.isInLabel) { return false; }
res = scanDelims(state, start); res = scanDelims(state, start);
startCount = res.delims; startCount = res.delims;

4
lib/rules_inline/links.js

@ -55,7 +55,7 @@ module.exports = function links(state, silent) {
// ^^^^^^ parsing link destination // ^^^^^^ parsing link destination
start = pos; start = pos;
if (parseLinkDestination(state, pos)) { if (parseLinkDestination(state, pos)) {
href = state.link_content; href = state.linkContent;
pos = state.pos; pos = state.pos;
} else { } else {
href = ''; href = '';
@ -72,7 +72,7 @@ module.exports = function links(state, silent) {
// [link]( <href> "title" ) // [link]( <href> "title" )
// ^^^^^^^ parsing link title // ^^^^^^^ parsing link title
if (pos < max && start !== pos && parseLinkTitle(state, pos)) { if (pos < max && start !== pos && parseLinkTitle(state, pos)) {
title = state.link_content; title = state.linkContent;
pos = state.pos; pos = state.pos;
// [link]( <href> "title" ) // [link]( <href> "title" )

21
lib/rules_inline/state_inline.js

@ -15,11 +15,22 @@ function StateInline(src, parser, options, env) {
this.pending = ''; this.pending = '';
this.pendingLevel = 0; this.pendingLevel = 0;
this.validateInsideLink = false; this.cache = {}; // Stores { start: end } pairs. Useful for backtrack
this.linkLevel = 0; // optimization of pairs parse (emphasis, strikes).
this.link_content = '';
this.label_nest_level = 0; // for stmd-like backtrack optimization // Link parser state vars
this.memo = {};
this.isInLabel = false; // Set true when seek link label - we should disable
// "paired" rules (emphasis, strikes) to not skip
// tailing `]`
this.linkLevel = 0; // Increment for each nesting link. Used to prevent
// nesting in definitions
this.linkContent = ''; // Temporary storage for link url
this.labelUnmatchedScopes = 0; // Track unpaired `[` for link labels
// (backtrack optimization)
} }

2
lib/rules_inline/strikethrough.js

@ -16,7 +16,7 @@ module.exports = function strikethrough(state, silent) {
// make del lower a priority tag with respect to links, same as <em>; // make del lower a priority tag with respect to links, same as <em>;
// this code also prevents recursion // this code also prevents recursion
if (state.validateInsideLink) { return false; } if (silent && state.isInLabel) { return false; }
if (state.level >= state.options.maxNesting) { return false; } if (state.level >= state.options.maxNesting) { return false; }

2
support/specsplit.js

@ -93,7 +93,7 @@ readFile(options.spec, 'utf8', function (error, input) {
}); });
if (!options.type) { if (!options.type) {
console.log(util.format('passed samples: %s, failed samples: %s', good.length, bad.length)); console.log(util.format('passed samples - %s, failed samples - %s', good.length, bad.length));
} else { } else {
var data = options.type === 'good' ? good : bad; var data = options.type === 'good' ? good : bad;

Loading…
Cancel
Save