npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mktoc

v1.0.10

Published

Generates a table of contents index

Downloads

28

Readme

Contents Index

Build Status npm version Coverage Status

Generate a table of contents index

Creates a list representing the structure of a document as determined by the headings in the document.

To inject the created list into a location in the document place the marker <!-- @toc --> in the source document.

By default it creates anchor links (#) to named anchors on the same page but the link behaviour may be disabled or customized using a destination function, see the api docs.

Install

npm i mktoc --save

For the command line interface install mkdoc globally (npm i -g mkdoc).



Usage

Create the stream and write a commonmark document:

var toc = require('mktoc')
  , ast = require('mkast');
ast.src('# Heading\n\n## Sub Heading\n\n')
  .pipe(toc())
  .pipe(ast.stringify({indent: 2}))
  .pipe(process.stdout);

Example

Create a standalone table of contents:

mkcat README.md | mktoc -s | mkout > TOC.md

Inject the table of contents into a document containing the <!-- @toc --> marker:

mkcat readme.md | mktoc | mkout > README.md

Set an initial heading with the specified level:

mkcat readme.md | mktoc --title 'Table of Contents' --level 2 | mkout > README.md

Only include headings for levels 2-4:

mkcat readme.md | mktoc -d 2 -m 4 | mkout > README.md

Create an ordered list and set the delimiter:

mkcat readme.md | mktoc -o -E '.' | mkout > README.md

Help

Usage: mktoc [options]

  Generates a table of contents index.

Options
  -t, --title=[TITLE]     Set initial heading
  -l, --level=[NUM]       Set level for initial heading
  -d, --depth=[LEVEL]     Ignore headings below LEVEL
  -m, --max=[LEVEL]       Ignore headings above LEVEL
  -p, --prefix=[VAL]      Set link destination prefix to VAL
  -b, --base=[URL]        Base URL for absolute links
  -B, --bullet=[CHAR]     Character for bullet lists
  -E, --delimiter=[CHAR]  Delimiter for ordered lists
  -D, --disable           Disable automatic links
  -o, --ordered           Create an ordered list
  -s, --standalone        Standalone index, discards input
  -h, --help              Display help and exit
  --version               Print the version and exit

[email protected]

API

toc

toc([opts][, cb])

Generate a document containing a table of contents list.

See Toc for more available options.

Returns an output stream.

  • opts Object processing options.
  • cb Function callback function.

Options

  • input Readable input stream.
  • output Writable output stream.

Toc

new Toc([opts])

Create a table of contents index stream.

Note that in order to build a complete index all data must be read so this implementation buffers incoming nodes and flushes them when the stream is ended writing the index nodes where necessary.

When the first child of a heading is a link it is preserved and no automatic link is created, otherwise when creating links inline markup in the heading is discarded.

If the standalone option is given then the incoming data is discarded and the document representing the index is flushed.

When a destination function is specified it is passed a string literal of the heading text and should return a URL, the function is invoked in the scope of this stream.

Typically prefix will be either a /, # or the empty string depending upon whether you want absolute, anchor or relative links. The default is to use # for anchor links on the same page.

If the bullet option is given it must be one of -, + or *.

If the delimiter option is given it must a period . or right parenthesis ).

  • opts Object processing options.

Options

  • standalone Boolean discard incoming data.
  • type String=bullet list output type, bullet or ordered.
  • link Boolean=true whether to create links in the output lists.
  • depth Number=1 ignore headings below this level.
  • max Number=6 ignore headings above this level.
  • destination Function builds the link URLs.
  • prefix String=# default link prefix.
  • base String a base path for absolute links.
  • bullet String=- character for bullet lists.
  • delimiter String=) delimiter for ordered lists.

License

MIT


Created by mkdoc on April 18, 2016