How do I create some kind of table of content in GitHub wiki?

后端 未结 9 617
孤城傲影
孤城傲影 2021-01-30 02:05

If you look here: http://en.wikipedia.org/wiki/Stack_Overflow

You\'ll notice there\'s a little \"Content\" section, if you click on one of the links, it will send you to

9条回答
  •  野的像风
    2021-01-30 02:39

    Due to the fact that github has it's own way of generating id=".." attributes in h1, h2, h3, etc... headers in html version after processing Markdown (for example Bitbucket use little different pattern of sluggifying headers title to id="slug") it is handy to don't reinvent the wheel and use library that reverse engineered this process.

    I found one quite good library for this task called markdown-toc.

    For me it seems the best solution because I always have installed node on my machine.

    Just execute npx markdown-toc -i file.md.

    And it looks like it is one of more popular tools for this task - at least in node.js ecosystem.

    ls
    cat <> test.md | tee 
    ## Table of Contents
    
    
    - old toc 1
    - old toc 2
    - old toc 3
    
    
    ## abc
    This is a b c.
    
    ## xyz
    This is x y z.
    EOF
    ls
    cat test.md
    npx markdown-toc -i test.md
    cat test.md
    

    output:

提交回复
热议问题