Refactor: Syntax as region (code, eq, sub, sup, strike) => Fix (Issue #709)

More syntax pattern are defined as regions => Faster, enable nesting
This commit is contained in:
Tinmarino 2020-08-03 18:45:46 -04:00
parent fb178f8e3c
commit 94a78859d7
10 changed files with 395 additions and 249 deletions

View File

@ -40,6 +40,22 @@ let rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\%([[:punct:]]\|\s\|$\)\@='
" text: $ equation_inline $
let s:rxEqIn = '\$[^$`]\+\$'
" text: `code`
let s:rxCode = '`[^`]\+`'
" text: ~~deleted text~~
let s:rxDelText = '\~\~[^~`]\+\~\~'
" text: ^superscript^
let s:rxSuperScript = '\^[^^`]\+\^'
" text: ,,subscript,,
let s:rxSubScript = ',,[^,`]\+,,'
function! s:root_path(subdir) abort
return repeat('../', len(split(a:subdir, '[/\\]')))
endfunction
@ -598,12 +614,12 @@ function! s:make_tag(line, regexp, func, ...) abort
\ '\(<a href.\{-}</a>\)\|'.
\ '\(<img src.\{-}/>\)\|'.
\ '\(<pre.\{-}</pre>\)\|'.
\ '\('.vimwiki#vars#get_syntaxlocal('rxEqIn').'\)'
\ '\('.s:rxEqIn.'\)'
"FIXME FIXME !!! these can easily occur on the same line!
"XXX {{{ }}} ??? obsolete
if '`[^`]\+`' ==# a:regexp || '{{{.\+}}}' ==# a:regexp ||
\ vimwiki#vars#get_syntaxlocal('rxEqIn') ==# a:regexp
\ s:rxEqIn ==# a:regexp
let res_line = s:subst_func(a:line, a:regexp, a:func)
else
let pos = 0
@ -643,11 +659,11 @@ function! s:process_tags_typefaces(line, header_ids) abort
let line = s:make_tag(line, s:rxItalic, 's:tag_em')
let line = s:make_tag(line, s:rxBold, 's:tag_strong', a:header_ids)
let line = s:make_tag(line, vimwiki#vars#get_global('rxTodo'), 's:tag_todo')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxDelText'), 's:tag_strike')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSuperScript'), 's:tag_super')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSubScript'), 's:tag_sub')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxCode'), 's:tag_code')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxEqIn'), 's:tag_eqin')
let line = s:make_tag(line, s:rxDelText, 's:tag_strike')
let line = s:make_tag(line, s:rxSuperScript, 's:tag_super')
let line = s:make_tag(line, s:rxSubScript, 's:tag_sub')
let line = s:make_tag(line, s:rxCode, 's:tag_code')
let line = s:make_tag(line, s:rxEqIn, 's:tag_eqin')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxTags'), 's:tag_tags', a:header_ids)
return line
endfunction

View File

@ -218,24 +218,44 @@ function! vimwiki#u#ft_is_vw() abort
endif
endfunction
" Helper: Expand regex from reduced typeface delimiters
" :param: list<list,delimiters>> with reduced regex
" Return: list with extended regex delimiters (not inside a word)
" -- [['\*_', '_\*']] -> [['\S\@<=\*_\|\*_\S\@=', '\S\@<=_\*\|_\*\S\@=']]
function! vimwiki#u#hi_expand_regex(lst) abort
let res = []
function! s:expand_regex(rx) abort
return '\S\@<=' .a:rx . '\|' . a:rx . '\S\@='
endfunction
for delimiters in a:lst
call add(res, [s:expand_regex(delimiters[0]), s:expand_regex(delimiters[1])])
endfor
return res
endfunction
" Helper: Create highlight region between two tags
" :param: tag <string> example '<b>'
" :param: syntax_group <string> example: VimwikiBold
" :param: contains <string> coma separated and prefixed, default VimwikiHTMLTag
" :param: (1) <boolean> is contained
" :param: (2) <string> more param ex:oneline
function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort
let opt_is_contained = a:0 > 0 ? 'contained ' : ''
let opt_is_contained = a:0 > 0 && a:1 > 0 ? 'contained ' : ''
let opt_more = a:0 > 1 ? ' ' . a:2 : ''
let opt_contains = ''
if a:contains !=# ''
let opt_contains = 'contains=' . a:contains . ' '
endif
let cmd = 'syn region ' . a:syntax_group . ' matchgroup=VimwikiHTMLDelimiter ' .
let cmd = 'syn region ' . a:syntax_group . ' matchgroup=VimwikiDelimiter ' .
\ opt_is_contained .
\ 'start="' . a:tag_pre . '" ' .
\ 'end="' . a:tag_post . '" ' .
\ 'keepend ' .
\ opt_contains .
\ b:vimwiki_syntax_concealends
\ b:vimwiki_syntax_concealends .
\ opt_more
"echom cmd
exe cmd
endfunction
@ -247,50 +267,89 @@ endfunction
" -- see here for underline not defined: https://stackoverflow.com/questions/3003476
function! vimwiki#u#hi_typeface(dic) abort
" Italic must go before, otherwise single * takes precedence over ** and ** is considered as
" a void italic.
" Note that the last syntax defined take precedence so that user can change at runtime
" (:h :syn-define)
" -- a void italic.
" Note:
" -- The last syntax defined take precedence so that user can change at runtime (:h :syn-define)
" -- Some cases are contained by default:
" -- -- ex: VimwikiCodeBoldUnderline is not defined in colorschemes -> VimwikiCode
" -- -- see: #709 asking for concealing quotes in bold, so it must be higlighted differently
" -- -- -- for the user to understand what is concealed around
" Bold > Italic > Underline
" Declare nesting capabilities
" -- to be embeded in standard: bold, italic, underline
let nested = 'VimwikiCode,VimwikiEqIn,VimwikiDelText,VimwikiSuperScript,VimwikiSubScript'
" -- to be embeded in exetended (the one above)
let nested .= ',VimwikiBold,VimwikiItalic,VimwikiUmderline'
for i in a:dic['italic']
" -- Italic 1
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiItalic ', 'VimwikiItalicBold,VimwikiItalicUnderline')
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiItalic ', nested .',VimwikiItalicBold,VimwikiItalicUnderline')
" -- Bold 2
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiBoldItalic', 'VimwikiBoldItalicUnderline', 1)
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiBoldItalic', nested . ',VimwikiBoldItalicUnderline', 1)
" -- Bold 3
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiBoldUnderlineItalic', '', 2)
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiBoldUnderlineItalic', nested, 2)
" -- Underline 2
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineItalic', 'VimwikiUnderlineItalicBold', 1)
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineItalic', nested . ',VimwikiUnderlineItalicBold', 1)
" -- Underline 3
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineBoldItalic', '', 2)
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineBoldItalic', nested, 2)
endfor
for b in a:dic['bold']
" -- Bold 1
call vimwiki#u#hi_tag(b[0],b[1], 'VimwikiBold', 'VimwikiBoldUnderline,VimwikiBoldItalic')
call vimwiki#u#hi_tag(b[0],b[1], 'VimwikiBold', nested . ',VimwikiBoldUnderline,VimwikiBoldItalic')
" -- Italic 2
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiItalicBold', 'VimwikiItalicBoldUnderline', 1)
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiItalicBold', nested . ',VimwikiItalicBoldUnderline', 1)
" -- Italic 3
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiItalicUnderlineBold', '', 2)
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiItalicUnderlineBold', nested, 2)
" -- Underline 2
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineBold', 'VimwikiUnderlineBoldItalic', 1)
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineBold', nested . ',VimwikiUnderlineBoldItalic', 1)
" -- Underline 3
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineItalicBold', '', 2)
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineItalicBold', nested, 2)
endfor
" markdown
if has_key(a:dic, 'bold_italic')
for bi in a:dic['bold_italic']
call vimwiki#u#hi_tag(bi[0], bi[1], 'VimwikiBoldItalic', 'VimwikiBoldItalicUnderline')
call vimwiki#u#hi_tag(bi[0], bi[1], 'VimwikiBoldItalic', nested . ',VimwikiBoldItalicUnderline')
endfor
endif
for u in a:dic['underline']
" -- Underline 1
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiUnderline', 'VimwikiUnderlineBold,VimwikiUnderlineItalic')
" -- Bold 2
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiBoldUnderline', 'VimwikiBoldUnderlineItalic', 1)
" -- Bold 3
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiBoldItalicUnderline', '', 2)
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiUnderline', nested . ',VimwikiUnderlineBold,VimwikiUnderlineItalic')
" -- Italic 2
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicUnderline', 'VimwikiItalicUnderlineBold', 1)
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicUnderline', nested . ',VimwikiItalicUnderlineBold', 1)
" -- Italic 3
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicBoldUnderline', '', 2)
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiBoldItalicUnderline', nested, 2)
" -- Underline 2
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiBoldUnderline', nested . ',VimwikiBoldUnderlineItalic', 1)
" -- Underline 3
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicBoldUnderline', nested, 2)
endfor
"" Code do not contain anything but can be contained very nested
for u in a:dic['code']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiCode', '')
endfor
" Deleted
for u in a:dic['del']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiDelText', nested)
endfor
"" Equation
for u in a:dic['eq']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiEqIn', nested)
endfor
" Superscript
for u in a:dic['sup']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiSuperScript', nested, 0, 'oneline')
endfor
" Subscript
for u in a:dic['sub']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiSubScript', nested, 0, 'oneline')
endfor
" Prevent var_with_underscore to trigger italic text

View File

@ -582,6 +582,7 @@ endfunction
" Populate syntax variable
" Exported: syntax/vimwiki.vim
" TODO refactor <= too big function
function! vimwiki#vars#populate_syntax_vars(syntax) abort
" Create is not exists
if !exists('g:vimwiki_syntax_variables')
@ -600,6 +601,35 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort
" Autoload default syntax file
execute 'runtime! syntax/vimwiki_'.a:syntax.'.vim'
" text: `code` or ``code`` only inline
" Note: `\%(^\|[^`]\)\@<=` means after a new line or a non `
let syntax_dic.dTypeface['code'] = [
\ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=',
\ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='],
\ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=',
\ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='],
\ ]
" text: ~~deleted text~~
let syntax_dic.dTypeface['del'] = ([
\ ['\~\~', '\~\~']])
" text: $ equation_inline $
" Match only one $
" ( ^ or not $) before $ and after: not $
let syntax_dic.dTypeface['eq'] = ([
\ ['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=',
\ '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']])
" text: ^superscript^
let syntax_dic.dTypeface['sup'] = ([
\ ['\^', '\^']])
" text: ,,subscript,,
let syntax_dic.dTypeface['sub'] = ([
\ [',,', ',,']])
" TODO make that clean (i.e clearify what is local to syntax ot to buffer)
" Get from local vars
let bullet_types = vimwiki#vars#get_wikilocal('bullet_types')

View File

@ -3742,6 +3742,8 @@ Changed:~
Removed:~
Fixed:~
* Issue #709: Support inline code spans inside emphasis
Refactoring code, del, eq, sup, sub as regions
* Issue #847 #640: Refactor: Syntax highlighting typeface: match -> region
* Issue #891: Fix: Table Pressing <Enter> autosets tw <- 0
* Issue #894: Make all appropriate settings wikilocal (many commits)

View File

@ -18,6 +18,8 @@ let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : ''
let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
" Populate all syntax vars
" Include syntax/vimwiki_markdown.vim as "side effect"
call vimwiki#vars#populate_syntax_vars(s:current_syntax)
@ -159,20 +161,6 @@ endfor
if vimwiki#vars#get_global('conceal_onechar_markers')
execute 'syn match VimwikiEqInChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_eqin').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiCodeChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_code').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiDelTextChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_deltext').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiSuperScript contained /'.
\ vimwiki#vars#get_syntaxlocal('char_superscript').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiSubScript contained /'.
\ vimwiki#vars#get_syntaxlocal('char_subscript').'/'.b:vimwiki_syntax_conceal
endif
let s:options = ' contained transparent contains=NONE'
if exists('+conceallevel')
let s:options .= b:vimwiki_syntax_conceal
@ -205,16 +193,6 @@ execute 'syn match VimwikiLinkChar /'.vimwiki#vars#get_global('rxWikiInclSuffix1
execute 'syn match VimwikiHeaderChar contained /\%(^\s*'.
\ vimwiki#vars#get_syntaxlocal('rxH').'\+\)\|\%('.vimwiki#vars#get_syntaxlocal('rxH').
\ '\+\s*$\)/'
execute 'syn match VimwikiEqInCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_eqin').'/'
execute 'syn match VimwikiCodeCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_code').'/'
execute 'syn match VimwikiDelTextCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_deltext').'/'
execute 'syn match VimwikiSuperScriptT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_superscript').'/'
execute 'syn match VimwikiSubScriptT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_subscript').'/'
execute 'syntax match VimwikiTodo /'. vimwiki#vars#get_global('rxTodo') .'/'
@ -237,6 +215,7 @@ syntax match VimwikiTableRow /^\s*|.\+|\s*$/
\ VimwikiCodeT,
\ VimwikiEqInT,
\ @Spell
syntax match VimwikiCellSeparator
\ /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained
@ -258,32 +237,6 @@ elseif vimwiki#vars#get_global('hl_cb_checked') == 2
endif
execute 'syntax match VimwikiEqIn /'.vimwiki#vars#get_syntaxlocal('rxEqIn').
\ '/ contains=VimwikiEqInChar,@NoSpell'
execute 'syntax match VimwikiEqInT /'.vimwiki#vars#get_syntaxlocal('rxEqIn').
\ '/ contained contains=VimwikiEqInCharT,@NoSpell'
execute 'syntax match VimwikiDelText /'.vimwiki#vars#get_syntaxlocal('rxDelText').
\ '/ contains=VimwikiDelTextChar,@Spell'
execute 'syntax match VimwikiDelTextT /'.vimwiki#vars#get_syntaxlocal('rxDelText').
\ '/ contained contains=VimwikiDelTextCharT,@Spell'
execute 'syntax match VimwikiSuperScript /'.vimwiki#vars#get_syntaxlocal('rxSuperScript').
\ '/ contains=VimwikiSuperScriptChar,@Spell'
execute 'syntax match VimwikiSuperScriptT /'.vimwiki#vars#get_syntaxlocal('rxSuperScript').
\ '/ contained contains=VimwikiSuperScriptCharT,@Spell'
execute 'syntax match VimwikiSubScript /'.vimwiki#vars#get_syntaxlocal('rxSubScript').
\ '/ contains=VimwikiSubScriptChar,@Spell'
execute 'syntax match VimwikiSubScriptT /'.vimwiki#vars#get_syntaxlocal('rxSubScript').
\ '/ contained contains=VimwikiSubScriptCharT,@Spell'
execute 'syntax match VimwikiCode /'.vimwiki#vars#get_syntaxlocal('rxCode').
\ '/ contains=VimwikiCodeChar,@NoSpell'
execute 'syntax match VimwikiCodeT /'.vimwiki#vars#get_syntaxlocal('rxCode').
\ '/ contained contains=VimwikiCodeCharT'
" <hr> horizontal rule
execute 'syntax match VimwikiHR /'.vimwiki#vars#get_syntaxlocal('rxHR').'/'
@ -308,7 +261,7 @@ syntax match VimwikiPlaceholderParam /.*/ contained
" html tags
if vimwiki#vars#get_global('valid_html_tags') !=? ''
" Source html file here
" Include: Source html file here
execute 'source ' . expand('<sfile>:h') . '/vimwiki_html.vim'
endif
@ -334,9 +287,11 @@ else
endfor
endif
" Highlight typefaces -> u.vim
let s:syntax_dic = vimwiki#vars#get_syntaxlocal('dTypeface')
call vimwiki#u#hi_typeface(s:syntax_dic)
" Highlight Typefaces -> u.vim
let s:typeface_dic = vimwiki#vars#get_syntaxlocal('dTypeface')
call vimwiki#u#hi_typeface(s:typeface_dic)
hi def link VimwikiMarkers Normal
hi def link VimwikiError Normal
@ -377,6 +332,7 @@ hi def link VimwikiUnderlineItalicBold VimwikiBoldItalicUnderline
" Typeface 2
hi def VimwikiBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
" Code
hi def link VimwikiCode PreProc
hi def link VimwikiCodeT VimwikiCode
@ -399,7 +355,14 @@ hi def link VimwikiCheckBoxDone Comment
hi def link VimwikiHR Identifier
hi def link VimwikiTag Keyword
hi def link VimwikiDelText Constant
" Deleted called strikethrough
" See $VIMRUTIME/syntax/html.vim
if v:version > 800 || v:version == 800 && has('patch1038')
hi def VimwikiDelText term=strikethrough cterm=strikethrough gui=strikethrough
else
hi def link VimwikiDelText Constant
endif
hi def link VimwikiDelTextT VimwikiDelText
hi def link VimwikiSuperScript Number
@ -428,6 +391,7 @@ hi def link VimwikiSubScriptChar VimwikiMarkers
hi def link VimwikiCodeChar VimwikiMarkers
hi def link VimwikiHeaderChar VimwikiMarkers
" TODO remove unsued due to region refactoring
hi def link VimwikiEqInCharT VimwikiMarkers
hi def link VimwikiBoldCharT VimwikiMarkers
hi def link VimwikiItalicCharT VimwikiMarkers
@ -450,7 +414,7 @@ call vimwiki#u#reload_regexes_custom()
let b:current_syntax='vimwiki'
" Code: EMBEDDED syntax setup
" Include: Code: EMBEDDED syntax setup -> base.vim
let s:nested = vimwiki#vars#get_wikilocal('nested_syntaxes')
if vimwiki#vars#get_wikilocal('automatic_nested_syntaxes')
let s:nested = extend(s:nested, vimwiki#base#detect_nested_syntax(), 'keep')

View File

@ -37,27 +37,6 @@ let s:default_syntax.dTypeface['bold_italic'] = [
\ ['\S\@<=_\*\|_\*\S\@=', '\S\@<=\*_\|\*_\S\@='],
\ ]
" text: $ equation_inline $
let s:default_syntax.rxEqIn = '\$[^$`]\+\$'
let s:default_syntax.char_eqin = '\$'
" text: `code`
let s:default_syntax.rxCode = '`[^`]\+`'
let s:default_syntax.char_code = '`'
" text: ~~deleted text~~
let s:default_syntax.rxDelText = '\~\~[^~`]\+\~\~'
let s:default_syntax.char_deltext = '\~\~'
" text: ^superscript^
let s:default_syntax.rxSuperScript = '\^[^^`]\+\^'
let s:default_syntax.char_superscript = '^'
" text: ,,subscript,,
let s:default_syntax.rxSubScript = ',,[^,`]\+,,'
let s:default_syntax.char_subscript = ',,'
" generic headers
let s:default_syntax.rxH = '='
let s:default_syntax.symH = 1

View File

@ -17,6 +17,11 @@ let html_typeface = {
\ 'bold': [['<b>', '</b\_s*>'], ['<strong>', '</strong\_s*>']],
\ 'italic': [['<i>', '</i\_s*>'], ['<em>', '</em\_s*>']],
\ 'underline': [['<u>', '</u\_s*>']],
\ 'code': [['<code>', '</code\_s*>']],
\ 'del': [['<del>', '</del\_s*>']],
\ 'eq': [],
\ 'sup': [['<sup>', '</sup\_s*>']],
\ 'sub': [['<sub>', '</sub\_s*>']],
\ }
call vimwiki#u#hi_typeface(html_typeface)

View File

@ -1,11 +1,9 @@
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki syntax file
" Description: Defines markdown syntax
" Home: https://github.com/vimwiki/vimwiki/
" see the comments in vimwiki_default.vim for some info about this file
" Description: Defines markdown syntax
" Called: vars.vim => Many other (common) variables are defined there
" More in u.vim, base.vim (nested_syntax for multiline code)
let s:markdown_syntax = g:vimwiki_syntax_variables['markdown']
@ -20,47 +18,20 @@ let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
let s:markdown_syntax.dTypeface = {}
" text: **bold** or __bold__
let s:markdown_syntax.dTypeface['bold'] = [
\ ['\S\@<=__\|__\S\@=', '\S\@<=__\|__\S\@='],
\ ['\S\@<=\*\*\|\*\*\S\@=', '\S\@<=\*\*\|\*\*\S\@='],
\ ]
let s:markdown_syntax.dTypeface['bold'] = vimwiki#u#hi_expand_regex([
\ ['__', '__'], ['\*\*', '\*\*']])
" text: *italic* or _italic_
let s:markdown_syntax.dTypeface['italic'] = [
\ ['\S\@<=\*\|\*\S\@=', '\S\@<=\*\|\*\S\@='],
\ ['\S\@<=_\|_\S\@=', '\S\@<=_\|_\S\@='],
\ ]
let s:markdown_syntax.dTypeface['italic'] = vimwiki#u#hi_expand_regex([
\ ['\*', '\*'], ['_', '_']])
" text: no underline defined
let s:markdown_syntax.dTypeface['underline'] = []
" text: *_bold italic_* or _*italic bold*_ or ___bi___ or ***bi***
let s:markdown_syntax.dTypeface['bold_italic'] = [
\ ['\S\@<=\*_\|\*_\S\@=', '\S\@<=_\*\|_\*\S\@='],
\ ['\S\@<=_\*\|_\*\S\@=', '\S\@<=\*_\|\*_\S\@='],
\ ['\S\@<=\*\*\*\|\*\*\*\S\@=', '\S\@<=\*\*\*\|\*\*\*\S\@='],
\ ['\S\@<=___\|___\S\@=', '\S\@<=___\|___\S\@='],
\ ]
let s:markdown_syntax.dTypeface['bold_italic'] = vimwiki#u#hi_expand_regex([
\ ['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']])
" text: $ equation_inline $
let s:markdown_syntax.rxEqIn = '\$[^$`]\+\$'
let s:markdown_syntax.char_eqin = '\$'
" text: `code`
let s:markdown_syntax.rxCode = '`[^`]\+`'
let s:markdown_syntax.char_code = '`'
" text: ~~deleted text~~
let s:markdown_syntax.rxDelText = '\~\~[^~`]\+\~\~'
let s:markdown_syntax.char_deltext = '\~\~'
" text: ^superscript^
let s:markdown_syntax.rxSuperScript = '\^[^^`]\+\^'
let s:markdown_syntax.char_superscript = '^'
" text: ,,subscript,,
let s:markdown_syntax.rxSubScript = ',,[^,`]\+,,'
let s:markdown_syntax.char_subscript = ',,'
" generic headers
let s:markdown_syntax.rxH = '#'

