How to write a table of contents in a Readme.md?

Hi,

I'm trying to add a table of contents into a Readme.md for one of my repositories but I can't find a way to do it.

I tried to use the same syntax as GitHub, something similar to:

# Table of Contents

1. [My first title](#my-first-title)
2. [My second title](#my-second-title)
## My first title
Some text.
## My second title

But it doesn't work. Nothing happens when I click on the links generated into the ToC.

I'm running Bitbucket server 5.4. Is it possible to do such a thing please? I didn't find anything relevant into the Atlassian documentation.

Thanks for your help.

Guillaume.

4 answers

1 accepted

This widget could not be displayed.

For bitbucket server:

1. [ Description. ](#desc)
2. [ Usage tips. ](#usage)

<a name="desc"></a>
## 1. Description

sometext

<a name="usage"></a>
## 2. Usage tips

sometext

It works! Thank you very much!

Obviously works because, as you said, you are hosting your own bitbucket server.

Others, reading this post and using bitbucket.org: Markdown on bitbucket.org does not allow HTML tags (for security reasons). github.com and other Markdown environments do, so in a common Markdown editor on your PC it should work, but you cannot publish that on bitbucket.org.

This widget could not be displayed.
Gonchik Tsymzhitov Community Champion Nov 19, 2017

Hi Guillaume, 

Have you tried this tutorial for README.md? 

https://bitbucket.org/tutorials/markdowndemo/overview#markdown-header-tables

 

 

Hope it helps.

 

Cheers,

Gonchik Tsymzhitov

Hi Gonchik,

Thank you for your help, but it doesn't answered my question. I'm not trying to create a table (I have no problems for this), but a table of contents.

Like:

Sélection_041.png

In other words: a list of links to the titles inside the README.

Guillaume.

This widget could not be displayed.

You need to add "markdown-header-" to your link parentheses.



1. [My First Title](#markdown-header-my-first-title)

2. [My Second Title](#markdown-header-my-second-title)

 

This worked for me.

This didn't work for me I tried with and without `markdown-header-`

Same for me... does not work...

same here, doesn't work...

Unfortunately you depend on the editor you are using. The built-in one on bitbucket.org creates for a "##My First Title" headline an anchor "markdown-header-my-first-title", other editors may create an anchor "my_first_title", "My_First_Title_0", etc. - and some might produce no anchor at all. The reason is that this is no part of Markdown, but just a "service" from some editors.

This widget could not be displayed.

On bitbucket.org, just write "[TOC]", see https://confluence.atlassian.com/bitbucket/add-a-table-of-contents-to-a-wiki-221451163.html

For other editors see their references. Retext, e.g., and maybe any Python based Markdown editor, allow to define "extensions", one of which is "markdown.extensions.toc" which provides the "[TOC]" functionality.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,319 views 8 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you