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?
Bitbucket can parse and display Markdown, reStructuredText, Textile, and plain text README files.
Bitbucket Data Center and Server uses Markdown for formatting text, as specified in CommonMark (with a few extensions).
It seems that Bitbucket Markdown does not support html-entities like , and literally displays it as , not as non-breaking space.
External Links To link inline, type the text you want to link within brackets, "[x]", followed directly by the link URL parentheses, "(y)".
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)
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 {
}'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With