Socket
Socket
Sign inDemoInstall

markdown-it-github-headings

Package Overview
Dependencies
3
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    markdown-it-github-headings

Add GitHub style anchor tags to headers


Version published
Weekly downloads
2K
increased by25.86%
Maintainers
3
Install size
104 kB
Created
Weekly downloads
 

Changelog

Source

2.0.1 2022-06-09

  • Add TypeScript Declaration #19 Thank you @ashaifarhan for contributing!
  • Updated dev dependencies to squelch audit warnings.

Readme

Source

markdown-it-github-headings

Add GitHub style anchor tags to headers

npm travis standard

Install

npm install markdown-it-github-headings

Usage

var md = require('markdown-it')()
  .use(require('markdown-it-github-headings'), options)

Options and Defaults

The defaults will make the heading anchors behave as close to how GitHub behaves as possible.

NameDescriptionDefault
classNamename of the class that will be added to the anchor taganchor
prefixHeadingIdsadd a prefix to each heading ID. (see security note below)true
prefixif prefixHeadingIds is true, use this string to prefix each ID.user-content-
enableHeadingLinkIconsAdds the icon next to each headingtrue
linkIconIf enableHeadingLinkIcons is true, use this to supply a custom icon (or anything really)
resetSluggerreset the slugger counter between .render calls for duplicate headers. (See tests for example)true

Why should I prefix heading IDs?

When using user generated content, its possible to run into DOM Clobbering when heading IDs are generated. Since IDs are used by JavaScript and CSS, a user could craft a page that breaks functionality or styles. A good way to avoid clobbering is to add a prefix to every generated ID to ensure they cannot overlap with existing IDs.

If you have full control over the content, there is less of a risk, but be aware that strange bugs related to DOM Clobbering are still possible!

For more information, here are some good resources on the topic:

One solution is to write some client side JavaScript to force non-prefixed hashes to jump to prefixed anchors. This is how its handled on GitHub and npmjs.com.

Check out marky-deep-links for an example (works great with browserify or webpack).

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC

Keywords

FAQs

Last updated on 09 Jun 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc