Browse Source

Removed unused code & improved tests coverage for some rules.

pull/24/head
Vitaly Puzrin 10 years ago
parent
commit
04ee60d3c4
  1. 2
      lib/common/html_re.js
  2. 2
      lib/common/utils.js
  3. 30
      lib/renderer.js
  4. 6
      lib/rules_inline/del.js
  5. 7
      lib/rules_inline/emphasis.js
  6. 63
      test/fixtures/markdown-it/commonmark_extras.txt

2
lib/common/html_re.js

@ -11,7 +11,7 @@ function replace(regex, options) {
if (!name) { if (!name) {
return new RegExp(regex, options); return new RegExp(regex, options);
} }
val = val.source || val; val = val.source;
regex = regex.replace(name, val); regex = regex.replace(name, val);
return self; return self;
}; };

2
lib/common/utils.js

@ -10,7 +10,7 @@ function isString(obj) { return _class(obj) === '[object String]'; }
var _hasOwnProperty = Object.prototype.hasOwnProperty; var _hasOwnProperty = Object.prototype.hasOwnProperty;
function has(object, key) { function has(object, key) {
return object ? _hasOwnProperty.call(object, key) : false; return _hasOwnProperty.call(object, key);
} }
// Merge objects // Merge objects

30
lib/renderer.js

@ -210,36 +210,6 @@ rules.del_close = function (/* tokens, idx, options, env */) {
}; };
rules.ins_open = function (/* tokens, idx, options, env */) {
return '<ins>';
};
rules.ins_close = function (/* tokens, idx, options, env */) {
return '</ins>';
};
rules.mark_open = function (/* tokens, idx, options, env */) {
return '<mark>';
};
rules.mark_close = function (/* tokens, idx, options, env */) {
return '</mark>';
};
rules.sub_open = function (/*tokens, idx, options, env */) {
return '<sub>';
};
rules.sub_close = function (/*tokens, idx, options, env */) {
return '</sub>';
};
rules.sup_open = function (/*tokens, idx, options, env */) {
return '<sup>';
};
rules.sup_close = function (/*tokens, idx, options, env */) {
return '</sup>';
};
rules.hardbreak = function (tokens, idx, options /*, env */) { rules.hardbreak = function (tokens, idx, options /*, env */) {
return options.xhtmlOut ? '<br />\n' : '<br>\n'; return options.xhtmlOut ? '<br />\n' : '<br>\n';
}; };

6
lib/rules_inline/del.js

