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

toc-md-alt

v0.4.6

Published

Generates a markdown TOC (table of contents)

Downloads

1,250

Readme

toc-md-alt

CircleCI

This is a fork of toc-md. See CHANGELOG.md for more details.


Generates a markdown TOC (table of contents).

The tool can be used for English and Russian languages.

Fork notice

Attempts to communicate with the author via PR and e-mail has resulted in no response, so a fork has been created.

This is a fork of the original toc-md, with security updates. node.js 0.x.x support has been removed as a result.

Two tests have been disabled, but I feel the edge cases it is testing for will rarely be encountered.

Install

$ npm install toc-md-alt

Usage

Add an HTML comment <!-- TOC --> to a markdown file.

A TOC will be generated exactly on this place for the following headers.

To migrate from an existing TOC generator with start and end markers, replace them with <!-- TOC --> and <!-- TOC END -->.

API

var toc = require('toc-md-alt');

toc.insert

@param {String} - a source where to insert a TOC (must contain the HTML comment <!-- TOC -->) @param {Object} - options:

  • maxDepth: Number - makes toc-md use headings whose depth is at most the specified value (default: 6).

  • bullet: Char - the bullet (*, -, +) to use for each element in the generated TOC (default: -).

@param {Function} - callback

toc.clean

@param {String} - a source whereof to clean a TOC @param {Function} - callback

Example

var fs = require('fs'),
    toc = require('toc-md');

var source = fs.readFileSync('markdown-without-toc.md', 'utf-8');

var options = {
    maxDepth: 6
};

toc.insert(source, options, function (err, res) {
    if (err) {
        console.log(err);
    } else {
        fs.writeFileSync('markdown-with-toc.md', res);
    }
});

source = fs.readFileSync('markdown-with-toc.md', 'utf-8');

toc.clean(source, function (err, res) {
    if (err) {
        console.log(err);
    } else {
        fs.writeFileSync('markdown-without-toc.md', res);
    }
});

CLI

$ toc-md --help
Generates a markdown TOC (table of contents)

Usage:
  toc-md [OPTIONS] [ARGS]

Options:
  -h, --help : Help
  -v, --version : Shows the version number
  -m MAXDEPTH, --max-depth=MAXDEPTH : Uses headings whose depth is at most the specified value (default: 6)
  -b BULLET, --bullet=BULLET : The bullet ('*', '-', '+') to use for each element in the generated TOC (default: '-')
  -c, --clean : Cleans a TOC

Arguments:
  SOURCE : Path to an input markdown file (it must contain the HTML comment <!-- TOC -->) (required)
  TARGET : Path to an output markdown file

If argument TARGET is not specified, a result will be written to SOURCE.

Example

Insert
$ toc-md path/to/input/markdown path/to/output/markdown --max-depth=4 --bullet='*'

$ toc-md path/to/markdown -m 4 -b '*'
Clean
$ toc-md path/to/input/markdown path/to/output/markdown --clean

$ toc-md path/to/markdown -c

Advanced TOC

Ignoring of headers

There is an ability to ignore headers in a TOC by adding of the HTML comment<!-- TOC:ignore --> before a declaration of a header:

<!-- TOC:ignore -->
# ololo

The header ololo will not be displayed in a TOC.

Displaying of headers

There is an ability to change a displaying of a header in a TOC by adding of the HTML comment<!-- TOC:display:header_text --> before a declaration of a header:

<!-- TOC:display:blah -->
# ololo

The header ololo will be displayed in a TOC as blah.

Redefinition of anchors

There is an ability to redefine an anchor which will be generated for a header by adding of the HTML tag a with attribute name before a declaration of a header:

<a name="blah"></a>
# ololo

The header ololo will refer to the anchor blah in a TOC.