summaryrefslogtreecommitdiff
path: root/user/vim
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-01-04 20:06:56 +0100
committerMartin Fischer <martin@push-f.com>2025-01-04 20:06:58 +0100
commit57d76e99da8a8635d22c1ff0b11fefb9b82cc8d3 (patch)
tree35a868239e521bb1e61d8c65b69eaaa2d474c596 /user/vim
parent78590c8e329abc8a144eee5e4235b8e82e643c3b (diff)
feat(user/vim): add djot syntax highlighting
From https://github.com/jgm/djot.
Diffstat (limited to 'user/vim')
-rw-r--r--user/vim/ftdetect/djot.vim1
-rw-r--r--user/vim/syntax/djot.vim85
2 files changed, 86 insertions, 0 deletions
diff --git a/user/vim/ftdetect/djot.vim b/user/vim/ftdetect/djot.vim
new file mode 100644
index 0000000..bcb5082
--- /dev/null
+++ b/user/vim/ftdetect/djot.vim
@@ -0,0 +1 @@
+au BufNewFile,BufRead *.dj set filetype=djot
diff --git a/user/vim/syntax/djot.vim b/user/vim/syntax/djot.vim
new file mode 100644
index 0000000..6ec3816
--- /dev/null
+++ b/user/vim/syntax/djot.vim
@@ -0,0 +1,85 @@
+" Vim syntax file
+" Language: Djot
+" Maintainer: John MacFarlane
+" Latest Revision: 2022-10-06
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn match heading '^##* .*$'
+syn match blockquote '^\s*>\%(\s\|$\)'
+
+syn region math matchgroup=delimiter skip='[^`]{1,}' start='[$][$]\?\z(``*\)' end='\z1\|^\s*$'
+syn region codespan matchgroup=delimiter skip='[^`]{1,}' start='\z(``*\)' end='\z1\|^\s*$'
+
+syn region comment matchgroup=delimiter start='%' end='%' contained
+syn region string start='"' end='"' skip='\\"'
+syn region attributes matchgroup=delimiter start="{[^\[\]_*'\"=\\+-]\@=" end="}" contains=string,comment
+
+syn region emphasis matchgroup=delimiter start='_[^[:blank:]}]\@=\|{_' end='_}\|[^[:blank:]{]\@=_\|^\s*$' contains=@inline
+syn region strong matchgroup=delimiter start='\*[^[:blank:]}]\@=\|{\*' end='[^[:blank:]{]\@=\*\|\*}\|^\s*$' contains=@inline
+
+syn region superscript matchgroup=delimiter start='\^[^[:blank:]}]\@=\|{\^' end='\^}\|[^[:blank:]{]\@=\^\|^\s*$' contains=@inline
+syn region subscript matchgroup=delimiter start='\~[^[:blank:]}]\@=\|{\~' end='\~}\|[^[:blank:]{]\@=\~\|^\s*$' contains=@inline
+
+syn region highlight matchgroup=delimiter start='{=' end='=}\|^\s*$' contains=@inline
+syn match rawattribute "`\@<={=[A-Za-z0-9]*}"
+
+syn region insert matchgroup=delimiter start='{+' end='+}\|^\s*$' contains=@inline
+syn region delete matchgroup=delimiter start='{-' end='-}\|^\s*$' contains=@inline
+
+syn match inlinelink '\[\%([^\]\\]\|\\[\]\\]\|[\r\n]\)*\](\%([^)\\]\|\\[)\\]\)*)' contains=@inline transparent
+syn match linkurl '(\%([^)\\]\|\\[)\\]\)*)'hs=s+1,he=e-1 containedin=inlinelink contained
+
+syn match referencelink '\[\%([^\]\\]\|\\[\]\\]\|[\r\n]\)*\]\[\%([^]\\]\|\\[]\\]\)*\]' contains=@inline transparent
+syn match linklabel '\]\zs\[\%([^]\\]\|\\[]\\]\)*\]'hs=s+1,he=e-1 containedin=referencelink contained
+
+syn match span '\[\%([^\]\\]\|\\[\]\\]\|[\r\n]\)*\][{]\@=' contains=@inline transparent
+
+syn match footnoteref '\[\^[^]]*\]'
+
+syn match openbrace /[{]["']/he=e-1
+syn match closebrace /["'][}]/hs=s+1
+
+syn match emoji ':[a-zA-Z0-9_+-]\+:'
+
+syn match escape '\\[\r\n ~!@#$%^&*(){}`\[\]/=\\?+|\'",<-]'he=e-1
+
+syn region djotautolinkurl matchgroup=delimiter start=/</ end=/>/
+
+syn cluster inline contains=linkurl,emphasis,strong,codespan,attributes,rawattribute,insert,delete,superscript,subscript,highlight,math,smartquote,openbrace,closebrace,emoji,escape,footnoteref,span
+
+syn region codeblock matchgroup=delimiter start='^\s*\z(````*\)\s*=\?\w*\s*$' end='^\s*\z1`*\s*$'
+
+hi emphasis term=italic cterm=italic gui=italic
+hi strong term=bold cterm=bold gui=bold
+hi def link insert Todo
+hi def link delete Error
+hi def link superscript Statement
+hi def link subscript Statement
+hi def link highlight Todo
+hi def link heading Label
+hi def link codespan Tag
+hi def link math Statement
+hi def link emoji Statement
+hi def link span Statement
+hi def link codeblock Tag
+hi def link string String
+hi def link inlinelink Typedef
+hi def link footnoteref Statement
+hi def link linkurl Underlined
+hi def link djotautolinkurl Underlined
+hi def link comment Comment
+hi def link linklabel Underlined
+hi def link escaped Typedef
+hi def link attributes Identifier
+hi def link rawattribute Identifier
+hi def link delimiter Ignore
+hi def link escape Ignore
+hi def link openbrace Ignore
+hi def link closebrace Ignore
+hi def link blockquote Comment
+
+let b:current_syntax = "djot"
+