Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-10895

Bitbucket should support [TOC] for auto table of content generation in markdown

    • 10
    • We collect Bitbucket feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      [TOC] has been around for a while now and it’s super useful to automagically generate table of contents for a document based on header information which markdown already has. Would be great to support [TOC] in Bitbucket

          Form Name

            [BSERV-10895] Bitbucket should support [TOC] for auto table of content generation in markdown

            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

            ```

            1. This is a GNU Awk script useful to workaround
            2. https://jira.atlassian.com/browse/BSERV-11959, by post-processing a
            3. pandoc-generated markdown document.
            1. Match any line starting with a pound sign, and append an HTML
            2. link whose name is derived from the title.
            {     if ($0 ~ /^#/)         print($0, "<a name=\"" \               tolower(gensub(/ /, "-", "g", gensub(/(^#+ ?| $)/, "", "g", $0))) \               "\"></a>")     else         print $0                # preserve other, non-matching lines }

            ```

            This is the makefile target:
            ```

            1. This generated README.md is intended to be rendered by Bitbucket.
              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!

            maxim.cournoyer added a comment - 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 a GNU Awk script useful to workaround https://jira.atlassian.com/browse/BSERV-11959 , by post-processing a pandoc-generated markdown document. Match any line starting with a pound sign, and append an HTML link whose name is derived from the title. {     if ($0 ~ /^#/)         print($0, "<a name=\"" \               tolower(gensub(/ /, "-", "g", gensub(/(^#+ ?| $)/, "", "g", $0))) \               "\"></a>")     else         print $0                # preserve other, non-matching lines } ``` This is the makefile target: ``` This generated README.md is intended to be rendered by Bitbucket. 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!

            David Puchosic added a comment - Yep  https://jira.atlassian.com/browse/BSERV-11959

            Kalle Niemitalo added a comment - - edited

            deleted

            Kalle Niemitalo added a comment - - edited deleted

            - support id in addition to name as target anchor of internal markdown link

            Has such a request been filed? I would vote for it for sure.
             

            Kalle Niemitalo added a comment - - support id in addition to name as target anchor of internal markdown link Has such a request been filed? I would vote for it for sure.  

            Malcolm Cook added a comment - - edited

            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)

            Malcolm Cook added a comment - - edited 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 would prefer having Bitbucket Server generate a table of contents outside the document itself. That way, we would benefit from it without adding any nonstandard [TOC] markup to our Markdown files.

            Kalle Niemitalo added a comment - I would prefer having Bitbucket Server generate a table of contents outside the document itself. That way, we would benefit from it without adding any nonstandard [TOC] markup to our Markdown files.

              Unassigned Unassigned
              4c762d6af390 Corey Steele
              Votes:
              28 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated: