- Notifications
You must be signed in to change notification settings - Fork2
Header anchors for markdown-it.
License
LeetCode-OpenSource/markdown-it-anchor
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Header anchors formarkdown-it.
constmd=require('markdown-it')().use(require('markdown-it-anchor'),opts)
See ademo as JSFiddle.
Theopts object can contain:
| Name | Description | Default |
|---|---|---|
level | Minimum level to apply anchors on or array of selected levels. | 1 |
slugify | A custom slugification function. | Seeindex.js |
permalink | Whether to add permalinks next to titles. | false |
renderPermalink | A custom permalink rendering function. | Seeindex.js |
permalinkClass | The class of the permalink anchor. | header-anchor |
permalinkSymbol | The symbol in the permalink anchor. | ¶ |
permalinkBefore | Place the permalink before the title. | false |
permalinkHref | A custom permalinkhref rendering function. | Seeindex.js |
callback | Called with token and info after rendering. | undefined |
TherenderPermalink function takes the slug, an options object withthe above options, and then all the usual markdown-it renderingarguments.
All headers abovelevel will then have anid attribute with a slugof their content.level can also be an array of headers levels toapply the anchor, like[2, 3] to have an anchor on only level 2 and3 headers.
Ifpermalink istrue, a¶ symbol linking to the header itself willbe added.
You may want to use thelink symbol aspermalinkSymbol, or a symbol from your favorite web font.
Thecallback option is a function that will be called at the end ofrendering with thetoken and aninfo object. Theinfo object hastitle andslug properties with the token content and the slug usedfor the identifier.
Starting fromv5.0.0,markdown-it-anchor dropped packagestringkeeping it's core value of being an unopinionated and secure library. Yet,users looking for backward compatibility may want the old slugify:
$ npm i -S string
conststring=require('string')constlegacySlugify=s=>string(s).slugify().toString()constmd=require('markdown-it')()constanchor=require('markdown-it-anchor',{slugify:legacySlugify})
Unicode is supported by default. Yet, if you are looking for a "prettier"--opinionated-- link,i.e without %xx, you may want to take a look atuslug:
$ npm i -S uslug
constuslug=require('uslug')constuslugify=s=>uslug(s)constmd=require('markdown-it')()constanchor=require('markdown-it-anchor',{slugify:uslugify})
Looking for an automatic table of contents (TOC) generator? Take a look atmarkdown-it-toc-done-right it'smade from the ground to be a great companion of this plugin.
About
Header anchors for markdown-it.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Languages
- JavaScript100.0%