davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
565 stars 82 forks source link

Cross Reference links in HTML not scrolling to anchor id #653

Closed rcarboni closed 2 months ago

rcarboni commented 3 months ago

When I create cross-references to flextables, either with a target id specified through #| tab.id: <id> or {r, tab.id=<ic>} chunk options, and use in a cross-reference as \@ref(tab:<id>), the knitted HTML creates a proper link with the correct html target/anchor id and the matching id on the table object:

<p>And link to <a href="#tab:table2">1.1</a></p>
<caption style="display:table-caption;"><span id="tab:table2">Table 1.1: </span><span>Second Table</span></caption>

but clicking on the first one doesn't jump/scroll to the second one.

Could this be due to the flextable being inside a #shadow-root?

REPRODUCIBLE EXAMPLE .Rmd

--- output: bookdown::html_document2 ---

```{r}

| tab.id: table1

| tab.cap: "First Table"

cars |> flextable::qflextable() ```

```{r, tab.cap='Second Table', tab.id='table2'} cars |> flextable::qflextable() ```

Link to \@ref(tab:table1)

And link to \@ref(tab:table2)

REPRODUCIBLE EXAMPLE END

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-apple-darwin20
Running under: macOS Sonoma 14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

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

time zone: America/Los_Angeles
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] utf8_1.2.4              fontLiberation_0.1.0    xml2_1.3.6             
 [4] httpcode_0.3.0          digest_0.6.36           magrittr_2.0.3         
 [7] evaluate_0.24.0         grid_4.4.1              flextable_0.9.7.005    
[10] fastmap_1.2.0           jsonlite_1.8.8          zip_2.3.1              
[13] processx_3.8.4          crul_1.5.0              ps_1.7.6               
[16] promises_1.3.0          fansi_1.0.6             fontBitstreamVera_0.1.1
[19] textshaping_0.4.0       cli_3.6.3               shiny_1.9.1            
[22] rlang_1.1.4             fontquiver_0.2.1        crayon_1.5.3           
[25] reprex_2.1.1            withr_3.0.1             gfonts_0.2.0           
[28] yaml_2.3.10             gdtools_0.3.7           tools_4.4.1            
[31] officer_0.6.6           uuid_1.2-1              httpuv_1.6.15          
[34] curl_5.2.1              vctrs_0.6.5             R6_2.5.1               
[37] mime_0.12               lifecycle_1.0.4         fs_1.6.4               
[40] ragg_1.3.2              pkgconfig_2.0.3         callr_3.7.6            
[43] clipr_0.8.0             pillar_1.9.0            later_1.3.2            
[46] data.table_1.15.4       glue_1.7.0              Rcpp_1.0.13            
[49] systemfonts_1.1.0       xfun_0.46               tibble_3.2.1           
[52] rstudioapi_0.16.0       knitr_1.48              xtable_1.8-4           
[55] htmltools_0.5.8.1       rmarkdown_2.27          compiler_4.4.1         
[58] askpass_1.2.0           openssl_2.2.0 
davidgohel commented 2 months ago

Yes, there have been some changes in bookdown, I think it had some negative impacts with flextable but I'm not sure if that's where it came from. Anyway, I've prepared a fix.

davidgohel commented 2 months ago

it should be fixed now