### Bug description

Hi. I'm trying to render some `.qmd` files to the PDF format with Mermaid/Graphviz diagrams inside. It seems that when the diagrams are labeled, `figure` environments in the generated `.tex` file are nested, which is a little weird for me.

Here's a minimal example.

````md
---
title: "Test"
format:
  latex:
    default
---

```{dot}
//| label: fig-1
//| fig-cap: a Graphviz figure
digraph G{
    A -> B -> C -> D
}
```
````

and the diagram part of the `.tex` output is:

````latex
\begin{figure}
    {\centering 
        \begin{figure}[H]
            {\centering \includegraphics[width=5.5in,height=3.5in]{index_files/figure-latex/dot-figure-1.png}}
        \end{figure}
    }
    \caption{\label{fig-1}a Graphviz figure}
\end{figure}
````

So these `figure` environments get nested, despite the desired output:

````latex
\begin{figure}[H]
    {\centering \includegraphics[width=5.5in,height=3.5in]{index_files/figure-latex/dot-figure-1.png}}
    \caption{\label{fig-1}a Graphviz figure}
\end{figure}
````

Though the problem seems to be harmless to the PDF output with default options, it may cause some unexpected glitches when custom templates are used.

probably related: #821 triggers the same problem.

- quarto version: 1.2.269
- OS: Windows

### Checklist

- [X] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [ ] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
cscheid
2022-12-22T10:51:26Z
sun123zxy
bug crossref
v1.4
open
labeled Mermaid & Graphviz diagrams generate nested `figure` environments in LaTeX
https://github.com/quarto-dev/quarto-cli/issues/3736