quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.96k stars 327 forks source link

FR: Forward additional attributes from code cells to FloatRefTarget nodes #8659

Open wjschne opened 9 months ago

wjschne commented 9 months ago

Bug description

I am creating a custom output for figures and tables that depends on custom attributes. FloatRefTarget has custom attributes for for tables but not for figures.

Steps to reproduce

---
format: 
  html:
    filters: 
      - myfilter.lua
---

```{r tbl-mytable}
#| tbl-cap: My caption
#| myattribute: value
data.frame(Numbers = seq(1,2), Letters = c("A", "B")) |> 
  knitr::kable()
#| fig-cap: My caption
#| myattribute: value
plot(1:3)

```lua 
--myfilter.lua
FloatRefTarget = function(float)
  quarto.log.output(float.type)
  quarto.log.output(float.attributes)
end

Expected behavior

quarto.log.output:

Table
List {myattribute: "value"}
Figure
List {myattribute: "value"}

Actual behavior

quarto.log.output:

Table
List {myattribute: "value"}
Figure
List {}

Your environment

Quarto check output

Quarto 1.5.9
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.5.9
      Path: C:\Program Files\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.11.3
      Path: C:/Users/renee/AppData/Local/Programs/Python/Python311/python.exe
      Jupyter: 5.3.1
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.3.2
      Path: C:/PROGRA~1/R/R-4.3.2
      LibPaths:
        - C:/Users/renee/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.2/library
      knitr: 1.45
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK
cscheid commented 9 months ago

We've never considered the possibility of forwarding arbitrary content in the metadata of code cells to the FloatRefTarget objects, and I don't think we document this anywhere.

I'm reading this as a feature request rather than a bug report, but I nevertheless like the idea. Still, but we need to think carefully about how this behavior across a variety of use cases (specifically, the outputs generated by code cells in different engines). I'd love to do it, but I don't know when we will have the resources to put in this.

cscheid commented 9 months ago

Another consideration is the variety of different ways in which FloatRefTarget nodes can be created, including:

mcanouil commented 9 months ago

Side note: mixing code cell options syntaxes is really not recommended. Recommended syntax is YAML. Please consider using label as YAML rather than as R/knitr inline.

```{r}
#| label: fig-myfigure
#| fig-cap: My caption
#| myattribute: value
plot(1:3)
wjschne commented 9 months ago

Thanks for your consideration. I have a hacky workaround that works. If time permits, it would be nice to have a more straightforward solution.