quarto-dev / quarto-cli

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

Improve validation of mermaid code block #3235

Open rgaiacs opened 1 year ago

rgaiacs commented 1 year ago

Bug description

The following minimal working example

---
title: "MWE"
---

```{mermaid}
%%| label: fig-percentage
%%| fig-cap: Flowchart

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]
//| label: fig-slash
//| fig-cap: Flowchart

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]

produces

![Screenshot 2022-11-08 at 12-31-11 MWE](https://user-images.githubusercontent.com/1506457/200475640-86a170ab-c949-4bfc-9b9e-aa79591ce243.png)

The build/render log is

pandoc to: html output-file: mermaid.html standalone: true section-divs: true html-math-method: mathjax wrap: none default-image-extension: png

metadata document-css: false link-citations: true date-format: long lang: en title: MWE

Output created: mermaid.html


Would be great to give a warning regarding the wrong code block metadata. For example:

Warning at line 17: mermaid code block uses %%| instead of //| Warning at line 18: mermaid code block uses %%| instead of //|



### 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.
- [X] 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 commented 1 year ago

I'd like to do something like that as well. The problem is that we don't have a good handle on what wrong comments to catch. As I understand it, mermaid syntax is open in the sense that we can't guarantee that //| is invalid syntax for all diagrams (afaict there's no published grammar for every diagram)