Skip to content

Commit

Permalink
Add name, non-header support for anchors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wooorm committed Feb 5, 2016
1 parent 39cfd46 commit ec06782
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ function gatherExposedFactory() {
if (filePath && ast) {
cache[filePath] = true;

visit(ast, 'heading', function (node) {
var data = node.data || /* istanbul ignore next */ {};
var attrs = data.htmlAttributes;
var id = (attrs && attrs.id) || data.id;
visit(ast, function (node) {
var data = node.data || {};
var attrs = data.htmlAttributes || {};
var id = attrs.name || attrs.id || data.id;

if (id) {
cache[filePath + '#' + id] = true;
Expand Down
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ is fine.
* [Command line](#command-line)
* [Programmatic](#programmatic)
* [Configuration](#configuration)
* [Integration](#integration)
* [Related](#related)
* [License](#license)

Expand Down Expand Up @@ -103,6 +104,20 @@ too. An example `.remarkrc` file could look as follows:
}
```

## Integration

**remark-validate-links** can detect anchors on nodes through
several properties on nodes:

* `node.data.htmlAttributes.name` — Used by [`remark-html`][remark-html]
to create a `name` attribute, which anchors can link to;

* `node.data.htmlAttributes.id` — Used by [`remark-html`][remark-html]
to create an `id` attribute, which anchors can link to;

* `node.data.id` — Used, in the future, by other tools to signal
unique identifiers on nodes.

## Related

* [`remark-lint`](https://github.com/wooorm/remark-lint)
Expand All @@ -111,3 +126,7 @@ too. An example `.remarkrc` file could look as follows:
## License

[MIT](LICENSE) © [Titus Wormer](http://wooorm.com)

<!-- Definitions -->

[remark-html]: https://github.com/wooorm/remark-html

0 comments on commit ec06782

Please sign in to comment.