markdown-toc icon indicating copy to clipboard operation
markdown-toc copied to clipboard

Table of content an ordered list

Open zainimran opened this issue 7 years ago • 8 comments

zainimran avatar May 21 '18 12:05 zainimran

Request for an option for generating toc markdown in the form of an ordered list.

zainimran avatar May 21 '18 12:05 zainimran

Hi @zainimran

Have you tried the bullets options? You can try setting that to '1.'.

doowb avatar May 21 '18 13:05 doowb

@doowb how would you increment the order number?

zainimran avatar May 21 '18 13:05 zainimran

Markdown will do that automatically if all of the numbers are 1..

Edit: technically... a markdown renderer will create an ordered html list which will add the numbers.

doowb avatar May 21 '18 13:05 doowb

Can you show me an example? I am trying to get an ordered table of content rendered for a project

zainimran avatar May 22 '18 07:05 zainimran

Examples generating the TOC for a "README.md" file

CLI

$ markdown-toc README.md --bullets "1."

API

const toc = require('markdown-toc');
toc('# One\n\n## One A\n\n## One B\n\n# Two\n\n## Two A\n\n## Two B', { bullets: '1.' }).content;
// Results in:
// 1. [One](#one)
//   1. [One A](#one-a)
//   1. [One B](#one-b)
// 1. [Two](#two)
//   1. [Two A](#two-a)
//   1. [Tow B](#two-b)

doowb avatar May 22 '18 21:05 doowb

Oh but I was looking for something like this: wikipedia-toc

zainimran avatar May 23 '18 06:05 zainimran

@zainimran I think to get those results you'll have to set the option nobullet: true so one isn't rendered, then use a custom linkify option. This comment has an example. The tok has additional properties to help know what level and index you're looking at to create the correct numbers.

If I find the time, I'll try to get an example working.

doowb avatar May 23 '18 15:05 doowb