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/markdown

v0.0.4

Published

ToC generator for markdown.

Downloads

55

Readme

@toc/markdown

ToC generator for markdown.

If links in this document not avaiable, please access README on GitHub directly.

Description

Analyse markdown text and generate Table of Contents.

Table of Contents

Get & Started

  • API mode

    const toc = require('@toc/markdown');
    
    toc(markdownText);
    // Return markdown text containing a "Table of Contents" section.
  • CLI mode

    # Install globally.
    # Command `toc-md` will be created.
    npm install -g @toc/markdown
    
    # Read markdown file and write markdown text with "Table of Contents" 
    # section into another file.
    toc-md /path/of/input.md /path/of/output.md

API

  • void toc( string markdownText [, Object options ])

options may contain following properties:

  • options.indent number | string DEFAULT "\u0009"
    Indent used on creating sub list in the ToC catalog. The default value is a TABSTOP character.

  • options.ignore string | string[] DEFAULT "< position"
    Indicate what titles should be ignored.
    The possible values may be:

    // Titles of sections preceding ToC section will be ingored.
    { ignore: '< position' }
    
    // Titles of sections following ToC section will be ingored.
    { ignore: '> position' }
    
    // Title of section No.3 will be ignored.
    { ignore: 3 }
    
    // Title of section No.1, No.2, No.9 and the following will be ignored.
    { ignore: [ 1, 2, '> 9' ] }
  • options.position number DEFAULT 1
    Indicate where to put the generated ToC section.
    -1 means to put ToC at first (before the headline), while 0 to put ToC just after the headline.
    If the value is larger than 0, ToC will be put just before the n-th second leve title line.

  • options.title string DEFAULT "Table of Contents"
    If set falsy, generated ToC will be bare without section title.

  • options.overwrite boolean DEFAULT true
    Whether to overwrite existing ToC section (a second level section with the same title equals to options.title).

Links