2019-12-21 04:41:03 +01:00
|
|
|
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
|
|
|
" Vimwiki syntax file
|
|
|
|
" Description: Defines markdown custom syntax
|
|
|
|
" Home: https://github.com/vimwiki/vimwiki/
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:add_target_syntax_ON(target, type) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
let prefix0 = 'syntax match '.a:type.' `'
|
|
|
|
let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
|
|
|
|
let prefix1 = 'syntax match '.a:type.'T `'
|
|
|
|
let suffix1 = '` display contained'
|
|
|
|
execute prefix0. a:target. suffix0
|
|
|
|
execute prefix1. a:target. suffix1
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:add_target_syntax_OFF(target, type) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
let prefix0 = 'syntax match VimwikiNoExistsLink `'
|
|
|
|
let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
|
|
|
|
let prefix1 = 'syntax match VimwikiNoExistsLinkT `'
|
|
|
|
let suffix1 = '` display contained'
|
|
|
|
execute prefix0. a:target. suffix0
|
|
|
|
execute prefix1. a:target. suffix1
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:wrap_wikilink1_rx(target) abort
|
2017-01-12 21:45:09 +01:00
|
|
|
return vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidPrefix') . a:target.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidSuffix')
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:existing_mkd_refs() abort
|
2017-01-16 22:09:49 +01:00
|
|
|
return keys(vimwiki#markdown_base#scan_reflinks())
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2012-07-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:highlight_existing_links() abort
|
2012-06-07 02:00:00 +02:00
|
|
|
" Wikilink1
|
|
|
|
" Conditional highlighting that depends on the existence of a wiki file or
|
|
|
|
" directory is only available for *schemeless* wiki links
|
|
|
|
" Links are set up upon BufEnter (see plugin/...)
|
2018-04-20 07:03:53 +02:00
|
|
|
let safe_links = '\%('.
|
|
|
|
\ vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikifiles')) .
|
2014-06-22 17:43:26 +02:00
|
|
|
\ '\%(#[^|]*\)\?\|#[^|]*\)'
|
2012-06-07 02:00:00 +02:00
|
|
|
" Wikilink1 Dirs set up upon BufEnter (see plugin/...)
|
2017-01-12 21:45:09 +01:00
|
|
|
let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs'))
|
2012-07-07 02:00:00 +02:00
|
|
|
" Ref links are cached
|
|
|
|
let safe_reflinks = vimwiki#base#file_pattern(s:existing_mkd_refs())
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2012-07-07 02:00:00 +02:00
|
|
|
" match [URL][]
|
2014-06-22 16:26:40 +02:00
|
|
|
let target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2012-06-07 02:00:00 +02:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
|
|
|
|
" match [DESCRIPTION][URL]
|
2014-06-22 16:26:40 +02:00
|
|
|
let target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2012-06-07 02:00:00 +02:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
|
|
|
|
|
2012-07-07 02:00:00 +02:00
|
|
|
" match [DIRURL][]
|
2014-06-22 16:26:40 +02:00
|
|
|
let target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2012-06-07 02:00:00 +02:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
|
|
|
|
" match [DESCRIPTION][DIRURL]
|
2014-06-22 16:26:40 +02:00
|
|
|
let target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2012-06-07 02:00:00 +02:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
|
2012-07-07 02:00:00 +02:00
|
|
|
|
|
|
|
" match [MKDREF][]
|
2014-06-22 16:26:40 +02:00
|
|
|
let target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2012-07-07 02:00:00 +02:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
|
|
|
|
" match [DESCRIPTION][MKDREF]
|
2014-06-22 16:26:40 +02:00
|
|
|
let target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2012-07-07 02:00:00 +02:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
" use max highlighting - could be quite slow if there are too many wikifiles
|
2016-12-22 19:55:20 +01:00
|
|
|
if vimwiki#vars#get_wikilocal('maxhi')
|
2012-06-07 02:00:00 +02:00
|
|
|
" WikiLink
|
2017-01-12 21:45:09 +01:00
|
|
|
call s:add_target_syntax_OFF(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
" Subsequently, links verified on vimwiki's path are highlighted as existing
|
|
|
|
call s:highlight_existing_links()
|
|
|
|
else
|
|
|
|
" Wikilink
|
2017-01-12 21:45:09 +01:00
|
|
|
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
|
2012-06-07 02:00:00 +02:00
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
" Weblink
|
2017-01-12 21:45:09 +01:00
|
|
|
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'VimwikiWeblink1')
|
2019-05-24 05:23:53 +02:00
|
|
|
call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxImage'), 'VimwikiImage')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
" WikiLink
|
|
|
|
" All remaining schemes are highlighted automatically
|
2014-02-24 12:16:23 +01:00
|
|
|
let s:rxSchemes = '\%('.
|
2018-05-20 15:18:05 +02:00
|
|
|
\ vimwiki#vars#get_global('schemes') . '\|'.
|
|
|
|
\ vimwiki#vars#get_global('web_schemes1').
|
2012-06-07 02:00:00 +02:00
|
|
|
\ '\):'
|
|
|
|
|
|
|
|
" a) match [nonwiki-scheme-URL]
|
2014-06-22 16:26:40 +02:00
|
|
|
let s:target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
|
2018-04-20 07:03:53 +02:00
|
|
|
\ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2014-02-24 12:16:23 +01:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
|
2012-06-07 02:00:00 +02:00
|
|
|
" b) match [DESCRIPTION][nonwiki-scheme-URL]
|
2014-06-22 16:26:40 +02:00
|
|
|
let s:target = vimwiki#base#apply_template(
|
2017-01-12 21:45:09 +01:00
|
|
|
\ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
|
2018-04-20 07:03:53 +02:00
|
|
|
\ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'),
|
2020-06-02 01:33:06 +02:00
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '', '')
|
2014-02-24 12:16:23 +01:00
|
|
|
call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" Header levels, 1-6
|
2014-02-24 12:16:23 +01:00
|
|
|
for s:i in range(1,6)
|
2018-04-20 07:03:53 +02:00
|
|
|
execute 'syntax match VimwikiHeader'.s:i.' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i).
|
|
|
|
\ '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'.
|
|
|
|
\ 'VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
|
2012-06-07 02:00:00 +02:00
|
|
|
endfor
|
|
|
|
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" concealed chars
|
2019-12-21 04:41:03 +01:00
|
|
|
if exists('+conceallevel')
|
2012-06-07 02:00:00 +02:00
|
|
|
syntax conceal on
|
|
|
|
endif
|
|
|
|
|
|
|
|
syntax spell toplevel
|
|
|
|
|
|
|
|
" VimwikiWikiLink1Char is for syntax markers (and also URL when a description
|
|
|
|
" is present) and may be concealed
|
2014-02-24 12:16:23 +01:00
|
|
|
let s:options = ' contained transparent contains=NONE'
|
2012-06-07 02:00:00 +02:00
|
|
|
" conceal wikilink1
|
2018-04-20 07:03:53 +02:00
|
|
|
execute 'syn match VimwikiWikiLink1Char /'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rx_wikilink_md_prefix').'/'.s:options
|
|
|
|
execute 'syn match VimwikiWikiLink1Char /'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rx_wikilink_md_suffix').'/'.s:options
|
|
|
|
execute 'syn match VimwikiWikiLink1Char /'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Prefix1').'/'.s:options
|
|
|
|
execute 'syn match VimwikiWikiLink1Char /'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWikiLink1Suffix1').'/'.s:options
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
" conceal weblink1
|
2018-04-20 07:03:53 +02:00
|
|
|
execute 'syn match VimwikiWeblink1Char "'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options
|
|
|
|
execute 'syn match VimwikiWeblink1Char "'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options
|
2019-05-24 05:23:53 +02:00
|
|
|
"image
|
|
|
|
execute 'syn match VimwikiImageChar "!"'.s:options
|
|
|
|
execute 'syn match VimwikiImageChar "'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options
|
|
|
|
execute 'syn match VimwikiImageChar "'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if exists('+conceallevel')
|
2012-06-07 02:00:00 +02:00
|
|
|
syntax conceal off
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" Tables
|
2020-01-05 05:21:52 +01:00
|
|
|
syntax match VimwikiTableRow /^\s*|.\+|\s*$/
|
2012-06-07 02:00:00 +02:00
|
|
|
\ transparent contains=VimwikiCellSeparator,
|
|
|
|
\ VimwikiLinkT,
|
|
|
|
\ VimwikiWeblink1T,
|
|
|
|
\ VimwikiWikiLink1T,
|
|
|
|
\ VimwikiNoExistsLinkT,
|
|
|
|
\ VimwikiTodo,
|
|
|
|
\ VimwikiBoldT,
|
|
|
|
\ VimwikiItalicT,
|
|
|
|
\ VimwikiBoldItalicT,
|
|
|
|
\ VimwikiItalicBoldT,
|
|
|
|
\ VimwikiDelTextT,
|
|
|
|
\ VimwikiSuperScriptT,
|
|
|
|
\ VimwikiSubScriptT,
|
|
|
|
\ VimwikiCodeT,
|
|
|
|
\ VimwikiEqInT,
|
|
|
|
\ @Spell
|
|
|
|
|
2020-01-08 14:03:40 +01:00
|
|
|
" TODO fix behavior within lists https://github.github.com/gfm/#list-items
|
2020-01-03 15:10:02 +01:00
|
|
|
" indented code blocks https://github.github.com/gfm/#indented-code-blocks
|
2020-01-08 14:03:40 +01:00
|
|
|
" execute 'syntax match VimwikiIndentedCodeBlock /' . vimwiki#vars#get_syntaxlocal('rxIndentedCodeBlock') . '/'
|
|
|
|
" hi def link VimwikiIndentedCodeBlock VimwikiPre
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" syntax group highlighting
|
2019-05-24 05:23:53 +02:00
|
|
|
hi def link VimwikiImage VimwikiLink
|
|
|
|
hi def link VimwikiImageT VimwikiLink
|
2012-06-07 02:00:00 +02:00
|
|
|
hi def link VimwikiWeblink1 VimwikiLink
|
|
|
|
hi def link VimwikiWeblink1T VimwikiLink
|
|
|
|
|
|
|
|
hi def link VimwikiWikiLink1 VimwikiLink
|
|
|
|
hi def link VimwikiWikiLink1T VimwikiLink
|
|
|
|
|