Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

7 answers

1 accepted

5 votes
Answer accepted

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.

Like # people like this

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.

It works! Thank you so much!

This is a Bitbucket server question, and [TOC] does not work on Bitbucket server.

The accepted answer basically just shows how to do this with manually-written html anchors and references/links. I'm looking for a way to have this TOC generated from existing headers.

A search for "table of contents" for Bitbucket Server produces zero hits:

https://confluence.atlassian.com/search/?productName=Bitbucket&productVersion=6.2&queryString=%22table%20of%20contents%22

Anyone know how to autogenerate TOC in Bitbucket Server? We're on 6.2.

Looks like it can be done with external software, like this, or this. But I would really like for this to be done in Bitbucket without having to add any of my own "glue"..

Like # people like this

Atlassian,

Please add [TOC] (and other extensions?) to Bitbucket Server.

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 seems to be related to the quite old version of CommonMark (which Bitbucket README markdown is based on) bundled into Bitbucket server.

[user@server app]$ find . -name "*.jar" | grep common 
./WEB-INF/atlassian-bundled-plugins/atlassian-remote-event-common-plugin-6.2.2.jar
./WEB-INF/atlassian-bundled-plugins/bitbucket-ao-common-7.9.0.jar
./WEB-INF/lib/atlassian-cache-common-impl-5.3.3.jar
./WEB-INF/lib/commonmark-0.15.2.jar
./WEB-INF/lib/commons-beanutils-1.9.4.jar
./WEB-INF/lib/commons-codec-1.14.jar
./WEB-INF/lib/commons-compiler-2.7.8.jar
./WEB-INF/lib/commons-compress-1.19.jar
./WEB-INF/lib/atlassian-extras-common-3.4.1.jar
./WEB-INF/lib/commons-digester-1.8.1.jar
./WEB-INF/lib/commons-fileupload-1.3.3.jar
./WEB-INF/lib/commons-io-2.6.jar
./WEB-INF/lib/commons-lang-2.6.jar
./WEB-INF/lib/commons-lang3-3.8.1.jar
./WEB-INF/lib/commons-pool-1.6.jar
./WEB-INF/lib/commons-validator-1.4.1.jar
./WEB-INF/lib/atlassian-plugins-webresource-common-5.4.0-01c481fbd.jar
./WEB-INF/lib/bitbucket-git-common-7.9.0.jar
./WEB-INF/lib/bitbucket-scm-common-7.9.0.jar
./WEB-INF/lib/bitbucket-web-common-7.9.0.jar
./WEB-INF/lib/commonmark-ext-autolink-0.15.2.jar
./WEB-INF/lib/commonmark-ext-gfm-strikethrough-0.15.2.jar
./WEB-INF/lib/commonmark-ext-gfm-tables-0.15.2.jar
./WEB-INF/lib/commonmark-ext-heading-anchor-0.15.2.jar
./WEB-INF/lib/commonmark-ext-image-attributes-0.15.2.jar
./WEB-INF/lib/commons-collections-3.2.2.jar
./WEB-INF/lib/crowd-common-4.1.6.jar
./WEB-INF/lib/crowd-integration-client-common-4.1.6.jar
./WEB-INF/lib/crowd-rest-common-4.1.6.jar
./WEB-INF/lib/crowd-server-common-4.1.6.jar
./WEB-INF/lib/hibernate-commons-annotations-5.1.2.Final.jar
./WEB-INF/lib/istack-commons-runtime-3.0.7.jar
./WEB-INF/lib/netty-common-4.1.53.Final.jar
./WEB-INF/lib/netty-transport-native-unix-common-4.1.53.Final.jar
./WEB-INF/lib/proto-google-common-protos-1.17.0.jar
./WEB-INF/osgi-framework-bundles/commons-lang-2.6.jar
./WEB-INF/osgi-framework-bundles/commons-pool-1.6.jar
./WEB-INF/savant/commons-text-1.8.jar



The bundled version (0.15.2) is from 2014, it could do with an update.
See also: https://jira.atlassian.com/browse/BSERV-11795
  

It's not possible with BB Server out of the box. Please vote for one or bothfboth othe related feature requests:

https://jira.atlassian.com/browse/BSERV-12289

https://jira.atlassian.com/browse/BSERV-10895

Try to use it like this:
1. [Description.](#markdown-header-desc)

0 votes

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,735 views 10 16
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you