Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a table of content in GitLab wiki?

I am a big fan of the __TOC__ that creates a table of content on a Wikimedia page.

Whenever you write things like this on a Wikimedia page:

This is a page for my project

## Credits ##

bla bla

## License ##

bla bla

__TOC_ automagically creates a table of content that allows you to navigate through inner links of the page.

I noticed that this is somehow possible in GitHub wiki pages: How do I create some kind of table of content in GitHub wiki? by using different tricks.

However, I miss this feature in GitLab wiki pages. Does it provide such functionality?

like image 892
fedorqui 'SO stop harming' Avatar asked Nov 07 '17 09:11

fedorqui 'SO stop harming'


People also ask

What is TOC in markdown?

Generate TOC (table of contents) of headlines from parsed markdown file.

What is markdown in GitLab?

GitLab Flavored Markdown automatically renders Markdown content in an easy-to-read and easy-to-write plain text language. Although Markdown is inherently more “human-readable” and versatile when writing rich web content, Markdown files can become tricky to work with as they become more verbose and complex.

Where are GitLab wiki files stored?

Where files are stored. Attach a file, and GitLab stores it according to your installed version of GitLab: Files added in GitLab 11.3 and later: Files are stored in the wiki's Git repository. Files added GitLab 11.2 and earlier: Files are stored in GitLab itself.


3 Answers

So this exists! I finally found a Merge Request in in the GitLab Community Edition: Replace Gollum [[_TOC_]] tag with result of TableOfContentsFilter

As its name describes, to have a table of contents you need to write the following:

[[_TOC_]]

All together, you can write something like:

This is a page for my project

[[_TOC_]]

## Credits

bla bla

## License

bla bla

and will show like this:

enter image description here

This is available from the GitLab 8.6 release as described in its milestone.

like image 134
fedorqui 'SO stop harming' Avatar answered Oct 13 '22 10:10

fedorqui 'SO stop harming'


Should be something like this

 ##### Table of Contents  
[1.-First Topic](#first-topic)
[2.-Second Topic](#second-topic) 
[3.-Third Topic](#third_topic)

And then you will reference each on the same page by using

 <a name="first-topic"/>
 <a name="second-topic"/>
 <a name="third-topic"/>
like image 28
mario rodriguez Avatar answered Oct 13 '22 10:10

mario rodriguez


This should be easier with GitLab 15.3 (August 2022):

Visualize table of contents in the WYSIWYG wiki editor

When you’re editing a wiki page in the rich text WYSIWYG editor, you expect to see an accurate representation of the content as it will appear after it’s published.
Some elements are too complex for plain text formatting, and require short codes or macros that generate content when the page is built.

A wiki’s table of contents is one example: it generates a list from your page’s subheadings, simplifying navigation of very long pages.
However, WYSIWYG page editing displayed a table of contents as a static placeholder block.

GitLab 15.3 shows a visual representation of the Table of Contents in the WYSIWYG wiki editor.

To add a table of contents while editing a page, select the plus (+) icon in the toolbar, then select Table of Contents.
The table of contents updates in real time as you create and edit subheadings on the page, helping you monitor the outline of your longer wiki pages.

See Documentation and Issue.

like image 44
VonC Avatar answered Oct 13 '22 10:10

VonC