Skip to content

github_document() should set +gfm_auto_identifiers to the input for TOC to work correctly #2039

@cderv

Description

@cderv

This is from an investigation following a question on Community
https://community.rstudio.com/t/github-document-table-of-contents-links-not-working-for-sections-that-begin-with-numbers/95539/3

At first I thought it was an issue with Pandoc not supporting the correct algorithm even for GFM, but in fact I misunderstood how the auto identifier feature works.

From this anwser on Pandoc dicussion, it seems that the auto identifier creation happens at read time, not write time. This seems counter intuitive but I put theses files togther in this gist: https://gist.github.com/cderv/589912cb000347cf6d22e91adfa852bc

As you see, not providing markdown+gfm_auto_identifiers will not produce the correct identifiers to work in the TOC for Pandoc autolink feature.

This means this works

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

# 1 Section

Sentence.

and this will produce a non working TOC

---
title: "Test"
output:
  github_document:
    toc: true
---

# 1 Section

Sentence.

I think we should set the extension in rmarkdown if toc = TRUE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions