Open lucas-johnson opened 3 years ago
Thanks for sharing the example: I can reproduce this.
I think this is related to how distill works by modifying the knitr's hook. The toc is created by Pandoc and this is the file that is passed to Pandoc (that I obtain by setting keep_md: true
)
---
author: Lucas Johnson
date: 2021-05-06
title: "Test Loop+Md Headers+Distill TOC"
description:
output:
distill::distill_article:
toc: true
keep_md: true
---
# Section 1
Fails with > 1 iteration
<div class="layout-chunk" data-layout="l-body">
## A
This is a section
## B
This is a section
## C
This is a section
</div>
# Section 2
Works with 1 iteration
<div class="layout-chunk" data-layout="l-body">
## A
This is a section
</div>
```{.r .distill-force-highlighting-css}
**distill** will wrap a chunk in a div and this seems to prevent Pandoc `--toc` to work. Could be something with Pandoc: https://github.com/jgm/pandoc/issues/3057 and https://github.com/jgm/pandoc/issues/997.
By default div are considered Pandoc Divs, and this cause the issue. Disabling `native_divs` makes this work
````markdown
output:
distill::distill_article:
toc: true
md_extensions: -native_divs
However, I also wonder if we should really add this <div>
for chunk that have results='asis'
🤔
@jjallaire would it make sense to not wrap such chunks in these special div ? Usualy using result = 'asis'
means you produce Markdown or HTML directly and maybe this layout-chunk
div is not required in this case.
I think this would fix this issue.
Thanks for this! md_extensions: -native_divs
works great.
Please see the attached zip with an
.Rmd
file and the resulting.html
produced viaknit to distill_article
from Rstudio. This should serve as an example of the problem.The gist of what I'm seeing is that headers produced from within a loop that iterates
> 1
times (lapply
in my case) are not rendered in the distill table of contents. If the loop only iterates once, then the header produced from the loop is rendered in the distill table of contents. I would expect both cases to produce entries in the distill table of contents.Package/R versions:
test_loop_headers.zip