Skip to content

Commit

Permalink
Rework syntax matching for graph links, w/ renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
hlfcoding committed Aug 13, 2017
1 parent 2f88e23 commit b35f433
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ graph BT
graph TB
ID-1>This is the text in the asymmetric box] %% tab completion: 'node'
ID-2>This is the text in the asymmetric box]
ID-1 --- ID-2
ID-1 --> ID-2
click ID-1 "http://www.github.com" "This is a tooltip for a link"
%% Example code
Expand All @@ -27,7 +27,7 @@ graph TD
graph LR
ID-1{This is the text in the rhombus} %% tab completion: 'node'
ID-2{This is the text in the rhombus}
ID-1-->ID-2
ID-1-->|This is the link text|ID-2
%% Example code
graph RL
Expand Down
33 changes: 22 additions & 11 deletions mermaid.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ file_extensions:
- mermaid
scope: source.mermaid
variables:
link: "--(?:-|\\>)"
node: \b\S+\b
node_from: ^\s*{{node}}\s?
node_to: \s?{{node}}\s*$
node_to: \s?{{node}}\b
text: .+
contexts:
prototype:
- include: line_comment
Expand Down Expand Up @@ -43,32 +45,41 @@ contexts:
- match: $
pop: true

- match: "{{node_from}}(--(-|\\>)){{node_to}}"
- match: "{{node_from}}(---)\\s?"
captures:
1: keyword.operator.type.link.mermaid
scope: meta.declaration.graph.link.mermaid
1: keyword.operator.link.begin.mermaid
push:
- meta_scope: meta.declaration.graph.link.mermaid
- match: "({{text}})\\s?({{link}})"
captures:
1: string.text.link.mermaid
2: keyword.operator.link.end.mermaid
- match: '{{node_to}}'
pop: true

- match: "{{node_from}}(---?)\\s?"
- match: "{{node_from}}({{link}})"
captures:
1: keyword.operator.type.link.begin.mermaid
1: keyword.operator.link.mermaid
push:
- meta_scope: meta.declaration.graph.link.mermaid
- meta_content_scope: string.text.link.mermaid
- match: "\\s?(--(-|\\>)?){{node_to}}"
- match: "(\\|)({{text}})(\\|)"
captures:
1: keyword.operator.type.link.end.mermaid
1: keyword.operator.link.text.begin.mermaid
2: string.text.link.mermaid
3: keyword.operator.link.text.end.mermaid
- match: '{{node_to}}'
pop: true

- match: "^\\s*({{node}})(\\[|\\(+|\\>|\\{)"
captures:
1: entity.name.node.mermaid
2: keyword.operator.type.node.begin.mermaid
2: keyword.operator.node.begin.mermaid
push:
- meta_scope: meta.declaration.graph.node.mermaid
- meta_content_scope: string.text.node.mermaid
- match: "(\\]|\\)+|\\})(\\b|\\s)"
captures:
1: keyword.operator.type.node.end.mermaid
1: keyword.operator.node.end.mermaid
pop: true

line_comment:
Expand Down

0 comments on commit b35f433

Please sign in to comment.