Markdown to create pages and table of contents?

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

    You can give this a try.

    # Table of Contents
    1. [Example](#example)
    2. [Example2](#example2)
    3. [Third Example](#third-example)
    4. [Fourth Example](#fourth-examplehttpwwwfourthexamplecom)
    
    
    ## Example
    ## Example2
    ## Third Example
    ## [Fourth Example](http://www.fourthexample.com) 
    
    0 讨论(0)
  • 2020-12-12 09:34

    For me, the solution proposed by @Tum works like a charm for a table of contents with 2 levels. However, for the 3rd level it didn't work. It didn't display the link as for the first 2 levels, it displays the plain text 3.5.1. [bla bla bla](#blablabla) <br> instead.

    My solution is an addition to the solution of @Tum (which is very simple) for people who need a table of contents with 3 levels or more.

    On the second level, a simple tab will do the indent correctly for you. But it doesn't support 2 tabs. Instead, you have to use one tab and add as many &nbsp; as needed yourself in order to align the 3rd level correctly.

    Here's an example using 4 levels (higher the levels, awful it becomes):

    # Table of Contents
    1. [Title](#title) <br>
        1.1. [sub-title](#sub_title) <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.1.1. [sub-sub-title](#sub_sub_title)
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.1.1.1. [sub-sub-sub-title](#sub_sub_sub_title)
    
    # Title <a name="title"></a>
    Heading 1
    
    ## Sub-Title <a name="sub_title"></a>
    Heading 2
    
    ### Sub-Sub-Title <a name="sub_sub_title"></a>
    Heading 3
    
    #### Sub-Sub-Sub-Title <a name="sub_sub_sub_title"></a>
    Heading 4
    

    This gives the following result where every element of the table of contents is a link to its corresponding section. Note also the <br> in order to add a new line instead of being on the same line.

    Table of Contents

    1. Title
      1.1. Sub-Title
             1.1.1. Sub-Sub-Title
                       1.1.1.1. Sub-Sub-Sub-Title

    Title

    Heading 1

    Sub-Title

    Heading 2

    Sub-Sub-Title

    Heading 3

    Sub-Sub-Sub-Title

    Heading 4

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

    MultiMarkdown Composer does seem to generate a table of contents to assist while editing.

    There might also be the one or the other library, who can generate TOCs: see Python Markdown TOC Extension.

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

    In Visual Studio Code (VSCode) you can use the extension Markdown All in One.

    Once installed, follow the steps below:

    1. Press CTRL+SHIFT+P
    2. Select Markdown: Create Table of Contents

    EDIT: nowadays I use DocToc to generate the table of contents, see my other answer for details.

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

    There are 2 way to create your TOC (summary) in your markdown document.

    1. Manually

    # My Table of content
    - [Section 1](#id-section1)
    - [Section 2](#id-section2)
    
    <div id='id-section1'/>
    ## Section 1
    <div id='id-section2'/>
    ## Section 2
    

    2. Programmatically

    You can use for example a script that generate summary for you, take a look to my project on github - summarizeMD -

    I've tried also other script/npm module (for example doctoc) but no one reproduce a TOC with working anchors.

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

    Depending on your workflow, you might want to look at strapdown

    That's a fork of the original one (http://strapdownjs.com) that adds the generation of the table of content.

    There's an apache config file on the repo (might not be properly updated yet) to wrap plain markdown on the fly, if you prefer not writing in html files.

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