### Bug description

Hello quarto team,

I have an problem when I try to make a header from r code. My objective is to generate a header from a for loop and that this header is available from the table of contents. But, when I tried to use htmltools or knit_print.html I cannot make that the header appear in the TOC.
Please if anyone knows a way it will be awsome.

Thanks in advance,

Quarto code below:

```
---
title: "Untitled"
format: html
editor: visual
toc: true
toc-depth: 10
params:
  a: ~disease + sex
---

## Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

```{r}
1 + 1
```

You can add options to executable code like this

```{r}
#| echo: false
2 * 2
```

The `echo: false` option disables the printing of code (only output is displayed).

```{r}
params
```

```{r}
library(tidyverse)
library(plotly)
library(htmltools)

knit_print.html("<h2 class=`anchored` data-anchored-id=`HI`>HI</h2>")

htmltools::h3("HI")

plotlist<-list()
for (i in colnames(iris)) {
    
  
    a<-as_tibble(iris) %>%
      ggplot(aes(i,Sepal.Length))+
      geom_point()
    
    b<-as_tibble(iris) %>%
      ggplot(aes(i,Sepal.Length))+
      geom_line()
    plotlist[[i]]<-list(h3("Hi"),ggplotly(a),ggplotly(b))
    
  
}

htmltools::tagList(plotlist)



for (i in 1:3) {
  nam <- paste0("a_",i)
  assign(nam,list(c(1,2,3)))
  
  
}

print(params$a)
```

### A

#### B

##### C

###### D
```

RStudio version:

platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          2.1                         
year           2022                        
month          06                          
day            23                          
svn rev        82513                       
language       R                           
version.string R version 4.2.1 (2022-06-23)
nickname       Funny-Looking Kid  

Operating system:
Linux, Ubuntu 20.04 within a VMWare virtual machine.


### Checklist

- [X] 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.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [X] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
2022-12-02T02:19:01Z
pipaber
bug
closed
Header generated from htmltools don`t appear in the table of contents.
https://github.com/quarto-dev/quarto-cli/issues/3548