Skip to content

TOC ignoring subsections from child document #3178

Description

@nclJoshCowley

Bug description

Context, my current workflow is to have a QMD that analyses a model fit using only the fit object.
This is then pulled into a application specific report using knitr::knit_child.

Issue is that the table of contents (TOC) is missing subsections if the child report has n > 1 subsections.

See the TOC in the following reproducible example.

---
format: html
keep-md: true
toc: true
toc-depth: 3
number-sections: true
---

```{r setup}
#| include: false
include_child <- function(n) {
  txt <- paste(
    sprintf("### H3 (Child) - %s\nSome content\n", seq(n), seq(n)),
    collapse = "\n"
  )
    
  res <- knitr::knit_child(text = txt, quiet = TRUE)
  return(res)
}
```

## Good

Section appears in TOC.

```{r}
#| echo: false
#| results: asis
cat(include_child(n = 1))
```

## Bad

No sections appears in TOC.

```{r}
#| echo: false
#| results: asis
cat(include_child(n = 2))
```

I'm using Windows 10 and the following version of RStudio:

RStudio 2022.07.2+576 "Spotted Wakerobin" Release (e7373ef832b49b2a9b88162cfe7eac5f22c40b34, 2022-09-06) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcrossref

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions