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

后端 未结 9 612
孤城傲影
孤城傲影 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:24

    Currently it's not possible to do that using markdown syntax (.md). There is ongoing unofficial discussion about automatically generating table of contents TOC on rendered markdown files like README.md which lists some of the ideas.

    However there are some other workarounds such as:

    • Use AsciiDoc instead as per suggestion from this comment. For example:

      :toc: macro
      :toc-title:
      :toclevels: 99
      # Title
      
      toc::[]
      
      ## A
      
      ### A2
      
      ## B
      
      ### B2
      

      Check the example at littlebits/react-popover (README.adoc).

    • Online Table Of Content Generator (raychenon/play-table-of-contents)

    • arthurhammer/github-toc - browser extension that adds a table of contents to GitHub repos
    0 讨论(0)
  • 2021-01-30 02:27

    It is nicely demonstrated in the Table of Contents of the Markdown Cheatsheet.

    ##### Table of Contents  
    [Headers](#headers)  
    [Emphasis](#emphasis)  
    ...snip...    
    <a name="headers"/>
    ## Headers
    

    If you hover over a Header in a GitHub Markdown file, you'll see a little link simple to the left of it, you can also use that link. The format for that link is <project URL#<header name>. The <header name> must be all lower case.

    0 讨论(0)
  • 2021-01-30 02:28

    If you are not in the position to stick with Markdown, you can do as below:

    • on GitHub/wiki: switch Markdown to MediaWiki. Use __TOC__ Syntax. See sample.
    • on GitHub/repo: switch Markdown to AsciiDoc. Use :toc: Syntax. See demo.

    However, using Markdown files in GitHub/repo, you can get it on GitHub Pages like in Wikipedia

    • when Jekyll is activated, it generates GitHub Pages using Kramdown by default
    • Kramdown comes with Table Of Content. Use {:toc} Syntax. See the explanation.
    0 讨论(0)
  • 2021-01-30 02:28

    You can choose the Edit mode "MediaWiki" which will generate a toc for the headers, e.g.

    == First ==
    
    == Second ==
    
    0 讨论(0)
  • 2021-01-30 02:32

    Since github cannot use TOC directly, but we have other alternatives.

    You can automatically generate TOC via Online tool:

    Generate TOC Table of Contents from GitHub Markdown or Wiki Online

    or via Local tool:

    github-markdown-toc

    0 讨论(0)
  • 2021-01-30 02:39

    One possible (semi-automated) solution is Eugene Kalinin's github-markdown-toc. This tool essentially crunches through your README.md file and snarfs out #'s headings to create a TOC.

    1. Download the script https://github.com/ekalinin/github-markdown-toc
    2. Feed your README.md to the script (as noted in Eugene's README.md)

      cat README.md | bash github-markdown-toc

    3. Cut and paste generated TOC and place it at the top of your README.md file

    Note that this bash implementation only works on Linux (from what I can tell).

    As a side note, there is a golang implementation and is probably more of a hassle to get working.

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