I started to use markdown to take notes.
I use marked to view my markdown notes and its beautiful.
But as my notes get longer I find it diff
You could also use pandoc
, the "swiss-army knife" for converting "one markup format into another". It can automatically generate a table of content in the output document if you supply the --toc
argument.
Hint: If you want a table of contents in html
output, you also need to supply -s
which generates a standalone document.
Example shell command line:
./pandoc -s --toc input.md -o output.html
You could try this ruby script to generate the TOC from a markdown file.
#!/usr/bin/env ruby
require 'uri'
fileName = ARGV[0]
fileName = "README.md" if !fileName
File.open(fileName, 'r') do |f|
inside_code_snippet = false
f.each_line do |line|
forbidden_words = ['Table of contents', 'define', 'pragma']
inside_code_snippet = !inside_code_snippet if line.start_with?('```')
next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ } || inside_code_snippet
title = line.gsub("#", "").strip
href = URI::encode title.gsub(" ", "-").downcase
puts " " * (line.count("#")-1) + "* [#{title}](\##{href})"
end
end
If your Markdown file is to be displayed in a repo on bitbucket.org, you should add [TOC]
at the location where you want your table of contents. It will then be auto-generated. More info here:
https://confluence.atlassian.com/bitbucket/add-a-table-of-contents-to-a-wiki-221451163.html
For the Visual Studio Code users the best option to use today (2020) is the Markdown All in One plugin.
To install it, launch the VS Code Quick Open (Control/⌘+P), paste the following command, and press enter.
ext install yzhang.markdown-all-in-one
And to generate the TOC, open the command palette (Control/⌘+Shift+P) and select the Select Markdown: Create Table of Contents
option.
Another option is the Markdown TOC plugin.
To install it, launch the VS Code Quick Open (Control/⌘+P), paste the following command, and press enter.
ext install markdown-toc
And to generate the TOC, open the command palette (Control/⌘+Shift+P) and select the Markdown TOC:Insert/Update
option or use Control/⌘+MT.
For the benefit of those of us making README.md
files in Atom (how I found this thread):
apm install markdown-toc
https://atom.io/packages/markdown-toc
I just started doing the same thing (take notes in Markdown). I use Sublime Text 2 with the MarkdownPreview plugin. The built-in markdown parser supports [TOC]
.