🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

toc-generate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toc-generate

Generate a table of contents

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
8
-27.27%
Maintainers
1
Weekly downloads
 
Created
Source

TOC Generate

| Create a table of contents for a HTML, ESModule

https://nodei.co/npm/toc-generate.png?downloads=true&downloadRank=true&stars=true

Demo

Demo Link

Usage

Script HTML

  • Include one of the link in to HTML
<script src="https://dunggramer.github.io/toc-generate/dist/toc-generate.js" defer></script>
<script src="https://gitcdn.xyz/cdn/DungGramer/toc-generate/master/dist/toc-generate.js" defer></script>
  • Call the function
 <script>
    document.addEventListener('DOMContentLoaded', function() {
        const tableOfContent = tocGenerate({
            contentWrapperSelector: "main",
            headingLevelFrom: 2,
            viewablePercentToHighlight: 70,
            showsHighLight: true,
            showsParentHighlight: true,
        });

        const tocSelector = document.querySelector("#toc");
        tocSelector.appendChild(tableOfContent);
    });
</script>

ESModule

npm i toc-generate
# or 
yarn add toc-generate

You may not use tocSelector if the content is not already displayed.

import tocGenerate from 'toc-generate';

const tableOfContent = tocGenerate({
    contentWrapperSelector: "main",
    headingLevelFrom: 2,
    viewablePercentToHighlight: 70,
    showsHighLight: true,
    showsParentHighlight: true,
});

const tocSelector = document.querySelector("#toc");
tocSelector.appendChild(tableOfContent);

API

ParameterTypeDefaultDescription
contentWrapperSelectorstring'body'The selector for the content wrapper
tocSelectorstringundefinedThe selector for the TOC
headingLevelFromnumber2The heading level to start from
headingLevelTonumber6The heading level to stop at
showsHighLightbooleanfalseWhether to show the highlight
showsParentHighlightbooleanfalseWhether to keep the parent highlight, only works when showsHighLight is true
viewablePercentToHighlightnumber70The viewable percent to highlight

Keywords

toc

FAQs

Package last updated on 07 May 2022

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