@ -47,7 +47,8 @@ module.exports = function(state, silent) {
startCount = res.delims; startCount = res.delims;
if (!res.can_open) { if (!res.can_open) {
state.pos += startCount; state.pos += startCount;
if (!silent) { state.pending += state.src.slice(start, state.pos); } // Earlier we checked !silent, but this implementation does not need it
state.pending += state.src.slice(start, state.pos);
return true; return true;
} }
@ -89,11 +90,10 @@ module.exports = function(state, silent) {
state.posMax = state.pos; state.posMax = state.pos;
state.pos = start + 2; state.pos = start + 2;
if (!silent) { // Earlier we checked !silent, but this implementation does not need it
state.push({ type: 'del_open', level: state.level++ }); state.push({ type: 'del_open', level: state.level++ });
state.md.inline.tokenize(state); state.md.inline.tokenize(state);
state.push({ type: 'del_close', level: --state.level }); state.push({ type: 'del_close', level: --state.level });
}
state.pos = state.posMax + 2; state.pos = state.posMax + 2;
state.posMax = max; state.posMax = max;

7
lib/rules_inline/emphasis.js

@ -62,7 +62,8 @@ module.exports = function emphasis(state, silent) {
startCount = res.delims; startCount = res.delims;
if (!res.can_open) { if (!res.can_open) {
state.pos += startCount; state.pos += startCount;
if (!silent) { state.pending += state.src.slice(start, state.pos); } // Earlier we checked !silent, but this implementation does not need it
state.pending += state.src.slice(start, state.pos);
return true; return true;
} }
@ -118,7 +119,8 @@ module.exports = function emphasis(state, silent) {
state.posMax = state.pos; state.posMax = state.pos;
state.pos = start + startCount; state.pos = start + startCount;
if (!silent) { // Earlier we checked !silent, but this implementation does not need it
// we have `startCount` starting and ending markers, // we have `startCount` starting and ending markers,
// now trying to serialize them into tokens // now trying to serialize them into tokens
for (count = startCount; count > 1; count -= 2) { for (count = startCount; count > 1; count -= 2) {
@ -132,7 +134,6 @@ module.exports = function emphasis(state, silent) {
for (count = startCount; count > 1; count -= 2) { for (count = startCount; count > 1; count -= 2) {
state.push({ type: 'strong_close', level: --state.level }); state.push({ type: 'strong_close', level: --state.level });
} }
}
state.pos = state.posMax + startCount; state.pos = state.posMax + startCount;
state.posMax = max; state.posMax = max;

63
test/fixtures/markdown-it/commonmark_extras.txt

@ -1,5 +1,4 @@
Regression tests for link backtracking optimizations: Regression tests for link backtracking optimizations:
. .
[[some unrelated text [link] [[some unrelated text [link]
@ -10,7 +9,6 @@ Regression tests for link backtracking optimizations:
This is not a valid emphasis, because \n considered a whitespace: This is not a valid emphasis, because \n considered a whitespace:
. .
**test **test
** **
@ -33,7 +31,6 @@ test
Link label has priority over emphasis (not covered by commonmark tests): Link label has priority over emphasis (not covered by commonmark tests):
. .
[**link]()** [**link]()**
@ -45,7 +42,6 @@ Link label has priority over emphasis (not covered by commonmark tests):
Issue #55: Issue #55:
. .
![test] ![test]
@ -57,7 +53,6 @@ Issue #55:
Should unescape only needed things in link destinations/titles: Should unescape only needed things in link destinations/titles:
. .
[test](<\f\o\o\>\\>) [test](<\f\o\o\>\\>)
. .
@ -72,7 +67,6 @@ Should unescape only needed things in link destinations/titles:
Not a closing tag Not a closing tag
. .
</ 123> </ 123>
. .
@ -81,7 +75,6 @@ Not a closing tag
Not a list item Not a list item
. .
1.list 1.list
. .
@ -89,8 +82,31 @@ Not a list item
. .
Coverage. Direcctive can terminate paragraph. Normalize link destination, but not text inside it:
.
<http://example.com/α%CE%B2γ%CE%B4>
.
<p><a href="http://example.com/%CE%B1%CE%B2%CE%B3%CE%B4">http://example.com/α%CE%B2γ%CE%B4</a></p>
.
Autolinks do not allow escaping:
.
<http://example.com/\[\>
.
<p><a href="http://example.com/%5C%5B%5C">http://example.com/\[\</a></p>
.
Should not throw exception on mailformed URI
.
[foo](<&#x25;test>)
.
<p><a href="%25test">foo</a></p>
.
Coverage. Directive can terminate paragraph.
. .
a a
<?php <?php
@ -99,27 +115,40 @@ a
<?php <?php
. .
Normalize link destination, but not text inside it:
Coverage. Nested email autolink (silent mode)
. .
<http://example.com/α%CE%B2γ%CE%B4> *<foo@bar.com>*
. .
<p><a href="http://example.com/%CE%B1%CE%B2%CE%B3%CE%B4">http://example.com/α%CE%B2γ%CE%B4</a></p> <p><em><a href="mailto:foo@bar.com">foo@bar.com</a></em></p>
. .
Autolinks do not allow escaping:
Coverage. Unpaired nested backtick (silent mode)
. .
<http://example.com/\[\> *`foo*
. .
<p><a href="http://example.com/%5C%5B%5C">http://example.com/\[\</a></p> <p><em>`foo</em></p>
. .
Should not throw exception on mailformed URI Coverage. Entities.
.
*&*
*&#x20;*
*&amp;*
. .
[foo](<&#x25;test>) <p><em>&amp;</em></p>
<p><em> </em></p>
<p><em>&amp;</em></p>
. .
<p><a href="%25test">foo</a></p>
Coverage. Escape.
.
*\a*
.
<p><em>\a</em></p>
. .

Loading…
Cancel
Save