{"record":{"id":"ea17f5836e7776b9","repo":"mermaid-js/mermaid","slug":"diagrams-beginning-with-are-not-valid-if-you","errorCode":null,"errorMessage":"Diagrams beginning with --- are not valid. If you were trying to use a YAML front-matter, please ensure that you've correctly opened and closed the YAML front-matter with un-indented `---` blocks","messagePattern":"Diagrams beginning with --- are not valid\\. If you were trying to use a YAML front-matter, please ensure that you've correctly opened and closed the YAML front-matter with un-indented `---` blocks","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/mermaid/src/diagram-api/diagram-orchestration.ts","lineNumber":72,"sourceCode":"  });\n  registerDiagram(\n    '---',\n    // --- diagram type may appear if YAML front-matter is not parsed correctly\n    {\n      db: {\n        clear: () => {\n          // Quite ok, clear needs to be there for --- to work as a regular diagram\n        },\n      },\n      styles: {}, // should never be used\n      renderer: {\n        draw: () => {\n          // should never be used\n        },\n      },\n      parser: {\n        parse: () => {\n          throw new Error(\n            'Diagrams beginning with --- are not valid. ' +\n              'If you were trying to use a YAML front-matter, please ensure that ' +\n              \"you've correctly opened and closed the YAML front-matter with un-indented `---` blocks\"\n          );\n        },\n      },\n      init: () => null, // no op\n    },\n    (text) => {\n      return text.toLowerCase().trimStart().startsWith('---');\n    }\n  );\n\n  if (injected.includeLargeFeatures) {\n    registerLazyLoadedDiagrams(flowchartElk, mindmap, architecture);\n  }\n\n  // Ordering of detectors is important. The first one to return true will be used.","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/mermaid-js/mermaid/blob/d93e9c88c01a599c062ee6a3f1462e3558ac6b90/packages/mermaid/src/diagram-api/diagram-orchestration.ts#L54-L90","documentation":"Thrown by a special stub diagram registered in diagram-orchestration for any text that starts (after lowercasing/trimming) with '---'. The stub's parse() always throws, because a bare '---' opener is treated as a malformed YAML front-matter block rather than a real diagram. It only parses if you also close the front matter correctly.","triggerScenarios":"Diagram text begins with '---' but the front matter is never closed with a second '---', or the text is literally just '---' with no diagram body after it.","commonSituations":"A user pastes a markdown file whose leading '---' front matter was left in, or hand-writes a diagram and accidentally starts it with '---'.","solutions":["Wrap front matter in a matching pair of un-indented '---' lines and put the diagram after the closing one.","Remove the leading '---' if no front matter was intended.","Ensure the opening '---' is not indented; indented '---' is not recognised as front matter."],"exampleFix":"// before\n---\ntitle: My Diagram\ngraph TD; A-->B\n\n// after\n---\ntitle: My Diagram\n---\ngraph TD; A-->B","handlingStrategy":"validation","validationCode":"function hasClosedFrontMatter(text: string): boolean {\n  const t = text.trimStart();\n  if (!t.startsWith('---')) return true;\n  const after = t.slice(3);\n  return /(^|\\n)---(\\s|$)/.test(after);\n}\nif (!hasClosedFrontMatter(text)) {\n  throw new Error('Unclosed YAML front matter');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await Diagram.fromText(text);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Diagrams beginning with ---')) {\n    // prompt user to fix/remove front matter\n  } else throw e;\n}","preventionTips":["Always close YAML front matter with a second un-indented '---'.","Strip front matter before passing text to mermaid if it is unused.","Avoid starting a diagram body with a literal '---'."],"tags":["mermaid","front-matter","yaml","diagram","parse"],"backgroundTag":null,"analyzedSha":"d93e9c88c01a599c062ee6a3f1462e3558ac6b90","analyzedAt":"2026-08-12T06:23:11.304Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}