git.iko.soy/typeable/remark-validate-links
on main help sign in
Add `name`, non-header support for anchors

This update adds support for non-header nodes with `data.htmlAttributes.id` or `data.id` properties, and it adds support for `data.htmlAttributes.name`. Plus, a section on this integration method is now in `readme.md`. Closes GH-1.

commitec067829f825c084e63da20d30dfe272b23dff59 authorTitus Wormer <tituswormer@gmail.com> dateFri 5 Feb 2016, 10:55 (11 years ago) parent39cfd46
2 files changed+23−4
index.js+4−4 readme.md+19
index.js+4−4
@@ -293,10 +293,10 @@ function gatherExposedFactory() {
293293 if (filePath && ast) {
294294 cache[filePath] = true;
295295
296− visit(ast, 'heading', function (node) {
297− var data = node.data || /* istanbul ignore next */ {};
298− var attrs = data.htmlAttributes;
299− var id = (attrs && attrs.id) || data.id;
296+ visit(ast, function (node) {
297+ var data = node.data || {};
298+ var attrs = data.htmlAttributes || {};
299+ var id = attrs.name || attrs.id || data.id;
300300
301301 if (id) {
302302 cache[filePath + '#' + id] = true;
readme.md+19
@@ -19,6 +19,7 @@ is fine.
1919* [Command line](#command-line)
2020* [Programmatic](#programmatic)
2121* [Configuration](#configuration)
22+* [Integration](#integration)
2223* [Related](#related)
2324* [License](#license)
2425
@@ -103,6 +104,20 @@ too. An example `.remarkrc` file could look as follows:
103104}
104105```
105106
107+## Integration
108+
109+**remark-validate-links** can detect anchors on nodes through
110+several properties on nodes:
111+
112+* `node.data.htmlAttributes.name` — Used by [`remark-html`][remark-html]
113+ to create a `name` attribute, which anchors can link to;
114+
115+* `node.data.htmlAttributes.id` — Used by [`remark-html`][remark-html]
116+ to create an `id` attribute, which anchors can link to;
117+
118+* `node.data.id` — Used, in the future, by other tools to signal
119+ unique identifiers on nodes.
120+
106121## Related
107122
108123* [`remark-lint`](https://github.com/wooorm/remark-lint)
@@ -111,3 +126,7 @@ too. An example `.remarkrc` file could look as follows:
111126## License
112127
113128[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
129+
130+<!-- Definitions -->
131+
132+[remark-html]: https://github.com/wooorm/remark-html