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
NODE_ENV=test mocha -R spec
echo "CommonMark stat:\n"
./support/specsplit.js test/fixtures/stmd/spec.txt

22
lib/links.js

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

6
lib/parser_inline.js

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

4
lib/parser_ref.js

@ -35,7 +35,7 @@ module.exports = function parse_reference(str, parser, options, env) {
// [label]: destination 'title'
// ^^^^^^^^^^^ parse this
if (!parseLinkDestination(state, pos)) { return -1; }
href = state.link_content;
href = state.linkContent;
pos = state.pos;
// [label]: destination 'title'
@ -49,7 +49,7 @@ module.exports = function parse_reference(str, parser, options, env) {
// [label]: destination 'title'
// ^^^^^^^ parse this
if (pos < max && start !== pos && parseLinkTitle(state, pos)) {
title = state.link_content;
title = state.linkContent;
pos = state.pos;
} else {
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:
// [foo *bar]()*
// [foo `bar]()`
if (state.validateInsideLink) { return false; }
if (silent && state.isInLabel) { return false; }
res = scanDelims(state, start);
startCount = res.delims;

4
lib/rules_inline/links.js

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

21
lib/rules_inline/state_inline.js

@ -15,11 +15,22 @@ function StateInline(src, parser, options, env) {
this.pending = '';
this.pendingLevel = 0;
this.validateInsideLink = false;
this.linkLevel = 0;
this.link_content = '';
this.label_nest_level = 0; // for stmd-like backtrack optimization
this.memo = {};
this.cache = {}; // Stores { start: end } pairs. Useful for backtrack
// optimization of pairs parse (emphasis, strikes).
// Link parser state vars
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>;
// this code also prevents recursion
if (state.validateInsideLink) { return false; }
if (silent && state.isInLabel) { 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) {
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 {
var data = options.type === 'good' ? good : bad;

Loading…
Cancel
Save