Skip to content

Instantly share code, notes, and snippets.

@jonschlinkert
Created December 15, 2015 19:42
Show Gist options
  • Star 56 You must be signed in to star a gist
  • Fork 25 You must be signed in to fork a gist
  • Save jonschlinkert/ac5d8122bfaaa394f896 to your computer and use it in GitHub Desktop.
Save jonschlinkert/ac5d8122bfaaa394f896 to your computer and use it in GitHub Desktop.
Example table of contents generated by markdown-toc, correctly links repeated headings.
@sarossell
Copy link

sarossell commented Mar 20, 2018

Thanks for the example. Unfortunately, my experience with the code showed that the lower case TOC anchor links did not match up with the Initial upper case header anchors. I had to change the case of the TOC links to initial upper for it to work.

@salmankhwaja
Copy link

Also, what is the method to include the links for Headings with SPACEs. for example, "This is a heading"

@salmankhwaja
Copy link

Got it. Beautiful thing.

@LrWm3
Copy link

LrWm3 commented Nov 12, 2018

Got it. Beautiful thing.

For anyone else wondering how to include spaces in headings:

- [Example 1 Heading](###Example%201%20Heading)

### Example 1 Heading

Example of heading with space

Example 1 Heading

Example of heading with space

@pleiades-s
Copy link

- [Example 1 Heading](###Example-1-Heading)
 
### Example 1 Heading

Using '-' for blanks works for me.

Example 1 Heading

Using '-' for blanks works for me.

@AvgustPol
Copy link

thanks <3

@matrixtribe
Copy link

matrixtribe commented Dec 6, 2020

What about using heading numbers?

  1. Introduction
    1.1 Purpose
    1.2 Description
  2. Development toolset
    2.1 IDEs
    2.2 Continuous Integration tools
    etc...

nm, got it!!

- [1. Introduction](#1-introduction)
  * [1.1 Purpose](#11-purpose)
  * [1.2 Scope](#12-scope)
  * [1.3 Acronyms](#13-acronyms)
  * [1.4 References](#14-references)
    + [1.4.1 Internal References](#141-internal-references)
    + [1.4.2 External References](#142-external-references)
  * [1.5 Overview](#15-overview)

@Aybak3k
Copy link

Aybak3k commented Apr 24, 2021

THX A LOT!!!!

@Badboy1307
Copy link

Thanks a ton.

@VictoriaChoy
Copy link

TKS!

@ian-l-kennedy
Copy link

ian-l-kennedy commented Feb 3, 2023

Hello,
Is there a way to add a link to get back to the TOC?

I often use Typora to edit my markdown. Occasionally I export the doc I am working on to a PDF. This is a convenient tool because the PDF supports all the linking throughout the doc. So, the TOC provides a great way to jump to content.

What if I wanted a link back to the TOC underneath some headings? Lets say I have a 50 page PDF that I generated from markdown, it would be awfully convenient if a user of the PDF could jump to content on page 45, then jump back to the TOC with only 2 clicks, and no scrolling.

It is as if I want this markdown to automagically work:

[link to TOC](this.TOC)

or

[link to TOC](#TOC#)

@ian-l-kennedy
Copy link

I guess I could just link to a heading very close to the TOC, or add a heading to the TOC and link to that :/ so, one click at the TOC to get to content, then a link somewhere to the heading ### Table of contents which just so happens to be above the TOC. dumb question maybe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment