Is there a way to write a Quarto doc that opens with "This is the plot we are going to produce" then the image, then the code that makes the plot in a possibly variable number of code/text chunks, then at the end the plot again? Without duplicating code. Can I put a markdown image tag at the start that is going to refer to the image that a future chunk is going to produce? Haven't tried yet but maybe its been done. qmd to HTML and/or PDF.

@geospacedman Not everything you asked for, but an attempt based on https://quarto.org/docs/authoring/contents.html

---
format: html
---

This is the plot that we are going to make

{{< contents a-cell >}}

Here is the code for making the plot

::: {#a-cell}
```{r}
#| echo: false
#| label: plot-code
plot(sample(1:10), sample(1:10))
```
:::

```{r}
#| echo: true
#| eval: false
#| label: plot-code
```

The plot again

{{< contents a-cell >}}

And code yet again
```{r}
#| echo: true
#| eval: false
#| label: plot-code
```

@isakroa i thought there was a way - I only really asked as a placeholder to remind me I wanted to figure this out sometime :) Thanks!
@geospacedman Your question made me realise this was something I wanted to know myself and was a good opportunity to look it up:)