rehype-slugs
rehype plugin to add ids to headings and output.
Last updated 2 months ago by justable .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install rehype-slugs 
SYNC missed versions from official npm registry.

rehype-slugs

rehype plugin to add ids to headings and output.

Installation

npm install unified
yarn unified

Usage

example.md looks as follows:

## [Hello](./example.md) World

Hello World

### Hello `World`

Hello World

## Hello <a href="./example.md">World</a>

Hello World

and example.js like this:

var vfile = require('to-vfile');
var slugs = require('rehype-slugs');
var remark = require('remark');
var remark2rehype = require('remark-rehype');

var result;
remark()
  .use(remark2rehype)
  .use(slugs, {
    maxDepth: 3,
    callback: function (res) {
      result = res;
    },
  })
  .process(vfile.readSync('example.md'), function (err, file) {
    if (err) throw err;
    console.log(slugs);
    console.log(String(file));
  });

Now, running node example.js yields:

[
  { id: '33bea', depth: 1, tagName: 'h2', text: 'Hello World' },
  { id: '1a67a', depth: 2, tagName: 'h3', text: 'Hello World' },
  { id: '50eb7', depth: 1, tagName: 'h2', text: 'Hello World' }
]
<h2 id="33bea"><a href="./heading.md">Hello</a> World</h2>
<p>Hello World</p>
<h3 id="1a67a">Hello <code>World</code></h3>
<p>Hello World</p>
<h2 id="50eb7">Hello World</h2>
<p>Hello World</p>

Current Tags

  • 0.0.4                                ...           latest (2 months ago)

4 Versions

  • 0.0.4                                ...           2 months ago
  • 0.0.3                                ...           2 months ago
  • 0.0.2                                ...           2 months ago
  • 0.0.1                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dev Dependencies (16)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |