Skip to content

Commit a503059

Browse files
committed
Add tests and fix title bug
1 parent 82713e9 commit a503059

File tree

5 files changed

+121
-5
lines changed

5 files changed

+121
-5
lines changed

lib/search.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ function search(root, expression, maxDepth) {
4949
*/
5050

5151
visit(root, HEADING, function (child, index, parent) {
52-
var value = (child.data && child.data.hProperties && child.data.hProperties.id) ?
53-
child.data.hProperties.id :
54-
toString(child);
55-
var id = slugs.slug(value);
52+
var value = toString(child);
53+
var id = child.data && child.data.hProperties && child.data.hProperties.id;
54+
id = slugs.slug(id || value);
5655

5756
if (parent !== root) {
5857
return;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"esmangle": "^1.0.1",
4444
"istanbul": "^0.4.4",
4545
"remark": "^8.0.0",
46+
"remark-attr": "^0.6.2",
4647
"remark-cli": "^4.0.0",
4748
"remark-comment-config": "^5.0.0",
4849
"remark-github": "^7.0.0",

test/fixtures/normal-attr/input.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Something
2+
3+
## Something else
4+
{ #else }
5+
6+
Text.
7+
8+
## Something elsefi
9+
10+
# Something also
11+
{ #something }
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"index": null,
3+
"endIndex": null,
4+
"map": {
5+
"type": "list",
6+
"ordered": false,
7+
"children": [
8+
{
9+
"type": "listItem",
10+
"loose": true,
11+
"children": [
12+
{
13+
"type": "paragraph",
14+
"children": [
15+
{
16+
"type": "link",
17+
"title": null,
18+
"url": "#something",
19+
"children": [
20+
{
21+
"type": "text",
22+
"value": "Something"
23+
}
24+
]
25+
}
26+
]
27+
},
28+
{
29+
"type": "list",
30+
"ordered": false,
31+
"children": [
32+
{
33+
"type": "listItem",
34+
"loose": false,
35+
"children": [
36+
{
37+
"type": "paragraph",
38+
"children": [
39+
{
40+
"type": "link",
41+
"title": null,
42+
"url": "#else",
43+
"children": [
44+
{
45+
"type": "text",
46+
"value": "Something else"
47+
}
48+
]
49+
}
50+
]
51+
}
52+
]
53+
},
54+
{
55+
"type": "listItem",
56+
"loose": false,
57+
"children": [
58+
{
59+
"type": "paragraph",
60+
"children": [
61+
{
62+
"type": "link",
63+
"title": null,
64+
"url": "#something-elsefi",
65+
"children": [
66+
{
67+
"type": "text",
68+
"value": "Something elsefi"
69+
}
70+
]
71+
}
72+
]
73+
}
74+
]
75+
}
76+
]
77+
}
78+
]
79+
},
80+
{
81+
"type": "listItem",
82+
"loose": false,
83+
"children": [
84+
{
85+
"type": "paragraph",
86+
"children": [
87+
{
88+
"type": "link",
89+
"title": null,
90+
"url": "#something-1",
91+
"children": [
92+
{
93+
"type": "text",
94+
"value": "Something also"
95+
}
96+
]
97+
}
98+
]
99+
}
100+
]
101+
}
102+
]
103+
}
104+
}

test/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var test = require('tape');
33
var fs = require('fs');
44
var path = require('path');
55
var remark = require('remark');
6+
var remarkAttr = require('remark-attr');
67
var toc = require('..');
78

89
var read = fs.readFileSync;
@@ -29,7 +30,7 @@ test('Fixtures', function (t) {
2930
}).forEach(function (fixture) {
3031
var filepath = join(ROOT, fixture);
3132
var output = JSON.parse(read(join(filepath, 'output.json'), 'utf8'));
32-
var input = remark().parse(read(join(filepath, 'input.md'), 'utf-8'));
33+
var input = remark().use(remarkAttr).parse(read(join(filepath, 'input.md'), 'utf-8'));
3334
var config = join(filepath, 'config.json');
3435
var result;
3536

0 commit comments

Comments
 (0)