Markdown to create pages and table of contents?

后端 未结 30 2414
爱一瞬间的悲伤
爱一瞬间的悲伤 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:21

    You can generate it using this bash one-liner. Assumes your markdown file is called FILE.md.

    echo "## Contents" ; echo ; 
    cat FILE.md | grep '^## ' | grep -v Contents | sed 's/^## //' | 
      while read -r title ; do 
        link=$(echo $title | tr 'A-Z ' 'a-z-') ; 
        echo "- [$title](#$link)" ; 
        done
    
    0 讨论(0)
  • 2020-12-12 09:21

    On Gitlab, markdown supports this : [[_TOC_]]

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

    I wrote a python script that parses a markdown file and outputs a table of contents as a markdown list: md-to-toc

    Unlike other scripts I've found, md-to-toc correctly supports duplicate titles. It also doesn't require an internet connection, so it works on any md file, not just those available from a public repo.

    0 讨论(0)
  • 2020-12-12 09:24
    # Table of Contents
    1. [Example](#example)
    2. [Example2](#example2)
    3. [Third Example](#third-example)
    
    ## Example [](#){name=example}
    ## Example2 [](#){name=example2}
    ## [Third Example](#){name=third-example}
    

    If you use markdown extra, don't forget you can add special attributes to links, headers, code fences, and images.
    https://michelf.ca/projects/php-markdown/extra/#spe-attr

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

    MultiMarkdown 4.7 has a {{TOC}} macro that inserts a table of contents.

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

    I just coded an extension for python-markdown, which uses its parser to retrieve headings, and outputs a TOC as Markdown-formatted unordered list with local links. The file is

    • md_toc.py (was md_toc.py)

    ... and it should be placed in markdown/extensions/ directory in the markdown installation. Then, all you have to do, is type anchor <a> tags with an id="..." attribute as a reference - so for an input text like this:

    $ cat test.md 
    Hello
    =====
    
    ## <a id="sect one"></a>SECTION ONE ##
    
    something here
    
    ### <a id='sect two'>eh</a>SECTION TWO ###
    
    something else
    
    #### SECTION THREE
    
    nothing here
    
    ### <a id="four"></a>SECTION FOUR
    
    also...
    

    ... the extension can be called like this:

    $ python -m markdown -x md_toc test.md 
    * Hello
        * [SECTION ONE](#sect one)
            * [SECTION TWO](#sect two)
                * SECTION THREE
            * [SECTION FOUR](#four)
    

    ... and then you can paste back this toc in your markdown document (or have a shortcut in your text editor, that calls the script on the currently open document, and then inserts the resulting TOC in the same document).

    Note that older versions of python-markdown don't have a __main__.py module, and as such, the command line call as above will not work for those versions.

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