Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown internal links not working in BitBucket README.md

I have a README.md file in a BitBucket project that goes something like

## Table of Contents

* [Document Organization](#document-organization)

...

## Document Organization

When I open up the markdown preview in the browser with Sublime Text the links in the Table of Contents jump to the appropriate sections, but when I upload the file to BitBucket, the URL seems correct but it does not jump to the section.

How can I fix this?

like image 396
JuJoDi Avatar asked Oct 14 '13 20:10

JuJoDi


People also ask

Does bitbucket support readme MD?

Bitbucket can parse and display Markdown, reStructuredText, Textile, and plain text README files.

Does bitbucket use markdown?

Bitbucket Data Center and Server uses Markdown for formatting text, as specified in CommonMark (with a few extensions).

Does bitbucket markdown support HTML?

It seems that Bitbucket Markdown does not support html-entities like  , and literally displays it as  , not as non-breaking space.

How do you add an external link in readme MD?

External Links To link inline, type the text you want to link within brackets, "[x]", followed directly by the link URL parentheses, "(y)".


3 Answers

I'd check the generated html on the anchor tag, from what I can recall of bitbuckets auto-ids I suspect your link needs to look more like

* [Document Organization](#markdown-header-document-organization)
like image 146
Oliver Matthews Avatar answered Oct 20 '22 10:10

Oliver Matthews


Here's a snippet to generate a Table of Contents for Bitbucket readmes (or other markdown files).

cat readme.md  |\
grep "^#" |\
sed 's|^[ ]*||g' |\
awk  -F, '\
BEGIN {
}{
  basic_name=$1;
  anchor=basic_name
  basic_name_no_hash=basic_name
  gsub(/^[#]* /,"",basic_name_no_hash)
  gsub(/[ ]*$/,"",basic_name_no_hash)
  subs_string=basic_name
  subs = gsub(/#/,"",subs_string);
  gsub(/^[#]+ /,"",anchor);
  gsub(/ /,"-",anchor);
  anchor = tolower(anchor);
  {for (i=0;i<subs-1;i++) printf "    " }
  print "* [" basic_name_no_hash "](#markdown-header-" anchor ")";
}
END {
}'
like image 2
Ryan Avatar answered Oct 20 '22 08:10

Ryan


This may do as well.

According to this: https://confluence.atlassian.com/bitbucket/mark-up-comments-305037452.html, bitbucket supports the Table of Contents extension which can auto-generate links and anchors based on the document headers.

The TOC extension is documented here: https://pythonhosted.org/Markdown/extensions/toc.html

Add the text "[TOC]" to the beginning of the document for it to be generated.

like image 2
Binary Phile Avatar answered Oct 20 '22 08:10

Binary Phile