Markdown to create pages and table of contents?

后端 未结 30 2412
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 08:49

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

相关标签:
30条回答
  • 2020-12-12 09:38

    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
    
    0 讨论(0)
  • 2020-12-12 09:40

    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
    
    0 讨论(0)
  • 2020-12-12 09:41

    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

    0 讨论(0)
  • 2020-12-12 09:42

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


    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.

    0 讨论(0)
  • 2020-12-12 09:42

    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

    0 讨论(0)
  • 2020-12-12 09:42

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

    0 讨论(0)
提交回复
热议问题