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

Open
#10,275 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
typescript
Domain
frontend, web-dev

Research direction

Read src/format/html/format-html.ts around lines 709-731, then review the linked discussion and example document to understand the anchor conflict. The issue presents multiple possible designs rather than a decided change; done would require an agreed selective opt-out behavior for headings or figures.

Written by the indexing model from the issue text.

Description

enhancement html

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

  • More configuration
     anchor-sections:
        headings: false
    
  • or exposing the opt-out through .no-anchor class.
    It can work with heading today, but really hard to set on computed figure because using cell option classes: no-anchor will set on the div.cell and not on the div.quarto-figure

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

But sometimes, with interactive graphics, it can conflict with existing elements.

Screenshot 2024-07-11 at 17 28 39

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

Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from quarto-dev/quarto-cli

All issues in quarto-dev/quarto-cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.