Skip to content

Commit 6522186

Browse files
committed
feat: check anchor links
Issue #91
1 parent cfdb731 commit 6522186

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## Version 3.10.0
4+
5+
* #91 check anchor links.
6+
37
## Version 3.9.3
48

59
* #184 fix issue with config loading. (@kenji-miyake)

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = function markdownLinkCheck(markdown, opts, callback) {
6060
}, markdown);
6161
}
6262

63-
const { links } = markdownLinkExtractor(markdown);
63+
const { links, anchors } = markdownLinkExtractor(markdown);
6464
const linksCollection = _.uniq(links);
6565
const bar = (opts.showProgressBar) ?
6666
new ProgressBar('Checking... [:bar] :percent', {
@@ -70,6 +70,8 @@ module.exports = function markdownLinkCheck(markdown, opts, callback) {
7070
total: linksCollection.length
7171
}) : undefined;
7272

73+
opts.anchors = anchors;
74+
7375
async.mapLimit(linksCollection, 2, function (link, callback) {
7476
if (opts.ignorePatterns) {
7577
const shouldIgnore = opts.ignorePatterns.some(function(ignorePattern) {

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"async": "^3.2.3",
3737
"chalk": "^4.1.2",
3838
"commander": "^6.2.0",
39-
"link-check": "^5.0.3",
39+
"link-check": "^5.1.0",
4040
"lodash": "^4.17.21",
4141
"markdown-link-extractor": "^2.0.1",
4242
"needle": "^3.0.0",

test/hash-links.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Foo
2+
3+
This is a test.
4+
5+
## Bar
6+
7+
The title is [Foo](#foo).
8+
9+
## Baz
10+
11+
The second section is [Bar](#bar).
12+
13+
## Uh, oh
14+
15+
There is no section named [Potato](#potato).

test/markdown-link-check.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -339,4 +339,15 @@ describe('markdown-link-check', function () {
339339
done();
340340
});
341341
});
342+
it('check hash links', function (done) {
343+
markdownLinkCheck(fs.readFileSync(path.join(__dirname, 'hash-links.md')).toString(), {}, function (err, result) {
344+
expect(err).to.be(null);
345+
expect(result).to.eql([
346+
{ link: '#foo', statusCode: 200, err: null, status: 'alive' },
347+
{ link: '#bar', statusCode: 200, err: null, status: 'alive' },
348+
{ link: '#potato', statusCode: 404, err: null, status: 'dead' },
349+
]);
350+
done();
351+
});
352+
});
342353
});

0 commit comments

Comments
 (0)