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

markdown-it-toc-ilm

v0.3.8

Published

A Markdown-it plugin for extracting TOC from markdown with attributes

Downloads

2

Readme

markdown-it-table-of-contents

A table of contents plugin for Markdown-it. Based on https://github.com/oktavilla/markdown-it-table-of-contents but with some additional features to support ILM attribute based overrides. For example, in ILM, only headers with an explicit class .toc(1-4) get added to the table of contents at the level specified. Moreover the optional attribute 'toc' overrides the contents displayed.

(ILM is a private text editor for producing custom audio-aligned ebooks supporting random-access to contents.)

For example:

# Title not Shown TOC {.title}

## Chapter 4. This is Shown in TOC but with a much shorter display title   {toc="4. Shorter Title"}

### This is a subtitle not shown in TOC {.notoc}

### This one is shown in TOC

Usage

var MarkdownIt = require("markdown-it");
var md = new MarkdownIt();

md.use(require("markdown-it-anchor")); // Optional, but makes sense as you really want to link to something
md.use(require("markdown-it-toc-ilm"));

Then add [[toc]] where you want the table of contents to be added in your markdown.

When using with md-ilm module, the parsing object returns a field toc with a useful Table of Contents object.

Options

You may specify options when useing the plugin. like so:

md.use(require("markdown-it-table-of-contents"), options);

These options are available:

Name | Description | Default ------------------|-----------------------------------------------------|------------------------------------ "includeLevel" | Headings levels to use (2 for h2:s etc) | [1, 2] "containerClass" | The class for the container DIV | "table-of-contents" "slugify" | A custom slugification function | string.js' slugify "markerPattern" | Regex pattern of the marker to be replaced with TOC | /^\[\[toc\]\]/im "listType" | Type of list (ul for unordered, ol for ordered) | ul "format" | A function for formatting headings (see below) | undefined "ilmStyle" | Follow ilm-style TOC rules (keep compatibility) | false "override_toc" | A function for overriding default selection rules | undefined

format is an optional function for changing how the headings are displayed in the TOC.

function format(headingAsString) {
  // manipulate the headings as you like here.
  return manipulatedHeadingString;
}

override_toc is an optional function for overriding header selection rules.

function override_toc(heading, op) {
  // op = {isShown (true), displayText (heading), level (1-4}
  // read heading.text, heading.classes, heading.attrs, heading.tag
  // modify and return op: {isShown (bool), displayText (str), level (1-4)} 
  return op;
}