I disagree with this feature request as it stands.
Firstly, a "[TOC]" does not exist in any variety of markdown (to my knowledge). Adding one to a markdown file is, well, making it no longer be markdown.
Second, asking Atlassian to start developing yet another variation on markdown with such a tag is a Bad Idea (tm).
Third, I typically add my own TOC to my markdown files and don't want to leave it up to Atlassian to do this for me - I'm sure we'll all start to disagree about the format. Plus, if they add their own, and I've already added one, well, that's just not right!
Do it yourself! Here is an example of adding to TOC to a markdown file using pandoc.
pandoc -s --toc -f markdown -t markdown my.md > my+toc.md
Similarly, pandoc can convert markdown to html with a TOC as follows:
pandoc -s --toc -f markdown -t html my.md > my+toc.html
Further, pandoc strives to implement a convention whereby a YAML frontmatter appearing in the markdown file can control TOC creation and control various aspects of the TOC (color, number of levels). It is a little incomplete [in my opinion|https://github.com/jgm/pandoc/issues/5784], but I expect it will get sorted soon. At which point, if Atlassian simply adopts pandoc as their markdown-to-html renderer, then Bitbucket users could simply opt-in to getting free TOC generation by putting a few lines at the top of their README.md files.
I do agreed that Bitbucket support for Markdown rendering as html in general is lacking. Atlassian should start by fixing this instead:
- support id in addition to name as target anchor of internal markdown link
(edits: clarity)
I'm sharing my custom workaround, which is consists of an GNU Awk script and Make target, with pandoc as an added dependency:
file: etc/add-url-to-section.awk
```
```
This is the makefile target:
```
README.md: README.md.in
pandoc -s --from=markdown --to=markdown_strict --toc --output="$@" "$<" \
&& gawk -i inplace -f etc/add-url-to-section.awk "$@" \
&& sed '1i //: # (GENERATED FILE: EDIT README.md.in INSTEAD)\n' -i "$@" \
|| rm "$@"
```
To use: `make README.md`; where the original README source is at `README.md.in`.
I hope this helps!