nagaozen / markdown-it-toc-done-right

A table of contents (TOC) plugin for Markdown-it with focus on semantic and security. Made to work gracefully with markdown-it-anchor.
MIT License
133 stars 26 forks source link

Option to add toc by default at the beginning of rendered content #48

Closed Uzay-G closed 3 years ago

Uzay-G commented 3 years ago

Hi,

I was wondering if it would be possible to add an option to automatically add the table of contents at the beginning of the content. This would be nice instead of manually adding it to the beginning of everything you render.

Thanks!

nagaozen commented 3 years ago

I believe that pre-processing the markdown content with a HOC seems to be a better way to achieve this. Something like:

function inject_toc_on_top (md) {
  return ['[TOC]','',md].join('\n')
}

let markdown_content = '# Header'
markdownIt.render(inject_toc_on_top (markdown_content))

No reason to address this as an option. Developers have the freedom to decide.