View File

@ -30,26 +30,6 @@ let s:media_syntax.dTypeface['bold_italic'] = [
\ ]
" text: $ equation_inline $
let s:media_syntax.rxEqIn = '\$[^$`]\+\$'
let s:media_syntax.char_eqin = '\$'
" text: `code`
let s:media_syntax.rxCode = '`[^`]\+`'
let s:media_syntax.char_code = '`'
" text: ~~deleted text~~
let s:media_syntax.rxDelText = '\~\~[^~]\+\~\~'
let s:media_syntax.char_deltext = '\~\~'
" text: ^superscript^
let s:media_syntax.rxSuperScript = '\^[^^]\+\^'
let s:media_syntax.char_superscript = '^'
" text: ,,subscript,,
let s:media_syntax.rxSubScript = ',,[^,]\+,,'
let s:media_syntax.char_subscript = ',,'
" generic headers
let s:media_syntax.rxH = '='
let s:media_syntax.symH = 1

View File

@ -4,9 +4,149 @@
# 1 Typeface {{{1
#################
# Extended types {{{2
Given vimwiki (Extended Types mono):
`code `
~~ strike ~~
$ equation $
^superscript ^
,, subscript ,,
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types mono):
AssertEqual 'VimwikiCode' , SyntaxAt(1, 8)
AssertEqual 'VimwikiDelText' , SyntaxAt(2, 8)
AssertEqual 'VimwikiEqIn' , SyntaxAt(3, 8)
AssertEqual 'VimwikiSuperScript' , SyntaxAt(4, 8)
AssertEqual 'VimwikiSubScript' , SyntaxAt(5, 8)
Given vimwiki (Extended Types nested in basic):
From __bold `code in bold ` end of bold__ morF
From _it and ~~ strieout in i~~ end of it_ morF
From __bold $ equation $ end bold __
**bold ^superscript ^ end of bold morF**
From normal ,, subscript ,, still normal morF
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types mono):
AssertEqual 'VimwikiCode' , SyntaxAt(1, 23)
AssertEqual 'VimwikiDelText' , SyntaxAt(2, 23)
AssertEqual 'VimwikiEqIn' , SyntaxAt(3, 23)
AssertEqual 'VimwikiSuperScript' , SyntaxAt(4, 23)
AssertEqual 'VimwikiSubScript' , SyntaxAt(5, 23)
Given vimwiki (Extended Types nested in extended):
From ^super to`code this ` is crazy but^ morF
From ,,sub to~~ strike ~~why not,, morF
From ~~strike $ equation $ end of strike~~morF
From $eq to ^super ^ Just inline morF$
From ^super t,,sub ,, end super eol ^
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types nested in extended):
AssertEqual 'VimwikiCode' , SyntaxAt(1, 23)
AssertEqual 'VimwikiDelText' , SyntaxAt(2, 23)
AssertEqual 'VimwikiEqIn' , SyntaxAt(3, 23)
AssertEqual 'VimwikiSuperScript' , SyntaxAt(4, 23)
AssertEqual 'VimwikiSubScript' , SyntaxAt(5, 23)
Given vimwiki (Basic Types nested in extended):
From ^super t__bold __ is crazy but^ morF
From ,,sub to _italic with en_ aaaaaaa,, morF
From $eq to **boldboldboldbo** aaaaaaaaa $
From ^super t *italic aaaaaaa*aaaaaaaaaaaaaaaaaaaaa
From ~~strike__ bbbbbbbbbbbbb__ssssssssssssssssss~~
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types nested in extended):
AssertEqual 'VimwikiBold' , SyntaxAt(1, 23)
AssertEqual 'VimwikiItalic' , SyntaxAt(2, 23)
AssertEqual 'VimwikiBold' , SyntaxAt(3, 23)
AssertEqual 'VimwikiItalic' , SyntaxAt(4, 23)
AssertEqual 'VimwikiBold' , SyntaxAt(5, 23)
Given vimwiki (Try to nest in code):
From `codeto__no onenest in code__ end`
From `codeto _no onenest in code_ end`
From `codeto ^no onenest in code^ end`
From `codeto ~~no onenest in code~~ end`
From `codeto ___no onenest in code___ end`
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types nested in extended):
AssertEqual 'VimwikiCode' , SyntaxAt(1, 23)
AssertEqual 'VimwikiCode' , SyntaxAt(2, 23)
AssertEqual 'VimwikiCode' , SyntaxAt(3, 23)
AssertEqual 'VimwikiCode' , SyntaxAt(4, 23)
AssertEqual 'VimwikiCode' , SyntaxAt(5, 23)
Given vimwiki (Multiline Typfaces Basic and extended):
__and bold
multiline__
_and it
mutliline_
~~and mutltie
strikeout~~
`
and mutli
path
`
and $ multi
equation
$
^ but no multi
sup ^
,,
but no multi
sub ,,
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Multiline syantax but not sup and sub):
AssertEqual 'VimwikiBold' , SyntaxAt(2, 1)
AssertEqual 'VimwikiItalic' , SyntaxAt(5, 1)
AssertEqual 'VimwikiDelText' , SyntaxAt(8, 1)
AssertEqual 'VimwikiCode' , SyntaxAt(11, 1)
AssertEqual 'VimwikiEqIn' , SyntaxAt(14, 1)
AssertEqual '' , SyntaxAt(17, 1)
AssertEqual '' , SyntaxAt(20, 1)
# HTML types {{{2
# Rememner Bold > Italic > Underline (my convention [Tinmarino])
Given vimwiki (Typeface for Italic var_with_underscore):
var_with_underscore
_this is
italic_
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax for typeface 1):
AssertEqual '' , SyntaxAt(1, 1)
AssertEqual 'VimwikiError' , SyntaxAt(1, 4)
AssertEqual '' , SyntaxAt(1, 5)
AssertEqual 'VimwikiItalic' , SyntaxAt(2, 2)
AssertEqual 'VimwikiItalic' , SyntaxAt(3, 2)
Given vimwiki (Typeface for html 1 like italic):
<b> ---- this is bold text 1 ---- </b>
<strong> - this is bold 2 - </strong>
@ -92,16 +232,16 @@ Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax for typeface):
AssertEqual 'VimwikiBold' , SyntaxAt(1, 4)
AssertEqual 'VimwikiBold' , SyntaxAt(2, 4)
AssertEqual 'VimwikiItalic' , SyntaxAt(3, 4)
AssertEqual 'VimwikiItalic' , SyntaxAt(4, 4)
AssertEqual 'VimwikiBoldItalic' , SyntaxAt(5, 4)
AssertEqual 'VimwikiBoldItalic' , SyntaxAt(6, 4)
AssertEqual 'VimwikiDelText' , SyntaxAt(7, 4)
AssertEqual 'VimwikiCode' , SyntaxAt(8, 4)
AssertEqual 'VimwikiSuperScript' , SyntaxAt(9, 4)
AssertEqual 'VimwikiSubScript' , SyntaxAt(10, 4)
AssertEqual 'VimwikiBold' , SyntaxAt(1, 5)
AssertEqual 'VimwikiBold' , SyntaxAt(2, 5)
AssertEqual 'VimwikiItalic' , SyntaxAt(3, 5)
AssertEqual 'VimwikiItalic' , SyntaxAt(4, 5)
AssertEqual 'VimwikiBoldItalic' , SyntaxAt(5, 5)
AssertEqual 'VimwikiBoldItalic' , SyntaxAt(6, 5)
AssertEqual 'VimwikiDelText' , SyntaxAt(7, 5)
AssertEqual 'VimwikiCode' , SyntaxAt(8, 5)
AssertEqual 'VimwikiSuperScript' , SyntaxAt(9, 5)
AssertEqual 'VimwikiSubScript' , SyntaxAt(10, 5)
# 2 Links {{{1
@ -146,24 +286,24 @@ Given vimwiki (Wiki Links):
[[http://someaddr.com/bigpicture.jpg|{{http://someaddr.com/thumbnail.jpg}}]]
Execute (Assert Syntax link):
AssertEqual SyntaxAt(2, 6), 'VimwikiLink'
AssertEqual SyntaxAt(4, 6), 'VimwikiLink'
AssertEqual SyntaxAt(6, 6), 'VimwikiLink'
AssertEqual SyntaxAt(8, 6), 'VimwikiLink'
AssertEqual SyntaxAt(10, 6), 'VimwikiLink'
AssertEqual SyntaxAt(12, 6), 'VimwikiLink'
AssertEqual SyntaxAt(14, 6), 'VimwikiLink'
AssertEqual SyntaxAt(16, 6), 'VimwikiLink'
AssertEqual SyntaxAt(18, 6), 'VimwikiLink'
AssertEqual SyntaxAt(20, 6), 'VimwikiLink'
AssertEqual SyntaxAt(22, 6), 'VimwikiLink'
AssertEqual SyntaxAt(24, 6), 'VimwikiLink'
AssertEqual SyntaxAt(26, 6), 'VimwikiLink'
AssertEqual SyntaxAt(28, 6), 'VimwikiLink'
AssertEqual SyntaxAt(30, 6), 'VimwikiLink'
AssertEqual SyntaxAt(32, 6), 'VimwikiLink'
AssertEqual SyntaxAt(34, 6), 'VimwikiLink'
AssertEqual SyntaxAt(36, 6), 'VimwikiLink'
AssertEqual 'VimwikiLink', SyntaxAt(2, 6)
AssertEqual 'VimwikiLink', SyntaxAt(4, 6)
AssertEqual 'VimwikiLink', SyntaxAt(6, 6)
AssertEqual 'VimwikiLink', SyntaxAt(8, 6)
AssertEqual 'VimwikiLink', SyntaxAt(10, 6)
AssertEqual 'VimwikiLink', SyntaxAt(12, 6)
AssertEqual 'VimwikiLink', SyntaxAt(14, 6)
AssertEqual 'VimwikiLink', SyntaxAt(16, 6)
AssertEqual 'VimwikiLink', SyntaxAt(18, 6)
AssertEqual 'VimwikiLink', SyntaxAt(20, 6)
AssertEqual 'VimwikiLink', SyntaxAt(22, 6)
AssertEqual 'VimwikiLink', SyntaxAt(24, 6)
AssertEqual 'VimwikiLink', SyntaxAt(26, 6)
AssertEqual 'VimwikiLink', SyntaxAt(28, 6)
AssertEqual 'VimwikiLink', SyntaxAt(30, 6)
AssertEqual 'VimwikiLink', SyntaxAt(32, 6)
AssertEqual 'VimwikiLink', SyntaxAt(34, 6)
AssertEqual 'VimwikiLink', SyntaxAt(36, 6)
Given vimwiki (Markdown Links):
Inline link: >
@ -180,10 +320,10 @@ Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax link):
AssertEqual SyntaxAt(2, 8), 'VimwikiWeblink1'
AssertEqual SyntaxAt(5, 8), 'VimwikiImage'
AssertEqual SyntaxAt(8, 8), 'VimwikiWikiLink1'
AssertEqual SyntaxAt(9, 8), 'VimwikiWikiLink1'
AssertEqual 'VimwikiWeblink1' , SyntaxAt(2, 8)
AssertEqual 'VimwikiImage' , SyntaxAt(5, 8)
AssertEqual 'VimwikiWikiLink1' , SyntaxAt(8, 8)
AssertEqual 'VimwikiWikiLink1' , SyntaxAt(9, 8)
# 3 Header {{{1
@ -201,12 +341,12 @@ Execute (Set syntax default):
call SetSyntax('default')
Execute (Assert Syntax Header):
AssertEqual SyntaxAt(1, 10), 'VimwikiHeader1'
AssertEqual SyntaxAt(2, 10), 'VimwikiHeader2'
AssertEqual SyntaxAt(3, 10), 'VimwikiHeader3'
AssertEqual SyntaxAt(4, 10), 'VimwikiHeader4'
AssertEqual SyntaxAt(5, 10), 'VimwikiHeader5'
AssertEqual SyntaxAt(6, 10), 'VimwikiHeader6'
AssertEqual 'VimwikiHeader1', SyntaxAt(1, 10)
AssertEqual 'VimwikiHeader2', SyntaxAt(2, 10)
AssertEqual 'VimwikiHeader3', SyntaxAt(3, 10)
AssertEqual 'VimwikiHeader4', SyntaxAt(4, 10)
AssertEqual 'VimwikiHeader5', SyntaxAt(5, 10)
AssertEqual 'VimwikiHeader6', SyntaxAt(6, 10)
Given vimwiki (Markdown Headers):
# Header level 1
@ -220,12 +360,12 @@ Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax Header):
AssertEqual SyntaxAt(1, 10), 'VimwikiHeader1'
AssertEqual SyntaxAt(2, 10), 'VimwikiHeader2'
AssertEqual SyntaxAt(3, 10), 'VimwikiHeader3'
AssertEqual SyntaxAt(4, 10), 'VimwikiHeader4'
AssertEqual SyntaxAt(5, 10), 'VimwikiHeader5'
AssertEqual SyntaxAt(6, 10), 'VimwikiHeader6'
AssertEqual 'VimwikiHeader1' , SyntaxAt(1, 10)
AssertEqual 'VimwikiHeader2' , SyntaxAt(2, 10)
AssertEqual 'VimwikiHeader3' , SyntaxAt(3, 10)
AssertEqual 'VimwikiHeader4' , SyntaxAt(4, 10)
AssertEqual 'VimwikiHeader5' , SyntaxAt(5, 10)
AssertEqual 'VimwikiHeader6' , SyntaxAt(6, 10)
# 10 Comments {{{1
###############
@ -238,8 +378,8 @@ Execute (Set syntax default):
call SetSyntax('default')
Execute (Assert Syntax VimwikiComment):
AssertEqual SyntaxAt(1, 1), 'VimwikiComment'
AssertEqual SyntaxAt(2, 4), 'VimwikiComment'
AssertEqual 'VimwikiComment' , SyntaxAt(1, 1)
AssertEqual 'VimwikiComment' , SyntaxAt(2, 4)
Given vimwiki (%%+, +%%):
%%+ This
@ -253,21 +393,21 @@ Execute (Set syntax default):
call SetSyntax('default')
Execute (Assert Syntax VimwikiMultilineComment):
AssertEqual SyntaxAt(1, 1), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(1, 8), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(2, 1), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(3, 1), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(4, 1), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(5, 1), 'VimwikiMultilineComment'
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(1, 1)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(1, 8)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(2, 1)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(3, 1)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(4, 1)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(5, 1)
AssertEqual SyntaxAt(6, 1), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(6, 11), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(6, 12), ''
AssertEqual SyntaxAt(6, 26), ''
AssertEqual SyntaxAt(6, 27), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(6, 37), 'VimwikiMultilineComment'
AssertEqual SyntaxAt(6, 38), ''
AssertEqual SyntaxAt(6, 51), ''
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(6, 1)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(6, 11)
AssertEqual '' , SyntaxAt(6, 12)
AssertEqual '' , SyntaxAt(6, 26)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(6, 27)
AssertEqual 'VimwikiMultilineComment' , SyntaxAt(6, 37)
AssertEqual '' , SyntaxAt(6, 38)
AssertEqual '' , SyntaxAt(6, 51)
# 10 Code {{{1
# 10.1 Code Indent (4 spaces) {{{2
@ -329,26 +469,26 @@ Execute (Set syntax markdown):
Execute (Assert ft, normal syntax and VimwikiTodo):
AssertEqual &ft, 'vimwiki'
AssertEqual SyntaxAt(1, 1), ''
AssertEqual SyntaxAt(2, 9), 'VimwikiTodo'
AssertEqual '', SyntaxAt(1, 1)
AssertEqual 'VimwikiTodo', SyntaxAt(2, 9)
Execute (Assert Code syntax):
AssertEqual SyntaxAt(4, 1), 'VimwikiPreDelim'
AssertEqual SyntaxAt(5, 1), 'VimwikiPre'
AssertEqual SyntaxAt(9, 1), 'vimLineComment'
AssertEqual SyntaxAt(10, 1), 'vimCommand'
AssertEqual SyntaxAt(13, 1), 'VimwikiPre'
AssertEqual SyntaxAt(14, 1), 'vimLineComment'
AssertEqual SyntaxAt(15, 1), 'vimCommand'
AssertEqual SyntaxAt(16, 1), 'VimwikiPre'
AssertEqual SyntaxAt(18, 1), 'VimwikiPre'
AssertEqual SyntaxAt(19, 1), 'vimLineComment'
AssertEqual SyntaxAt(20, 1), 'vimCommand'
AssertEqual SyntaxAt(21, 1), 'VimwikiPre'
AssertEqual SyntaxAt(23, 1), 'VimwikiPre'
AssertEqual SyntaxAt(24, 1), 'vimLineComment'
AssertEqual SyntaxAt(25, 1), 'vimCommand'
AssertEqual SyntaxAt(26, 1), 'VimwikiPre'
AssertEqual 'VimwikiPreDelim', SyntaxAt(4, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(5, 1)
AssertEqual 'vimLineComment' , SyntaxAt(9, 1)
AssertEqual 'vimCommand' , SyntaxAt(10, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(13, 1)
AssertEqual 'vimLineComment' , SyntaxAt(14, 1)
AssertEqual 'vimCommand' , SyntaxAt(15, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(16, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(18, 1)
AssertEqual 'vimLineComment' , SyntaxAt(19, 1)
AssertEqual 'vimCommand' , SyntaxAt(20, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(21, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(23, 1)
AssertEqual 'vimLineComment' , SyntaxAt(24, 1)
AssertEqual 'vimCommand' , SyntaxAt(25, 1)
AssertEqual 'VimwikiPre' , SyntaxAt(26, 1)
# 11 Math {{{1
@ -374,8 +514,8 @@ Given vimwiki (Math markdown):
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert math syntax):
AssertEqual SyntaxAt(1, 18), 'VimwikiEqIn'
Execute (Assert math syntax 1):
AssertEqual 'VimwikiEqIn', SyntaxAt(1, 18)
let syntax_5 = SyntaxAt(5, 1)
Assert syntax_5 == 'texStatement' || syntax_5 == 'texMathSymbol'
let syntax_12 = SyntaxAt(12, 1)
@ -404,8 +544,8 @@ Given vimwiki (Math wiki):
Execute (Set syntax default):
call SetSyntax('default')
Execute (Assert math syntax):
AssertEqual SyntaxAt(1, 18), 'VimwikiEqIn'
Execute (Assert math syntax 2):
AssertEqual 'VimwikiEqIn', SyntaxAt(1, 18)
let syntax_5 = SyntaxAt(5, 1)
Assert syntax_5 == 'texStatement' || syntax_5 == 'texMathSymbol'
let syntax_12 = SyntaxAt(12, 1)