mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.35k stars 227 forks source link

Ignore invalid diagrams in markdown instead of throwing error #543

Open alamise opened 1 year ago

alamise commented 1 year ago

I have a requirement: to replace the charts saved in mermaid format in a markdown file (c.md) with actual images. So, I installed mermaid-cli and executed the following command:

mmdc -i c.md -o c_1.md

It's basically working fine, but there is a small issue: There are multiple charts in c.md, and one of them has an incorrect format.

Expected behavior: Skip the erroneous chart and convert the charts with the correct format. The erroneous chart should retain its original code in the markdown file.

Current behavior: Encountering an erroneous chart results in an error and the process terminates.

aloisklink commented 1 year ago

Encountering an erroneous chart results in an error and the process terminates.

In my opinion, this is expected behavior, and it's what I'd want mermaid-cli to do.

It might make sense to add an option (maybe something like --replace-invalid-mermaid) that prints a warning if a mermaid chart is invalid, something like what GitHub does:

Input

```mermaid
flowchart
  This is my example invalid diagram.


### Output

![image](https://github.com/mermaid-js/mermaid-cli/assets/19716675/526633b9-6004-4197-805c-1264ff96a325)

_Edit_: By the way @alamise, I hope you don't mind, I edited your issue title! Please feel free to change it something else if you'd prefer.