Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Header anchors for markdown-it.

License

NotificationsYou must be signed in to change notification settings

LeetCode-OpenSource/markdown-it-anchor

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header anchors formarkdown-it.

Usage

constmd=require('markdown-it')().use(require('markdown-it-anchor'),opts)

See ademo as JSFiddle.

Theopts object can contain:

NameDescriptionDefault
levelMinimum level to apply anchors on or array of selected levels.1
slugifyA custom slugification function.Seeindex.js
permalinkWhether to add permalinks next to titles.false
renderPermalinkA custom permalink rendering function.Seeindex.js
permalinkClassThe class of the permalink anchor.header-anchor
permalinkSymbolThe symbol in the permalink anchor.
permalinkBeforePlace the permalink before the title.false
permalinkHrefA custom permalinkhref rendering function.Seeindex.js
callbackCalled 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.

User-Friendly URLs

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 Support

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})

Table of Contents

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

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript100.0%

[8]ページ先頭

©2009-2025 Movatter.jp