Skip to content

Commit 4f01596

Browse files
committed
Update code, tests for 100% coverage
1 parent 4a02014 commit 4f01596

File tree

7 files changed

+80
-19
lines changed

7 files changed

+80
-19
lines changed

handlers/heading.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module.exports = heading;
55
var all = require('../all');
66

77
function heading(h, node) {
8-
var depth = Number(node.tagName.charAt(1)) || 1;
8+
var depth = Number(node.tagName.charAt(1));
9+
10+
/* istanbul ignore next - `else` shouldn’t happen, of course… */
11+
depth = depth || 1;
12+
913
return h(node, 'heading', {depth: depth}, all(h, node));
1014
}

handlers/list-item.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ module.exports = listItem;
55
var is = require('hast-util-is-element');
66
var all = require('../all');
77

8-
function listItem(h, node, parent) {
8+
function listItem(h, node) {
99
var children = node.children;
10-
var tail = !parent || parent.children[parent.children.length - 1] === node;
1110
var head = children[0];
1211
var checked = null;
1312
var loose = false;
@@ -64,10 +63,5 @@ function listItem(h, node, parent) {
6463
}
6564
}
6665

67-
/* Last list-item is never loose. */
68-
if (tail) {
69-
loose = false;
70-
}
71-
7266
return h(node, 'listItem', {loose: loose, checked: checked}, content);
7367
}

tests/fixtures/ol/index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515
<p>Bar.</p>
1616

1717
<ol start="3">
18-
<li><p>Alpha</p></li>
19-
<li><p>Bravo</p></li>
20-
<li><p>Charlie</p></li>
18+
<li>
19+
<p>Alpha</p>
20+
<p>Bravo</p>
21+
</li>
22+
<li>
23+
<p>Charlie</p>
24+
<p>Delta</p>
25+
</li>
26+
<li>
27+
<p>Echo</p>
28+
<p>Foxtrot</p>
29+
</li>
2130
</ol>
2231

2332
<p>Baz.</p>

tests/fixtures/ol/index.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ Foo.
1313
Bar.
1414

1515
3. Alpha
16-
4. Bravo
17-
5. Charlie
16+
17+
Bravo
18+
19+
4. Charlie
20+
21+
Delta
22+
23+
5. Echo
24+
25+
Foxtrot
1826

1927
Baz.
2028

tests/fixtures/ul/index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515
<p>Bar.</p>
1616

1717
<ul>
18-
<li><p>Alpha</p></li>
19-
<li><p>Bravo</p></li>
20-
<li><p>Charlie</p></li>
18+
<li>
19+
<p>Alpha</p>
20+
<p>Bravo</p>
21+
</li>
22+
<li>
23+
<p>Charlie</p>
24+
<p>Delta</p>
25+
</li>
26+
<li>
27+
<p>Echo</p>
28+
<p>Foxtrot</p>
29+
</li>
2130
</ul>
2231

2332
<p>Baz.</p>

tests/fixtures/ul/index.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ Foo.
1313
Bar.
1414

1515
- Alpha
16-
- Bravo
16+
17+
Bravo
18+
1719
- Charlie
1820

21+
Delta
22+
23+
- Echo
24+
25+
Foxtrot
26+
1927
Baz.
2028

2129
-···

tests/index.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var fs = require('fs');
44
var path = require('path');
5-
5+
var u = require('unist-builder');
6+
var h = require('hastscript');
67
var test = require('tape');
78
var hidden = require('is-hidden');
89
var negate = require('negate');
@@ -12,10 +13,38 @@ var html = require('rehype-parse');
1213
var stringify = require('remark-stringify');
1314
var assert = require('mdast-util-assert');
1415
var remove = require('unist-util-remove-position');
15-
var toMDAST = require('../');
16+
var toMDAST = require('..');
1617

1718
var fixtures = path.join(__dirname, 'fixtures');
1819

20+
test('core', function (t) {
21+
t.deepEqual(
22+
toMDAST(u('root', [h('strong', 'Alpha')])),
23+
u('root', [u('strong', [u('text', 'Alpha')])]),
24+
'should transform HAST to MDAST'
25+
);
26+
27+
t.deepEqual(
28+
toMDAST(u('root', [u('unknown', 'text')])),
29+
u('root', [u('text', 'text')]),
30+
'should transform unknown texts to `text`'
31+
);
32+
33+
t.deepEqual(
34+
toMDAST(u('root', [u('unknown', [h('em')])])),
35+
u('root', [u('emphasis', [])]),
36+
'should unwrap unknown parents'
37+
);
38+
39+
t.deepEqual(
40+
toMDAST(u('root', [u('unknown')])),
41+
u('root', []),
42+
'should ignore unknown voids'
43+
);
44+
45+
t.end();
46+
});
47+
1948
test('fixtures', function (t) {
2049
var fromHTML = unified()
2150
.use(html)

0 commit comments

Comments
 (0)