github_document table of contents links not working for sections that begin with numbers

When I use "# 10 Section" as a section heading in a github_document with "toc: true", the href in the table of contents link is "#section", and the href in the anchor is "#10-section", so the link from the table of contents doesn't work. Is there a way I can get table of contents links to work with sections that begin with numbers?

I believe this is currently a limitation from Pandoc which is doing the conversion.
Identifier can't start with a number
From : Pandoc - Pandoc User’s Guide

  • Remove everything up to the first letter (identifiers may not begin with a number or punctuation mark).

Even for github specific extension (gfm_auto_identifier) this happens.

This would be a feature request to Pandoc that it supports for GFM keeping the starting number.
It could also be considered as a bug in Pandoc maybe because the toc produced in markdown won't work for Github.

Oh in fact it make me dig into how it works and looking at https://groups.google.com/g/pandoc-discuss/c/c3LEmJEQCkk/m/5Oq6r2_SBwAJ

It seems it is something that should happen at the parsing phase. So if you do this, it works as expected

---
title: "Test"
output:
  github_document:
    md_extension: +gfm_auto_identifiers
    toc: true
---

# 10 Section

Sentence.

I think we need to fix this in github_document()

Thanks a lot for the report!

I opened an issue to track

Christophe,

Thank you very much for the fix and for opening the issue. The RStudio Community is such a wonderful resource!

Bill

1 Like

Christophe,

Thanks you very much for fixing the bug so quickly. I've installed the development version of rmarkdown, and it works perfectly.

Bill

1 Like

Thanks to you for reporting this issue !
Without your question we would not have known this was an issue. You help us improve the package and I learn from looking into your question !

Thank you very much !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.