Skip to content

Commit

Permalink
Introduce slugifyWithState to avoid breaking change with slugify
Browse files Browse the repository at this point in the history
…second argument
  • Loading branch information
valeriangalliat committed Aug 24, 2024
1 parent 2e889a1 commit 3f99b83
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 15 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ const md = require('markdown-it')()
.use(require('markdown-it-anchor'), { slugify: s => slugify(s) })
```

### Custimizing the slugify input

Additionally, if you want to further customize the title that gets
passed to the `slugify` function, you can do so by customizing the
`getTokensText` function, that gets the plain text from a list of
Expand All @@ -144,6 +146,18 @@ the previous approach with a stock markdown-it, but would also include
custom tokens added by any of your markdown-it plugins, which might or
might not be desirable for you. Now you have the option!

### Slugifying with state

If you need access to the markdown-it state from the slugify function,
e.g. to access `state.env`, you can use `slugifyWithState` instead.

```js
const md = require('markdown-it')()
.use(require('markdown-it-anchor'), {
slugifyWithState: (title, state) => `${state.env.id}-${slugify(title)}`
})
```

## Manually setting the `id` attribute

You might want to explicitly set the `id` attribute of your headings
Expand Down
2 changes: 1 addition & 1 deletion dist/markdownItAnchor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/markdownItAnchor.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 3f99b83

Please sign in to comment.