mermaid-js / mermaid-cli

Command line tool for the Mermaid library
MIT License
2.23k stars 210 forks source link

Frontmatter breaks svg generation #611

Closed itaysk closed 8 months ago

itaysk commented 8 months ago

Describe the bug Trying to render a flowchart with a front matter section (e.g chart title) fails:

Error: Evaluation failed: Error: Parse error on line 1:
---title: mytitle
^
Expecting 'NEWLINE', 'SPACE', 'GRAPH', got 'LINK'

same chart in Live editor works, or in GitHub:

---
title: mytitle
---
flowchart TD
  a

To Reproduce Steps to reproduce the behavior:

❯ echo <<EOF > /tmp/test
heredoc> ---
title: mytitle
---
flowchart TD
  a
heredoc> EOF
❯ mmdc -i /tmp/test -o /tmp/test_out.svg
Generating single mermaid chart

Error: Evaluation failed: UnknownDiagramError: No diagram type detected matching given configuration for text: 
    at s1A (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:11:76)
    at yjA (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:64:685)
    at Object.VDe [as render] (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:87:1152)
    at file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:89:538
    at new Promise (<anonymous>)
    at Q (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:89:515)
    at zUt (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:89:190)
    at file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:89:674
    at new Promise (<anonymous>)
    at Object.PUt [as render] (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/dist/index.html:89:483)
    at pptr://__puppeteer_evaluation_script__:14:46
    at ExecutionContext._ExecutionContext_evaluate (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:254:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js:143:16)
    at async CDPJSHandle.evaluate (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/JSHandle.js:56:16)
    at async CDPElementHandle.$eval (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/node_modules/puppeteer-core/lib/esm/puppeteer/common/ElementHandle.js:86:24)
    at async renderMermaid (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:246:22)
    at async parseMMD (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:218:20)
    at async run (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:479:20)
    at async cli (file:///opt/homebrew/lib/node_modules/@mermaid-js/mermaid-cli/src/index.js:184:3)

Expected behavior Title should be rendered, or at least not breaking the render

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

itaysk commented 8 months ago

sorry it appears the problem was with a leading whitespace.

aloisklink commented 8 months ago

No worries!

Maybe there's a way to add a better error message to Mermaid if that happens?

I know Mermaid is moving their parsing engine to Langium, so it might be something to change once that happens.