jonschlinkert / markdown-toc

API and CLI for generating a markdown TOC (table of contents) for a README or any markdown files. Uses Remarkable to parse markdown. Used by NASA/openmct, Prisma, Joi, Mocha, Sass, Prettier, Orbit DB, FormatJS, Raneto, hapijs/code, webpack-flow, docusaurus, release-it, ts-loader, json-server, reactfire, bunyan, husky, react-easy-state, react-snap, chakra-ui, carbon, alfresco, repolinter, Assemble, Verb, and thousands of other projects.
https://github.com/jonschlinkert
MIT License
1.64k stars 706 forks source link

Table of content an ordered list #122

Open zainimran opened 6 years ago

zainimran commented 6 years ago

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

doowb commented 6 years ago

Hi @zainimran

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

zainimran commented 6 years ago

@doowb how would you increment the order number?

doowb commented 6 years ago

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.

zainimran commented 6 years ago

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

doowb commented 6 years ago

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)
zainimran commented 6 years ago

Oh but I was looking for something like this:

wikipedia-toc
doowb commented 6 years ago

@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.