rstudio / pagedown

Paginate the HTML Output of R Markdown with CSS for Print
https://pagedown.rbind.io
Other
894 stars 127 forks source link

List of Figures/Tables not working in pagedown::html_paged (loft.lua / pandoc issue?) #280

Closed adamvi closed 2 years ago

adamvi commented 2 years ago

Hello and, like many others, I am so grateful for and indebted to your efforts on the development of this package!

I am no longer able to produce a list of figures/tables in reports that had rendered/chrome_printed well previously (Dec 2021). I am scheduled to present this work with a demonstration on how to create pagedown reports at a large conference for education researchers next month (!) so I'm hoping to get this worked out ASAP so that I can (re)present it thoroughly and with confidence...

I munged around for over a day in code and compared HTML, knit.md, etc results with previous versions, and eventually came to the conclusion that the issue is in the pagedown package somewhere (or perhaps due to recent changes in pandoc?) and not with anything I've done.

I was able to replicate this issue using the skeleton.Rmd file in the latest dev version of the package:

dir.create("tests")
file.copy(system.file("rmarkdown", "templates", "html-paged", "skeleton", "skeleton.Rmd" , package = "pagedown"), "tests")
##  Run without changes, and then repeat with changes in YAML
rmarkdown::render(file.path("tests", "skeleton.Rmd"), clean=FALSE)
pagedown::chrome_print(file.path("tests", "skeleton.html"), wait=10, timeout=60)

I ran this code with the skeleton.Rmd "out-of-the-box" and with several different changes in the YAML trying to get the lof and/or lot options to work based on what had worked for me as well as in your documentation. For example:

---
title: "A Multi-page HTML Document"
author: "Yihui Xie and Romain Lesur"
date: "`r Sys.Date()`"
output:
  pagedown::html_paged:
    toc: true
    self_contained: true
toc-title: Contents
lot: true
lot-title: "Tables"
lof: true
lof-title: "Figures"
---

# Test

```{r, fig.cap='A caption.'}
plot(1)

The only additional feature to be produced was the `toc-title` - no List of Figures and/or Tables.

I examined the HTML output in these examples and my reports, and the issue seems to be that the LOF `<div>` is not being created in the pandoc rendering process with the `loft.lua` filter.  In a version of a test report that previously rendered with the LOF, I had something like this:

``` html
<div id="LOF" class="section level1 lof unnumbered front-matter">
<h1>Tables and Figures</h1>
<ul>
<li><a href="#fig:unnamed-chunk-15">1</a> Example learning loss recovery trajectories.</li>
<li><a href="#fig:hist-prof">2</a> Historical percent proficient trends by content area and grade</li>
<li><a href="#fig:unnamed-chunk-16">5</a> Example learning loss illustration with a summative state assessment</li>
</ul>
</div>

Some things I've tried with the example and my report:

I have NO experience with LUA and no idea how to debug any potential issues, which is why I'm referring this issue to you 😃

Thank you in advance for advice/package changes!

Pandoc version (used in rmarkdown):

pandoc 2.17.1.1
Compiled with pandoc-types 1.22.1, texmath 0.12.4, skylighting 0.12.2,
citeproc 0.6.0.1, ipynb 0.2

Session Info:

> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur/Monterey 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rmarkdown_2.13.1 pagedown_0.17.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.2     knitr_1.37       servr_0.24       magrittr_2.0.2   R6_2.5.1         rlang_1.0.2      fastmap_1.1.0    stringr_1.4.0    highr_0.9        tools_4.1.3      websocket_1.4.1
[12] xfun_0.30        cli_3.2.0        jquerylib_0.1.4  htmltools_0.5.2  yaml_2.3.5       digest_0.6.29    bookdown_0.25.2  processx_3.5.2   later_1.3.0      ps_1.6.0         sass_0.4.0
[23] promises_1.2.0.1 evaluate_0.15    mime_0.12        stringi_1.7.6    compiler_4.1.3   bslib_0.3.1      jsonlite_1.8.0   httpuv_1.6.5
yihui commented 2 years ago

I guess this is a pandoc version problem. Our example page https://pagedown.rbind.io is built with Pandoc 2.14.2. I just tried Pandoc 2.17.1.1, and the LOT/LOF couldn't be generated. @cderv @RLesur Could you take a look? Thanks!

cderv commented 2 years ago

This come indeed from Pandoc version. Last one working is 2.16.2 so change happens on 2.17. I'll have a look and see if we can add some test to detect that earlier.

cderv commented 2 years ago

Ok I think I have found the culprit in 2.17 release note.

Functions of name Doc are no longer accepted as alternatives for Pandoc filter functions. This functionality was undocumented.

It seems we were using an undocumented feature in our Lua filter. I'll rewrite this.

cderv commented 2 years ago

@adamvi Open PR should fix this is you are in a hurry

remotes::install_github("rstudio/pagedown")

It should be merged soon though.

yihui commented 2 years ago

I am scheduled to present this work with a demonstration on how to create pagedown reports at a large conference for education researchers next month (!) so I'm hoping to get this worked out ASAP so that I can (re)present it thoroughly and with confidence...

@adamvi If the current dev version works for you, we can make a new CRAN release soon. Thanks for presenting this package at the conference!