2.0.2 • Published 7 days ago

rehype-postfix-footnote-anchors v2.0.2

Weekly downloads
456
License
MIT
Repository
github
Last release
7 days ago

rehype-postfix-footnote-anchors Build Status Coverage Status

This rehype plugin appends a custom postfix to footnotes, or changes the anchors/IDs to/from footnotes.

When you render several pieces of Markdown to HTML in a same webpage you might want to make sure that footnotes will not conflict between each piece of rendered HTML.

For instance:

*

```md
foo[^foo]

[^foo]: Footnote :)
```

*

```md
bar[^foo]

[^foo]: Conflict?
```

Rendering both of these will have the note next to bar link to Footnote :) instead of Conflict?, and Conflict? will have a link to go back to foo instead of bar.

This plugin plays well with remark-numbered-footnotes. Using remark-numbered-footnotes increases the risks of conflicts, hence the interest of postfixing footnote anchors.

Installation

npm:

npm install rehype-postfix-footnote-anchors

Usage

Dependencies:

const unified = require('unified')
const remarkParse = require('remark-parse')
const rehypePostfixFoonotes = require('rehype-postfix-footnote-anchors')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

Usage:

unified()
  .use(reParse, {footnotes: true})
  .use(remark2rehype)
  .use(rehypePostfixFoonotes, postfix)
  .use(stringify)

Configuration

In the above Usage example, postfix can be one of two things:

  • a string: postfix = '-my-postfix'

    postfix will be appended to the existing footnotes identifiers

  • a function: postfix = (identifier: string): string => 'foo' + identifier + 'bar'

    postfix will be called with the footnote identifier and should return a string

License

MIT © Zeste de Savoir

2.0.2

7 days ago

2.0.1

3 years ago

2.0.0

4 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago