%YAML 1.2
---
name: Mermaid
file_extensions:
- mermaid
- mmd
scope: source.mermaid
contexts:
main:
- include: comment
- include: strings
- include: links
- include: head
- include: keywords
- include: members
- include: numbers
- include: shapes
- include: identifiers
comment:
- match: '%%.*$\n?'
scope: comment.line.percent.mermaid
strings:
- match: '"'
scope: punctuation.definition.string.begin.mermaid
push: string_double
- match: "'"
scope: punctuation.definition.string.begin.mermaid
push: string_single
string_double:
- meta_scope: string.quoted.double.mermaid
- match: '\\.'
scope: constant.character.escape.mermaid
- match: '"'
scope: punctuation.definition.string.end.mermaid
pop: true
- match: '$\n?'
pop: true
string_single:
- meta_scope: string.quoted.single.mermaid
- match: "'"
scope: punctuation.definition.string.end.mermaid
pop: true
- match: '$\n?'
pop: true
links:
- match: '(<\|?|<)?(={2,}|-\.+-|-{2,})(\|>|>{1,2}|\){1,2}|[ox])'
scope: keyword.operator.link.mermaid
- match: '(<\|?|<)?(\.{2,})(\|?>)'
scope: keyword.operator.link.mermaid
- match: '(->>?|-\)|-x)'
scope: keyword.operator.link.mermaid
- match: '(<\|?|[ox*])--([ox])?'
scope: keyword.operator.link.mermaid
- match: '(={2,}|-{2,})'
scope: keyword.operator.link.mermaid
- match: '(<{2,}|\^|v(?=\s*\|))'
scope: keyword.operator.direction.mermaid
head:
- match: '^\s*(?i:(flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v\d+)?|gantt|pie|quadrantChart|erDiagram|journey|gitGraph|mindmap|timeline|requirementDiagram|block-beta|C4[A-Za-z]*))\b'
scope: keyword.control.diagram.mermaid
push: head_direction
head_direction:
- meta_scope: meta.diagram.mermaid
- match: '[ \t]+'
- match: '\b(?i:(TD|TB|BT|LR|RL))\b'
scope: constant.language.direction.mermaid
- match: '$\n?'
pop: true
- include: comment
- match: ';'
scope: punctuation.terminator.mermaid
pop: true
- match: '.'
pop: true
keywords:
- match: '^\s*(?i:(subgraph|end|direction|participant|actor|note|alt|else|opt|loop|par|and|break|critical|option|rect|activate|deactivate|autonumber|create|destroy|links|link|call|click|classDef|class|style|linkStyle|title|section|dateFormat|axisFormat|excludes|todayMarker|tickInterval|weekday|state|default|namespace|interface|accTitle|accDescr|quadrant-[1-4]|x-axis|y-axis))\b'
captures:
1: keyword.other.statement.mermaid
- match: '\b(?i:(left of|right of|over|as))\b'
scope: keyword.other.modifier.mermaid
- match: '(?=:)'
push: statement_text
statement_text:
- meta_scope: meta.statement.mermaid
- include: comment
- include: strings
- include: numbers
- match: '$\n?'
pop: true
- match: '[^|%"\n\d]+'
scope: text.mermaid
members:
- match: '^[ \t]*(?=[+\-#~][A-Za-z_$])'
push: visibility
- match: '(~[A-Za-z_][A-Za-z0-9_]*~)'
scope: storage.type.generic.mermaid
visibility:
- match: '[+\-#~]'
scope: keyword.other.visibility.mermaid
pop: true
- match: ''
pop: true
numbers:
- match: '\b\d+(?:\.\d+)?(?:ms|s|m|h|d|w|y|%)\b'
scope: constant.numeric.duration.mermaid
- match: '\b\d+(?:\.\d+)?\b'
scope: constant.numeric.mermaid
shapes:
- match: '\|'
scope: punctuation.definition.label.mermaid
push: edge_label
- match: '(\(\(|\)\)|\[\[|\]\]|\[|\]|\(|\)|\{|\})'
scope: punctuation.definition.shape.mermaid
edge_label:
- meta_scope: string.unquoted.edge-label.mermaid
- include: strings
- match: '\|'
scope: punctuation.definition.label.mermaid
pop: true
- match: '$\n?'
pop: true
- match: '[^%"\n|]+'
scope: text.mermaid
identifiers:
- match: '\b[A-Za-z_][A-Za-z0-9_\-]*\b'
scope: variable.other.id.mermaid