textlint rule to make sure every link in a document is available.
The primary target of this rule is Markdown documents, but it also works on plain text documents (See tests).
$ npm install textlint-rule-no-dead-link
$ npm install textlint textlint-rule-no-dead-link
$ textlint --rule textlint-rule-no-dead-link text-to-check.txt
Shows an error if a link is dead (i.e. its server returns one of the "non-ok" responses).
Shows an error if a link is obsolete or moved to another location (i.e. its server returns one of the "redirect" responses).
This error is fixable and textlint will automatically replace the obsolete links with their new ones if you run it with --fix
option.
Sometimes your files contain relative URIs, which don't have domain information in an URI string. In this case, we have to somehow resolve the relative URIs and convert them into absolute URIs.
The resolution strategy is as follows:
- If
baseURI
is specified, use that path to resolve relative URIs (See the below section for details). - If not, try to get the path of the file being linted and use its parent folder as the base path.
- If that's not available (e.g., when you are performing linting from API), put an error
Unable to resolve the relative URI
.
Please write your configurations in .textlintrc
.
The default options are:
{
"rules": {
"no-dead-link": {
"checkRelative": true,
"baseURI": null,
"ignore": [],
"preferGET": []
}
}
}
This rule checks the availability of relative URIs by default.
You can turn off the checks by passing false
to this option.
The base URI to be used for resolving relative URIs.
Though its name, you can pass either an URI starting with http
or https
, or an file path starting with /
.
Examples:
"no-dead-link": {
"baseURI": "http://example.com/"
}
"no-dead-link": {
"baseURI": "/Users/textlint/path/to/parent/folder/"
}
An array of URIs to be ignored. These URIs will be skipped from the availability checks.
Example:
"no-dead-link": {
"ignore": [
"http://example.com/not-exist/index.html",
"http://example.com/*" # Glob format
]
}
An array of origins to lets the rule connect to the origin's URL by GET
instead of default HEAD
request.
Although the rule will fall back to GET
method when HEAD
request is failed (status code is not between 200 and 300), in order to shorten time to run your test, you can use this option when you are sure that target origin always returns 5xx for HEAD
request.
Example:
"no-dead-link": {
"preferGET": [
"http://example.com"
]
}
npm test
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT License (http://nodaguti.mit-license.org/)