quarto-dev / quarto-cli

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

[FR] Allow to selectively disable anchors added to headings or figures. #10275

Open cderv opened 1 month ago

cderv commented 1 month ago

anchor-sections configuration only allows true or false to opt-out adding anchor in a document. We don't have currently some more specific configuration to target one of the selector. In particular, sections and figures are dealt the same.

https://github.com/quarto-dev/quarto-cli/blob/00c5b5b79a0ba69ef53edc77261ba63ef47728bc/src/format/html/format-html.ts#L709-L731

We could offer some more control over this in the future, like

Opening this to track idea. Motivation: See https://github.com/quarto-dev/quarto-cli/discussions/10274#discussioncomment-10023421 - the current situation creates conflict with interactive figure that could already have some content exactly at the same place as the anchor we add

Discussed in https://github.com/quarto-dev/quarto-cli/discussions/10274

Originally posted by **royfrancis** July 11, 2024 ### Description A code chunk with a label creates a clickable anchor. This is usually fine and nice to have. ![Screenshot 2024-07-11 at 17 18 21](https://github.com/quarto-dev/quarto-cli/assets/5083500/19a7a32f-0e40-483d-b815-40eba69c5a05) But sometimes, with interactive graphics, it can conflict with existing elements. ![Screenshot 2024-07-11 at 17 28 39](https://github.com/quarto-dev/quarto-cli/assets/5083500/bf81e08a-7f80-424e-b8b6-6a6971b5b30a) `anchor-sections: false` disables anchors for the whole document. Is it possible to disable anchors selectively by chunk? Or enable anchors for headings, but disable for figures? An example document
Click here ```` --- title: Anchor conflict format: html --- ## ggplot ```{r} #| label: fig-ggplot #| fig-cap: A ggplot figure library(ggplot2) data <- data.frame(x = c(1, 2, 3, 4, 5), y = c(10, 11, 12, 13, 14)) p <- ggplot(data = data,aes(x = x,y = y))+ geom_point() p+labs(title="A ggplot figure") ``` ## ggiraph ```{r} #| label: fig-ggiraph #| fig-cap: A ggiraph figure library(ggiraph) p1 <- p+labs(title="A ggiraph figure") girafe(ggobj = p1) |> girafe_options(opts_toolbar(saveaspng = TRUE)) ``` ## plotly ```{r} #| label: fig-plotly #| fig-cap: A plotly figure library(plotly) plot_ly(data, x = ~x, y = ~y, type = 'scatter', mode = 'markers') |> layout(title = list(text = "A plotly figure", x = 0.1)) ``` ````
`quarto 1.5.54`
cscheid commented 1 month ago

I think the good fix here would be to try and make it so that in the case of interactive graphics, both icons appear and look good together.