A vanilla JavaScript library that automatically generates the "Table of Contents" of an HTML document.

Overview

GitHub license GitHub release Language

DocumentOutline.js

DocumentOutline is a vanilla JavaScript library that automatically generates the "Table of Contents" of an HTML document.

See a live example here.



How To Use

Import needed files:

<html>
  <head>
    <!-- Import CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/AngeloFaella/[email protected]/outline.css">
  </head>
  <body>
    <!-- Wrap your main content in a div -->
    <div>
        <!-- Use heading tags to structure your document -->
        <h1> 1 - Title</h1>
        <h2> 1.1 - Subtitle</h2>
        <h3> 1.2 - Subtitle</h3>
        ...
        <h1> 2 - Title</h1>
        <h2> 2.1 - Subtitle</h2>
        <h3> 2.2 - Subtitle</h3>
        ...
    </div>  
    <!-- Import the library -->    
    <script src="https://cdn.jsdelivr.net/gh/AngeloFaella/[email protected]/DocumentOutline.js"></script>
  </body>
</html>

Then initialize the outline:

let outline = new DocumentOutline();

Or initialize with custom options:

let outline = new DocumentOutline({
	 backgroundColor: '#02181d',
	 textColor: 'white',
	 textColorLight: 'lightgrey',
	 accentColor: 'rgb(221 201 0)',
	 defaultOpen: false
});



Documentation


Classes

DocumentOutline

Kind: global class


Functions

new DocumentOutline(options)

Param Type Description
options Object
[options.backgroundColor] String background color of the outline
[options.textColor] String text color of the first-level sections
[options.accentColor] String accent color of the outline
[options.textColorLight] String text color of the sub sections
[options.defaultOpen] String indicate the initial mode of the outline. Outline is open by default on desktop and closed on mobile.

onSearchInput(text)

Called when a search is submitted

Kind: global function

Param Type Description
text String text to search

showOutline()

Show document outline.

On desktop the outline is placed to the left of the main content takes 20% of the width.

On mobile the outline is placed above the main content and takes 100% of the width.

Kind: global function


hideOutline()

Hide document outline.

On desktop the outline reduces its width to 3%.

On mobile the outline disappears completely and a floating button appears in the bottom-left corner.

Kind: global function

You might also like...

Random Fractals stash of Observable Data Tools 🛠️ and Notebooks 📚 in ES Modules .js, .nb.json, .ojs, .omd, .html and .qmd document formats for Data Previews

Random Fractals stash of Observable Data Tools 🛠️ and Notebooks 📚 in ES Modules .js, .nb.json, .ojs, .omd, .html and .qmd document formats for Data Previews

Random Fractals stash of Observable Data Tools 🛠️ and Notebooks 📚 in ES Modules .js, .nb.json, .ojs, .omd, .html and .qmd document formats for Data Previews in a browser and in VSCode IDE with Observable JS extension, Quarto extension, and new Quarto publishing tools.

Nov 25, 2022

This is a plugin for Obsidian (https://obsidian.md). Can open document with `.html` and `.htm` file extensions.

Obsidian HTML reader Plugin This is a plugin for Obsidian (https://obsidian.md). Can open document with .html and .htm file extensions. Obsidian HTML

Dec 27, 2022

Obsidian plugin: copy document as HTML, including images

Copy as HTML Plugin for Obsidian that copies the current document to the clipboard, so it can be pasted into HTML aware application like gmail. This p

Dec 22, 2022

curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.

curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.

What is it ? Shaders are the new front-end web developpment big thing, with the ability to create very powerful 3D interactions and animations. A lot

Jan 1, 2023

A JavaScript Library that allows you to execute function when a certain element gets added to the document

wait-for-it.js A JavaScript Library that allows you to execute function when a certain element gets added to the document Getting Started If you want

Apr 26, 2022

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Jul 19, 2022

🪢 A really tiny library that generates classname strings.

cnz (“classnamez”) The smallest classnames-compatible package yet (I think). This is an extremely simple javascript utility for conditionally joining

Dec 15, 2022

A set of javascript packages that generates fake data for you.

Faker A set of javascript packages that generates fake data for you. Install $ npm install --save @fakerjs/faker Usage import faker from '@fakerjs/fa

Apr 18, 2022

Lightweight (zero dependencies) library for enabling cross document web messaging on top of the MessageChannel API.

Lightweight (zero dependencies) library for enabling cross document web messaging on top of the MessageChannel API.

Jul 15, 2022
Comments
  • How would I use DocumentOutline in WordPress

    How would I use DocumentOutline in WordPress

    Hi, Like to use this in my wordpress site. HTML, CSS and importing the library I unserstand, but then you say:

    Then initialize the outline:

    let outline = new DocumentOutline();

    Could you explain exactly how and where I do that.

    Thanks

    opened by david-j-m 2
Releases(1.0)
Waypoint - Automatic Table of Contents Generator for Obsidian.md

Waypoint - Automatic Table of Contents Generator for Obsidian.md Do you use folders to categorize your notes and wish that Obsidian would show certain

Idrees 153 Jan 2, 2023
Table of contents Trilium widget for editable and readonly text notes.

Trilium-TocWidget Table of contents Trilium widget for editable and readonly text notes. Screenshot Features The ToC is live and automatically updated

Antonio Tejada 25 Dec 29, 2022
jQuery plugin to generate a table of contents

jquery.contentify A jQuery plugin to generate a table of contents Usage The below code snippet shows how to create the table of contents in a containe

Johannes Marbach 1 Aug 24, 2021
Add a table of contents to the sidebar of your GitHub issues and pull requests.

github-sidebar-jump-extension Getting started ?? Build locally Checkout the repository to your local machine Run npm install to install all required d

Jason Barry 11 Sep 7, 2022
Show floating sticky outline (table of contents) for Notion pages, powered by nbundle.

Notion Outline Show floating sticky outline (table of contents) for Notion pages, powered by nbundle. This is an nbundle-powered Notion app bootstrapp

nbundle 11 Nov 10, 2022
Creates a table of contents in a DOM element optionally linked to with anchors. No jQuery or other dependencies.

HTML-Contents Creates a table of contents in a DOM element optionally linked to with anchors. No dependencies. @psalmody Get It We're on npm: npm i ht

Michael Tallino 3 Oct 25, 2022
Automatically document all of your Remix loaders and actions typings per each route. 📚

About remix-docs-gen parses all of your Remix loaders and actions and automatically documents all the typings per each route. Installation First, you

Stratulat Alexandru 50 Nov 9, 2022
A JavaScript library built on top of the Faker.JS library. It generates massive amounts of fake data in the browser and node.js.

Blaver - generate massive amounts of fake data in the browser and node.js Blaver is a JavaScript library built on top of the Faker.JS library. It gene

Priyansh 113 Dec 30, 2022
Simple webpack plugin that generates VERSION and commitInfo insert index.html during build

Html commit version plugin Simple webpack plugin that generates CommitInfo and VERSION insert index.html during build. English | 简体中文 Usage Given a we

null 13 Mar 8, 2022
A jquery plugin that allows an html page to be converted and/or downloaded into a Microsoft Word Document with an emphasis on performance

googoose A jquery plugin that allows an html page to be converted and/or downloaded into a Microsoft Word Document with an emphasis on performance Abo

Aaron Adel 32 Jan 3, 2023