项目作者: farskid

项目描述 :
Remarkable plugin to auto generate unique header ids, highly customizable
高级语言: JavaScript
项目地址: git://github.com/farskid/remarkable-header-ids.git
创建时间: 2020-03-18T00:33:14Z
项目社区:https://github.com/farskid/remarkable-header-ids

开源协议:MIT License

下载


remarkable-header-ids NPM version NPM downloads Build Status

Autogenerate unique ids for text headers (h1,…h6)

Install

Install with npm:

  1. $ npm install --save remarkable-header-ids

Usage

  1. const HeaderIdsPlugin = require("remarkable-header-ids");
  2. const Remarkable = require("remarkable");
  3. const markdownParser = new Remarkable().use(
  4. HeaderIdsPlugin()
  5. );

Options

Params

Option name Type defaultValue Note
levels number[] [1, 2, 3, 4, 5, 6]
anchorClassName string “header-anchor”
anchorText string “#” When anchorText is empty, the anchor will not be rendered at all
headerId (slug: string) => string slug => “heading-#” + slug

Example

  1. const Remarkable = require("remarkable");
  2. const HeaderIdsPlugin = require("remarkable-header-ids");
  3. const parser = new Remarkable().use(
  4. HeaderIdsPlugin({
  5. levels: [2], // only transform h2
  6. anchorClassName: "this-is-anchor-in-header",
  7. anchorText: "AnchorText",
  8. headerId: (slug) =>
  9. `header-that-has-this-anchor-${slug}`,
  10. })
  11. );

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for avice on opening issues, pull requests, and coding standards.

Tests

Test content is located inside the test directory. For more info regarding the internals of test suite, check out test/parse.js.

to run the test, execute npm test from the root directory. This script will render into test/parsed.html.

Author

Farzad Yousefzadeh

License

Copyright © 2020, github/farskid.
Released under the MIT license.