Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-toc-generator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-toc-generator

The Table of Contents Generator is a JavaScript library that generates a table of contents based on the headings (e.g., ``, ``, ``) within an HTML document. It provides options for customizing the generated table of contents.

  • 0.1.3
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Table of Contents Generator

The Table of Contents Generator is a JavaScript library that generates a table of contents based on the headings (e.g., <h1>, <h2>, <h3>) within an HTML document. It provides options for customizing the generated table of contents.

  • No external dependencies
  • Size: 1.33 kB (minified and gzipped)

Installation

You can install the Table of Contents Generator library using npm:

npm install html-toc-generator

Usage

To use the Table of Contents Generator in your project, follow these steps:

  1. Import the library:
import TableOfContents from 'html-toc-generator';
  1. Create an instance of the TableOfContents class:
const options = {
  attributes: ['h1', 'h2', 'h3'],
  appendTo: 'body',
  containerClassName: 'toc',
  ordered: false,
  contentSelector: '#content'
};

const tableOfContents = new TableOfContents(options);
  1. Call the init method to generate the table of contents:
tableOfContents.init();

Options

The TableOfContents class accepts an optional options object during initialization. The available options are:

OptionTypeDefault ValueOptionalDescription
attributesstring[]['h1', 'h2', 'h3']YesAn array of HTML heading tag names to include in the table of contents.
appendTostring'body'YesThe selector of the element to which the table of contents should be appended.
containerClassNamestring'toc'YesThe CSS class name to be applied to the container element of the table of contents.
orderedbooleanfalseYesA boolean value indicating whether the generated table of contents should be ordered or unordered.
contentSelectorstring'#content'YesThe selector of the element containing the content to generate the table of contents from.
s

License

This project is licensed under the MIT License.

FAQs

Package last updated on 10 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc