Markdown internal links do not work in BitBucket README.md

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

## Table of Contents * [Document Organization](#document-organization) ... ## Document Organization 

When I open the preview of the markings in the browser using Sublime Text, the links in the table of contents go to the appropriate sections, but when I upload the file to BitBucket, the URL seems to be correct, but it does not go to the section.

The BitBucket repository is private, so I cannot use it.

How can i fix this?

+6
source share
3 answers

I would check the generated html on the anchor tag, from the fact that I can remember the bits that I suspect your link should look more like

 * [Document Organization](#markdown-header-document-organization) 
+16
source

Here's a snippet for creating a table of contents for reading on Bitbucket (or other markup 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 { }' 
+2
source

It can also do.

According to this: https://confluence.atlassian.com/bitbucket/mark-up-comments-305037452.html , bitbucket supports a table of contents extension that can automatically generate links and anchors based on document headers.

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

Add the text [TOC] at the top of the document to create it.

0
source

Source: https://habr.com/ru/post/955933/


All Articles