From: Charles McGarvey Date: Wed, 4 Mar 2020 02:45:33 +0000 (-0700) Subject: Initial commit X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=ee69535580bbe2dd66a06b81780ac815f6824a8c;p=chaz%2Fvim-mermaid Initial commit --- ee69535580bbe2dd66a06b81780ac815f6824a8c diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6bfa669 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Charles McGarvey + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..69542ce --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ + +VIM ?= vim + +all: + +run: test + +test: test.mmd + $(VIM) --cmd 'let &runtimepath=".,".&runtimepath' $^ + +.PHONY: all run test diff --git a/README.md b/README.md new file mode 100644 index 0000000..2457db9 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# vim-mermaid - [Vim](https://www.vim.org) syntax for [mermaid](https://mermaid-js.github.io/mermaid/) + +This makes Vim support mermaid diagram syntax. + +## Install + +Using [vim-plug](https://github.com/junegunn/vim-plug): + + Plug 'chazmcgarvey/vim-mermaid' + +Or similar with the Vim plugin manager of your choice. + +## Caveats + +So far only sequence diagrams are supported. diff --git a/ftdetect/mermaid.vim b/ftdetect/mermaid.vim new file mode 100644 index 0000000..cca2b71 --- /dev/null +++ b/ftdetect/mermaid.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.mmd setlocal filetype=mermaid commentstring=%%\ %s diff --git a/syntax/mermaid.vim b/syntax/mermaid.vim new file mode 100644 index 0000000..3c36f0c --- /dev/null +++ b/syntax/mermaid.vim @@ -0,0 +1,87 @@ +" Vim syntax file for Mermaid diagrams +" Language: Mermaid +" Maintainer: Charles McGarvey +" Version: 0.1 + +if exists('b:current_syntax') + finish +endif + +" sequenceDiagram +syntax keyword mmdDiagramType sequenceDiagram + +" -> --> ->> -->> -X --X +syntax match mmdArrow /\v(--\>\>|--\>|-\>\>|--X|-\>|-X)/ + \ nextgroup=mmdActivationSymbol,mmdActorBeforeMessage skipwhite contained + +syntax match mmdInvalidActorChar /[-:;,]/ contained + +syntax match mmdActorBeforeArrow /\v\S.{-}\ze\s*(-\>|--\>|-\>\>|--\>\>|-X|--X)/ + \ contains=mmdInvalidActorChar nextgroup=mmdArrow skipwhite +syntax match mmdActorBeforeMessage /\v([^\t :][^:]*)=[^\t :]/ + \ contains=mmdInvalidActorChar nextgroup=mmdMessageDelimiter skipwhite contained +syntax match mmdActorBeforeComma /\v\S.{-}\ze\s*,/ + \ contains=mmdInvalidActorChar nextgroup=mmdComma,mmdActorBeforeMessage skipwhite contained + +" , +syntax match mmdComma /\v,/ nextgroup=mmdActorBeforeMessage skipwhite contained + +" +|- +syntax match mmdActivationSymbol /\v[-\+]/ contained nextgroup=mmdActorBeforeMessage skipwhite + +" participant [as ] +" activate +" deactivate +syntax match mmdActor /\v\S.*/ contained contains=mmdInvalidActorChar +syntax match mmdActor /\v\c\S.{-}\ze\s+as\s/ nextgroup=mmdAlias skipwhite contained contains=mmdInvalidActorChar +syntax match mmdParticipant /^\v\c\s*\zsparticipant\ze\s/ nextgroup=mmdActor skipwhite +syntax match mmdAlias /\v\cas\ze\s/ nextgroup=mmdMessage skipwhite contained +syntax match mmdActivation /^\v\c\s*\zs(activate|deactivate)\s+/ nextgroup=mmdActor skipwhite + +" loop [] +" alt [] +" else [] +" opt [] +" rect [] +" end +syntax match mmdGroup /^\v\c\s*\zs(alt|else|loop|opt)/ nextgroup=mmdMessage skipwhite +syntax match mmdGroup /^\v\c\s*\zsrect/ nextgroup=mmdColor skipwhite +syntax match mmdGroup /^\v\c\s*\zsend/ +syntax match mmdColor /\v\S.*/ contained + +" autonumber +syntax match mmdAutonumber /^\v\c\s*\zsautonumber/ + +" Note left|right of : +" Note over [,]: +syntax match mmdMessageDelimiter /\v:/ contained nextgroup=mmdMessage skipwhite +syntax match mmdMessage /\v\S.*/ contained +syntax match mmdNote /^\v\c\s*Note\s+(right of|left of)\ze\s/ nextgroup=mmdActorBeforeMessage skipwhite +syntax match mmdNote /^\v\c\s*Note\s+over\ze\s/ nextgroup=mmdActorBeforeComma,mmdActorBeforeMessage skipwhite + +" %% +syntax keyword mmdTodo contained FIXME TODO XXX +syntax match mmdComment /\v\%\%.*$/ contains=mmdTodo + +highlight link mmdInvalidActorChar Error +highlight link mmdDiagramType Function +highlight link mmdArrow Operator +highlight link mmdComma Operator +highlight link mmdActivationSymbol Keyword +highlight link mmdParticipant Keyword +highlight link mmdActivation Keyword +highlight link mmdAlias Keyword +highlight link mmdTodo Todo +highlight link mmdComment Comment +highlight link mmdActor Identifier +highlight link mmdActorBeforeArrow Identifier +highlight link mmdActorBeforeMessage Identifier +highlight link mmdActorBeforeComma Identifier +highlight link mmdMessageDelimiter Delimiter +highlight link mmdMessage String +highlight link mmdNote Keyword +highlight link mmdGroup Statement +highlight link mmdAutonumber Statement +highlight link mmdColor Constant + +let b:current_syntax = 'mermaid' diff --git a/test.mmd b/test.mmd new file mode 100644 index 0000000..291daf6 --- /dev/null +++ b/test.mmd @@ -0,0 +1,32 @@ +%% This diagram file doesn't compile but can be used to manually test +%% highlighting. +sequenceDiagram + participant this wasdf sadf as as Alice in chains + participant John,asdf + Alice->> + John: Hello John, how are you? %% asdfaf + Alice ->> +John: John, can you hear me? + Alice ->> John : John, can you hear me? + activate John!!! + Jo;n-->> - This is a test : Hi Alice, I can hear you! + John-->> + Z : Hi Alice, I can hear you! + %% whatever + activate Foo + loop This is just a test + John-->>-Alice: I feel great! + end + Loop F + John-->>-Alice: I feel great! + END + alt whatever + else + end + opt asfef + foo -> bar : nice + end + rect brown + TODO asdf as + Note left of Alice: whatever + Note right of asdf : asdfwe + Note over foo,Bar : asdfwe + Alice -X +Bob : Hello world!!!!!!!!!1 + %% TODO This is a comment FIXME