GithubHelp home page GithubHelp logo

ruanyf / markdown-it-toc-and-anchor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from medfreeman/markdown-it-toc-and-anchor

3.0 3.0 1.0 51 KB

markdown-it plugin to add a toc and anchor links in headings

License: MIT License

JavaScript 100.00%

markdown-it-toc-and-anchor's Introduction

markdown-it-toc-and-anchor

Travis Build Status AppVeyor Build Status Version Coverage Status Dependency Status

markdown-it plugin to add toc and anchor links in headings

Installation

$ npm install markdown-it-toc-and-anchor

Usage

ES6

import markdownIt from "markdown-it"
import markdownItTocAndAnchor from "markdown-it-toc-and-anchor"

markdownIt({
    html: true,
    linkify: true,
    typography: true,
  })
    .use(markdownItTocAndAnchor, {
      // ...options
    })
    .render(md)

ES5 / CommonJS

var markdownIt = require('markdown-it'),
    markdownItTocAndAnchor = require('markdown-it-toc-and-anchor').default;

markdownIt({
    html: true,
    linkify: true,
    typography: true,
  })
    .use(markdownItTocAndAnchor, {
      // ...options
    })
    .render(md)

ℹ️ Note that the 'default' property has to be used when requiring this plugin, this is due to the use of Babel 6 now making ES6 compliant exports (Misunderstanding ES6 Modules, Upgrading Babel, Tears, and a Solution )

Options

toc

(default: true)

Allows you to enable/disable the toc transformation of @[toc]

tocClassName

(default: "markdownIt-TOC")

Option to customize html class of the <ul> wrapping the toc

tocFirstLevel

(default: 1)

Allows you to skip some heading level. Example: use 2 if you want to skip <h1> from the TOC.

tocLastLevel

(default: 6)

Allows you to skip some heading level. Example: use 5 if you want to skip <h6> from the TOC.

tocCallback

(default: null)

Allows you to get toc contents externally by executing a callback function returning toc elements, in addition / instead of using @[toc] tag in content. Example :

  markdownIt({
    html: true,
    linkify: true,
    typography: true,
  })
    .use(markdownItTocAndAnchor, {
      tocCallback: function(tocMarkdown, tocArray, tocHtml) {
        console.log(tocHtml)
      }
    })
    .render(md)

To allow callback to be more flexible, this option is also available in global markdown-it options, and in render environment. Example :

Callback in global markdown-it options
  var mdIt = markdownIt({
    html: true,
    linkify: true,
    typography: true,
  })
    .use(markdownItTocAndAnchor)

  ....

  mdIt.set({
    tocCallback: function(tocMarkdown, tocArray, tocHtml) {
      console.log(tocHtml)
    }
  })
    .render(md)
Callback in render environment
  var mdIt = markdownIt({
    html: true,
    linkify: true,
    typography: true,
  })
    .use(markdownItTocAndAnchor)

  ....

  mdIt
    .render(md, {
      tocCallback: function(tocMarkdown, tocArray, tocHtml) {
        console.log(tocHtml)
      }
    })

anchorLink

(default: true)

Allows you to enable/disable the anchor link in the headings

anchorLinkSymbol

(default: "#")

Allows you to customize the anchor link symbol

anchorLinkSpace

(default: true)

Allows you to enable/disable inserting a space between the anchor link and heading.

anchorLinkSymbolClassName

(default: null)

Allows you to customize the anchor link symbol class name. If not null, symbol will be rendered as <span class="anchorLinkSymbolClassName">anchorLinkSymbol</span>.

anchorLinkBefore

(default: true)

Allows you to prepend/append the anchor link in the headings

anchorLinkPrefix

(default: undefined)

Allows you to add a prefix to the generated header ids, e.g. section-.

anchorClassName

(default: "markdownIt-Anchor")

Allows you to customize the anchor link class

resetIds

(default: true)

Allows you to reset (or not) ids incrementation. Use it if you will have multiple documents on the same page.


CONTRIBUTING

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests ($ npm test).

markdown-it-toc-and-anchor's People

Contributors

medfreeman avatar moox avatar ruanyf avatar tylerlong avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kevinyzy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.