Browse Source

Removed dead code in block rules & improved tests coverage

pull/41/head
Vitaly Puzrin 10 years ago
parent
commit
18efc864bd
  1. 2
      lib/rules_block/blockquote.js
  2. 2
      lib/rules_block/heading.js
  3. 6
      lib/rules_block/hr.js
  4. 3
      lib/rules_block/list.js
  5. 38
      lib/rules_block/paragraph.js
  6. 17
      test/fixtures/markdown-it/commonmark_extras.txt

2
lib/rules_block/blockquote.js

@ -10,8 +10,6 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
if (pos > max) { return false; }
// check the block quote marker
if (state.src.charCodeAt(pos++) !== 0x3E/* > */) { return false; }

2
lib/rules_block/heading.js

@ -8,8 +8,6 @@ module.exports = function heading(state, startLine, endLine, silent) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
if (pos >= max) { return false; }
ch = state.src.charCodeAt(pos);
if (ch !== 0x23/* # */ || pos >= max) { return false; }

6
lib/rules_block/hr.js

@ -5,13 +5,9 @@
module.exports = function hr(state, startLine, endLine, silent) {
var marker, cnt, ch,
pos = state.bMarks[startLine],
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
pos += state.tShift[startLine];
if (pos > max) { return false; }
marker = state.src.charCodeAt(pos++);
// Check hr marker

3
lib/rules_block/list.js

@ -11,8 +11,6 @@ function skipBulletListMarker(state, startLine) {
pos = state.bMarks[startLine] + state.tShift[startLine];
max = state.eMarks[startLine];
if (pos >= max) { return -1; }
marker = state.src.charCodeAt(pos++);
// Check bullet
if (marker !== 0x2A/* * */ &&
@ -36,6 +34,7 @@ function skipOrderedListMarker(state, startLine) {
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
// List marker should have at least 2 chars (digit + dot)
if (pos + 1 >= max) { return -1; }
ch = state.src.charCodeAt(pos++);

38
lib/rules_block/paragraph.js

@ -34,26 +34,24 @@ module.exports = function paragraph(state, startLine/*, endLine*/) {
content = state.getLines(startLine, nextLine, state.blkIndent, false).trim();
state.line = nextLine;
if (content.length) {
state.tokens.push({
type: 'paragraph_open',
tight: false,
lines: [ startLine, state.line ],
level: state.level
});
state.tokens.push({
type: 'inline',
content: content,
level: state.level + 1,
lines: [ startLine, state.line ],
children: []
});
state.tokens.push({
type: 'paragraph_close',
tight: false,
level: state.level
});
}
state.tokens.push({
type: 'paragraph_open',
tight: false,
lines: [ startLine, state.line ],
level: state.level
});
state.tokens.push({
type: 'inline',
content: content,
level: state.level + 1,
lines: [ startLine, state.line ],
children: []
});
state.tokens.push({
type: 'paragraph_close',
tight: false,
level: state.level
});
return true;
};

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

@ -197,14 +197,13 @@ z")
z">foo</a></p>
.
Image coverage
Coverage. Image
.
![test]( x )
.
<p><img src="x" alt="test"></p>
.
.
![test][foo]
@ -212,7 +211,6 @@ Image coverage
.
<p>![test][foo]</p>
.
.
![test][[[
@ -220,3 +218,16 @@ Image coverage
.
<p>![test][[[</p>
.
.
![test](
.
<p>![test](</p>
.
Coverage. Link
.
[test](
.
<p>[test](</p>
.

Loading…
Cancel
Save