Skip to content

Links in ToC to sections within chapters fail when names are not unique #909

@richarddmorey

Description

@richarddmorey

Creating two sections in different chapters with the same name appears to link all table of contents links back to the first section with that name.

Steps to reproduce:

bookdown-bug-demo.zip

  1. Download the demo here: https://bookdown.org/yihui/bookdown/get-started.html
  2. In 01-intro.Rmd add to the end:
## Visualisation

Test

  1. In 02-literature.Rmd add the same thing to the end (so the section labels are the same: "Visualization".
  2. Build using the "Build" button.
  3. Open the resulting HTML file and click on the table of contents link for the "Visualization" section of Chapter 3. Notice that it takes you to Chapter 2 instead.

What I expected: The link to the "Visualization" section in Chapter 3 should take you to Chapter 3.

Some things to note:

  • Naming the "Visualization" section in 02-literature.Rmd to "Visualization2" fixes the issue.
  • I have confirmed this also occurs with the development version 0.20.1.
  • Reverting to bookdown 0.19 fixes the issue.

[I note offhand that I found this issue when installing the development version to try to fix another issue last week. It slipped my mind reporting it because it turned out my other issue was with another package...]

> xfun::session_info('rmarkdown')
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5, RStudio 1.3.1023

Locale: en_GB.UTF-8 / en_GB.UTF-8 / en_GB.UTF-8 / C / en_GB.UTF-8 / en_GB.UTF-8

Package version:
  base64enc_0.1.3 digest_0.6.25   evaluate_0.14  
  glue_1.4.1      graphics_4.0.0  grDevices_4.0.0
  highr_0.8       htmltools_0.5.0 jsonlite_1.7.0 
  knitr_1.29      magrittr_1.5    markdown_1.1   
  methods_4.0.0   mime_0.9        rlang_0.4.6    
  rmarkdown_2.3   stats_4.0.0     stringi_1.4.6  
  stringr_1.4.0   tinytex_0.24    tools_4.0.0    
  utils_4.0.0     xfun_0.15       yaml_2.2.1     

Pandoc version: 2.9.2.1

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('bookdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/bookdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions