Refactor: Syntax highlighting typeface: match -> region: (Issues #847, #640)

- Less code, Easyer to maintain, to add a markup language
- Faster to load, and to highlight
- Support multiline tags: #847
- Support nested tags
- Support intraword tags: this<b>bold</b>type #640
This commit is contained in:
Tinmarino 2020-08-02 03:51:25 -04:00
parent 5408d74b35
commit 1b16720b7b
9 changed files with 248 additions and 210 deletions

View File

@ -9,6 +9,36 @@ if exists('g:loaded_vimwiki_html_auto') || &compatible
endif
let g:loaded_vimwiki_html_auto = 1
" FIXME: Magics: Why not use the current syntax highlight
" This is due to historical copy paste and lazyness of markdown user
" text: **strong** or __strong__
let s:rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(\*\|_\)\{2\}'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\1\{2\}'.
\'\%([[:punct:]]\|\s\|$\)\@='
" text: _emphasis_ or *emphasis*
let s:rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(\*\|_\)'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\1'.
\'\%([[:punct:]]\|\s\|$\)\@='
" Fixme: and those ? are they converted ?
" text: *_bold italic_* or _*italic bold*_
let rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(\*\)\{3\}'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'.
\'\1\{3\}'.
\'\%([[:punct:]]\|\s\|$\)\@='
let rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(_\)\{3\}'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'.
\'\1\{3\}'.
\'\%([[:punct:]]\|\s\|$\)\@='
function! s:root_path(subdir) abort
return repeat('../', len(split(a:subdir, '[/\\]')))
@ -609,8 +639,9 @@ endfunction
function! s:process_tags_typefaces(line, header_ids) abort
let line = a:line
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxItalic'), 's:tag_em')
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxBold'), 's:tag_strong', a:header_ids)
" Convert line tag by tag
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')
@ -978,7 +1009,7 @@ function! s:process_tag_list(line, lists) abort
" text.
" XXX necessary? in *bold* text, no space must follow the first *
if !in_list
let pos = match(a:line, '^\s*'.vimwiki#vars#get_syntaxlocal('rxBold'))
let pos = match(a:line, '^\s*' . s:rxBold)
if pos != -1
return [0, []]
endif

View File

@ -215,3 +215,79 @@ function! vimwiki#u#ft_is_vw() abort
return 0
endif
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
function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort
let opt_is_contained = a:0 > 0 ? 'contained ' : ''
let opt_contains = ''
if a:contains !=# ''
let opt_contains = 'contains=' . a:contains . ' '
endif
let cmd = 'syn region ' . a:syntax_group . ' matchgroup=VimwikiHTMLDelimiter ' .
\ opt_is_contained .
\ 'start="' . a:tag_pre . '" ' .
\ 'end="' . a:tag_post . '" ' .
\ 'keepend ' .
\ opt_contains .
\ b:vimwiki_syntax_concealends
"echom cmd
exe cmd
endfunction
" Highight typeface: see $VIMRUNTIME/syntax/html.vim
" -- Basically allow nesting with multiple definition contained
" :param: dic <dic:list:list> must contain: bold, italic and underline, even if underline is often void,
" -- 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)
for i in a:dic['italic']
" -- Italic 1
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiItalic ', 'VimwikiItalicBold,VimwikiItalicUnderline')
" -- Bold 2
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiBoldItalic', 'VimwikiBoldItalicUnderline', 1)
" -- Bold 3
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiBoldUnderlineItalic', '', 2)
" -- Underline 2
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineItalic', 'VimwikiUnderlineItalicBold', 1)
" -- Underline 3
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineBoldItalic', '', 2)
endfor
for b in a:dic['bold']
" -- Bold 1
call vimwiki#u#hi_tag(b[0],b[1], 'VimwikiBold', 'VimwikiBoldUnderline,VimwikiBoldItalic')
" -- Italic 2
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiItalicBold', 'VimwikiItalicBoldUnderline', 1)
" -- Italic 3
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiItalicUnderlineBold', '', 2)
" -- Underline 2
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineBold', 'VimwikiUnderlineBoldItalic', 1)
" -- Underline 3
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineItalicBold', '', 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')
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)
" -- Italic 2
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicUnderline', 'VimwikiItalicUnderlineBold', 1)
" -- Italic 3
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicBoldUnderline', '', 2)
endfor
endfunction

View File

@ -2061,6 +2061,8 @@ conditionally, make sure the settings are set before Vimwiki loads (that is,
before plugin/vimwiki.vim is sourced). If this is not possible, try this
command after the Vimwiki settings are (re-) set: >
:call vimwiki#vars#init()
If you also want to reload syntax variables, prefix the last command by: >
:unlet g:vimwiki_syntax_variables
------------------------------------------------------------------------------
12.1 Registered Wiki *g:vimwiki_list* *vimwiki-register-wiki*

View File

@ -162,14 +162,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 VimwikiBoldChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_bold').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiItalicChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_italic').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiBoldItalicChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_bolditalic').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiItalicBoldChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_italicbold').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiCodeChar contained /'.
\ vimwiki#vars#get_syntaxlocal('char_code').'/'.b:vimwiki_syntax_conceal
execute 'syn match VimwikiDelTextChar contained /'.
@ -215,14 +207,6 @@ execute 'syn match VimwikiHeaderChar contained /\%(^\s*'.
\ '\+\s*$\)/'
execute 'syn match VimwikiEqInCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_eqin').'/'
execute 'syn match VimwikiBoldCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_bold').'/'
execute 'syn match VimwikiItalicCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_italic').'/'
execute 'syn match VimwikiBoldItalicCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_bolditalic').'/'
execute 'syn match VimwikiItalicBoldCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_italicbold').'/'
execute 'syn match VimwikiCodeCharT contained /'
\ .vimwiki#vars#get_syntaxlocal('char_code').'/'
execute 'syn match VimwikiDelTextCharT contained /'
@ -274,31 +258,11 @@ elseif vimwiki#vars#get_global('hl_cb_checked') == 2
endif
execute 'syntax match VimwikiBold /'.vimwiki#vars#get_syntaxlocal('rxBold').
\ '/ contains=VimwikiBoldChar,@Spell'
execute 'syntax match VimwikiBoldT /'.vimwiki#vars#get_syntaxlocal('rxBold').
\ '/ contained contains=VimwikiBoldCharT,@Spell'
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 VimwikiItalic /'.vimwiki#vars#get_syntaxlocal('rxItalic').
\ '/ contains=VimwikiItalicChar,@Spell'
execute 'syntax match VimwikiItalicT /'.vimwiki#vars#get_syntaxlocal('rxItalic').
\ '/ contained contains=VimwikiItalicCharT,@Spell'
execute 'syntax match VimwikiBoldItalic /'.vimwiki#vars#get_syntaxlocal('rxBoldItalic').
\ '/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell'
execute 'syntax match VimwikiBoldItalicT /'.vimwiki#vars#get_syntaxlocal('rxBoldItalic').
\ '/ contained contains=VimwikiBoldItalicChatT,VimwikiItalicBoldCharT,@Spell'
execute 'syntax match VimwikiItalicBold /'.vimwiki#vars#get_syntaxlocal('rxItalicBold').
\ '/ contains=VimwikiBoldItalicChar,VimwikiItalicBoldChar,@Spell'
execute 'syntax match VimwikiItalicBoldT /'.vimwiki#vars#get_syntaxlocal('rxItalicBold').
\ '/ contained contains=VimwikiBoldItalicCharT,VimsikiItalicBoldCharT,@Spell'
execute 'syntax match VimwikiDelText /'.vimwiki#vars#get_syntaxlocal('rxDelText').
\ '/ contains=VimwikiDelTextChar,@Spell'
execute 'syntax match VimwikiDelTextT /'.vimwiki#vars#get_syntaxlocal('rxDelText').
@ -343,91 +307,16 @@ syntax match VimwikiPlaceholderParam /.*/ contained
" html tags
" Copied from $VIMRUNTIME
" Note: The me=s-1 was omited from the region definition
" See: `syn region VimwikiBoldUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=VimwikiHTMLTag...`
" Note: Not configurable
if vimwiki#vars#get_global('valid_html_tags') !=? ''
let s:html_tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|')
exe 'syntax match VimwikiHTMLtag #\c</\?\%('.s:html_tags.'\)\%(\s\{-1}\S\{-}\)\{-}\s*/\?>#'
" Helper: Create highlight region between html 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
function! s:highlight_html(tag, syntax_group, contains, ...)
let opt_is_contained = a:0 > 0 ? 'contained ' : ''
let opt_contains = ''
if a:contains !=# ''
let opt_contains = 'contains=' . a:contains . ' '
endif
exe 'syn region ' a:syntax_group . ' matchgroup=VimwikiHTMLDelimiter ' .
\ opt_is_contained .
\ 'start="<' . a:tag . '>" end="</' . a:tag . '\_s*>" '.
\ opt_contains .
\ b:vimwiki_syntax_concealends
endfunction
" Bold
" -- Bold 1
call s:highlight_html('b', 'VimwikiBold', 'VimwikiBoldUnderline,VimwikiBoldItalic')
call s:highlight_html('strong', 'VimwikiBold', 'VimwikiBoldUnderline,VimwikiBoldItalic')
" -- Bold 2
call s:highlight_html('u', 'VimwikiBoldUnderline', 'VimwikiBoldUnderlineItalic', 1)
call s:highlight_html('i', 'VimwikiBoldItalic', 'VimwikiBoldItalicUnderline', 1)
call s:highlight_html('em', 'VimwikiBoldItalic', 'VimwikiBoldItalicUnderline', 1)
" -- Bold 3
call s:highlight_html('i', 'VimwikiBoldUnderlineItalic', '', 2)
call s:highlight_html('em', 'VimwikiBoldUnderlineItalic', '', 2)
call s:highlight_html('u', 'VimwikiBoldItalicUnderline', '', 2)
" Italic
" -- Italic 1
call s:highlight_html('i', 'VimwikiItalic ', 'VimwikiItalicBold,VimwikiItalicUnderline')
call s:highlight_html('em', 'VimwikiItalic ', 'VimwikiItalicBold,VimwikiItalicUnderline')
" -- Italic 2
call s:highlight_html('b', 'VimwikiItalicBold', 'VimwikiItalicBoldUnderline', 1)
call s:highlight_html('strong', 'VimwikiItalicBold', 'VimwikiItalicBoldUnderline', 1)
call s:highlight_html('u', 'VimwikiItalicUnderline', 'VimwikiItalicUnderlineBold', 1)
" -- Italic 3
call s:highlight_html('u', 'VimwikiItalicBoldUnderline', '', 2)
call s:highlight_html('b', 'VimwikiItalicUnderlineBold', '', 2)
call s:highlight_html('strong', 'VimwikiItalicUnderlineBold', '', 2)
" Underline
" -- Underline 1
call s:highlight_html('u', 'VimwikiUnderline', 'VimwikiUnderlineBold,VimwikiUnderlineItalic')
" -- Underline 2
call s:highlight_html('b', 'VimwikiUnderlineBold', 'VimwikiUnderlineBoldItalic', 1)
call s:highlight_html('b','VimwikiUnderlineBold', 'VimwikiUnderlineBoldItalic', 1)
call s:highlight_html('strong', 'VimwikiUnderlineBold', 'VimwikiUnderlineBoldItalic', 1)
call s:highlight_html('i', 'VimwikiUnderlineItalic', 'VimwikiUnderlineItalicBold', 1)
call s:highlight_html('em', 'VimwikiUnderlineItalic', 'VimwikiUnderlineItalicBold', 1)
" -- Underline 3
call s:highlight_html('b', 'VimwikiUnderlineItalicBold', '', 2)
call s:highlight_html('strong', 'VimwikiUnderlineItalicBold', '', 2)
call s:highlight_html('i', 'VimwikiUnderlineBoldItalic', '', 2)
call s:highlight_html('em', 'VimwikiUnderlineBoldItalic', '', 2)
" Comment: home made
execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment').
\ '/ contains=@Spell,VimwikiTodo'
" Only do syntax highlighting for multiline comments if they exist
let s:mc_start = vimwiki#vars#get_syntaxlocal('rxMultilineCommentStart')
let s:mc_end = vimwiki#vars#get_syntaxlocal('rxMultilineCommentEnd')
if !empty(s:mc_start) && !empty(s:mc_end)
execute 'syntax region VimwikiMultilineComment start=/'.s:mc_start.
\ '/ end=/'.s:mc_end.'/ contains=@NoSpell,VimwikiTodo'
endif
" Source html file here
execute 'source ' . expand('<sfile>:h') . '/vimwiki_html.vim'
endif
" tags
execute 'syntax match VimwikiTag /'.vimwiki#vars#get_syntaxlocal('rxTags').'/'
" header groups highlighting
if vimwiki#vars#get_global('hl_headers') == 0
" Strangely in default colorscheme Title group is not set to bold for cterm...
@ -445,7 +334,9 @@ else
endfor
endif
" Highlight typefaces -> u.vim
let s:syntax_dic = vimwiki#vars#get_syntaxlocal('dTypeface')
call vimwiki#u#hi_typeface(s:syntax_dic)
hi def link VimwikiMarkers Normal
@ -558,7 +449,7 @@ call vimwiki#u#reload_regexes_custom()
let b:current_syntax='vimwiki'
" EMBEDDED syntax setup
" Code: EMBEDDED syntax setup
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

@ -10,44 +10,38 @@
let s:default_syntax = g:vimwiki_syntax_variables['default']
" TODO mutualise
" Get config: possibly concealed chars
let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : ''
let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
" Typeface:
let s:default_syntax.dTypeface = {}
" text: *strong*
let s:default_syntax.dTypeface['bold'] = [
\ ['\S\@<=\*\|\*\S\@=', '\S\@<=\*\|\*\S\@='],
\ ]
" text: _italic_
let s:default_syntax.dTypeface['italic'] = [
\ ['\S\@<=_\|_\S\@=', '\S\@<=_\|_\S\@='],
\ ]
" text: no underline defined
let s:default_syntax.dTypeface['underline'] = []
" text: *_bold italic_* or _*italic bold*_
let s:default_syntax.dTypeface['bold_italic'] = [
\ ['\S\@<=\*_\|\*_\S\@=', '\S\@<=_\*\|_\*\S\@='],
\ ['\S\@<=_\*\|_\*\S\@=', '\S\@<=\*_\|\*_\S\@='],
\ ]
" text: $ equation_inline $
let s:default_syntax.rxEqIn = '\$[^$`]\+\$'
let s:default_syntax.char_eqin = '\$'
" text: *strong*
" let s:default_syntax.rxBold = '\*[^*]\+\*'
let s:default_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'.
\'\*'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:default_syntax.char_bold = '*'
" text: _emphasis_
" let s:default_syntax.rxItalic = '_[^_]\+_'
let s:default_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'.
\'_'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:default_syntax.char_italic = '_'
" text: *_bold italic_* or _*italic bold*_
let s:default_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\*_'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'_\*'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:default_syntax.char_bolditalic = '\*_'
let s:default_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'_\*'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\*_'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:default_syntax.char_italicbold = '_\*'
" text: `code`
let s:default_syntax.rxCode = '`[^`]\+`'
let s:default_syntax.char_code = '`'

34
syntax/vimwiki_html.vim Normal file
View File

@ -0,0 +1,34 @@
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki syntax file
" Home: https://github.com/vimwiki/vimwiki/
" Description: Defines html syntax
" Loaded: conditionaly by syntax/vimwiki.vim
" Copied from $VIMRUNTIME
" Note: The me=s-1 was omited from the region definition
" See: `syn region VimwikiBoldUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=VimwikiHTMLTag...`
" Note: Not configurable
let s:html_tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|')
exe 'syntax match VimwikiHTMLtag #\c</\?\%('.s:html_tags.'\)\%(\s\{-1}\S\{-}\)\{-}\s*/\?>#'
" Typeface:
let html_typeface = {
\ 'bold': [['<b>', '</b\_s*>'], ['<strong>', '</strong\_s*>']],
\ 'italic': [['<i>', '</i\_s*>'], ['<em>', '</em\_s*>']],
\ 'underline': [['<u>', '</u\_s*>']],
\ }
call vimwiki#u#hi_typeface(html_typeface)
" Comment: home made
execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment').
\ '/ contains=@Spell,VimwikiTodo'
" Only do syntax highlighting for multiline comments if they exist
let s:mc_start = vimwiki#vars#get_syntaxlocal('rxMultilineCommentStart')
let s:mc_end = vimwiki#vars#get_syntaxlocal('rxMultilineCommentEnd')
if !empty(s:mc_start) && !empty(s:mc_end)
execute 'syntax region VimwikiMultilineComment start=/'.s:mc_start.
\ '/ end=/'.s:mc_end.'/ contains=@NoSpell,VimwikiTodo'
endif

View File

@ -9,41 +9,44 @@
let s:markdown_syntax = g:vimwiki_syntax_variables['markdown']
" TODO mutualise
" Get config: possibly concealed chars
let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : ''
let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
" Typeface:
let s:markdown_syntax.dTypeface = {}
" text: **bold** or __bold__
let s:markdown_syntax.dTypeface['bold'] = [
\ ['\S\@<=__\|__\S\@=', '\S\@<=__\|__\S\@='],
\ ['\S\@<=\*\*\|\*\*\S\@=', '\S\@<=\*\*\|\*\*\S\@='],
\ ]
" text: *italic* or _italic_
let s:markdown_syntax.dTypeface['italic'] = [
\ ['\S\@<=\*\|\*\S\@=', '\S\@<=\*\|\*\S\@='],
\ ['\S\@<=_\|_\S\@=', '\S\@<=_\|_\S\@='],
\ ]
" 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\@='],
\ ]
" text: $ equation_inline $
let s:markdown_syntax.rxEqIn = '\$[^$`]\+\$'
let s:markdown_syntax.char_eqin = '\$'
" text: **strong** or __strong__
let s:markdown_syntax.rxBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(\*\|_\)\{2\}'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\1\{2\}'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.char_bold = '\*\*\|__'
" text: _emphasis_ or *emphasis*
let s:markdown_syntax.rxItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(\*\|_\)'.
\'\%([^*_`[:space:]][^*_`]*[^*_`[:space:]]\|[^*_`[:space:]]\)'.
\'\1'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.char_italic = '\*\|_'
" text: *_bold italic_* or _*italic bold*_
let s:markdown_syntax.rxBoldItalic = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(\*\)\{3\}'.
\'\%([^*`[:space:]][^*`]*[^*`[:space:]]\|[^*`[:space:]]\)'.
\'\1\{3\}'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.char_bolditalic = '\*\*\*'
let s:markdown_syntax.rxItalicBold = '\%(^\|\s\|[[:punct:]]\)\@<='.
\'\(_\)\{3\}'.
\'\%([^_`[:space:]][^_`]*[^_`[:space:]]\|[^_`[:space:]]\)'.
\'\1\{3\}'.
\'\%([[:punct:]]\|\s\|$\)\@='
let s:markdown_syntax.char_italicbold = '___'
" text: `code`
let s:markdown_syntax.rxCode = '`[^`]\+`'
let s:markdown_syntax.char_code = '`'

View File

@ -9,24 +9,31 @@
let s:media_syntax = g:vimwiki_syntax_variables['media']
let s:media_syntax.dTypeface = {}
" text: '''strong'''
let s:media_syntax.dTypeface['bold'] = [
\ ['\S\@<=''''''\|''''''\S\@=', '\S\@<=''''''\|''''''\S\@='],
\ ]
" text: ''italic''
let s:media_syntax.dTypeface['italic'] = [
\ ['\S\@<=''''\|''''\S\@=', '\S\@<=''''\|''''\S\@='],
\ ]
" text: no underline defined
let s:media_syntax.dTypeface['underline'] = []
" text: '''''strong italic'''''
let s:media_syntax.dTypeface['bold_italic'] = [
\ ['\S\@<=''''''''''\|''''''''''\S\@=', '\S\@<=''''''''''\|''''''''''\S\@='],
\ ]
" text: $ equation_inline $
let s:media_syntax.rxEqIn = '\$[^$`]\+\$'
let s:media_syntax.char_eqin = '\$'
" text: '''strong'''
let s:media_syntax.rxBold = "'''[^']\\+'''"
let s:media_syntax.char_bold = "'''"
" text: ''emphasis''
let s:media_syntax.rxItalic = "''[^']\\+''"
let s:media_syntax.char_italic = "''"
" text: '''''strong italic'''''
let s:media_syntax.rxBoldItalic = "'''''[^']\\+'''''"
let s:media_syntax.rxItalicBold = s:media_syntax.rxBoldItalic
let s:media_syntax.char_bolditalic = "'''''"
let s:media_syntax.char_italicbold = s:media_syntax.char_bolditalic
" text: `code`
let s:media_syntax.rxCode = '`[^`]\+`'
let s:media_syntax.char_code = '`'

View File

@ -17,7 +17,7 @@ Given vimwiki (Typeface for html 1 like italic):
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax for typeface):
Execute (Assert Syntax for typeface 1):
AssertEqual 'VimwikiBold' , SyntaxAt(1, 15)
AssertEqual 'VimwikiBold' , SyntaxAt(2, 15)
AssertEqual 'VimwikiItalic' , SyntaxAt(3, 15)
@ -32,7 +32,7 @@ Given vimwiki (Typeface for html 2 like italicUnderline):
<u> Underline -cacaca<b>bold underline-------</b>asacc acaca- </u>
<u> Underline -cacaca<i>italic underline-----</i>asdacacc acaca- </u>
Execute (Assert Syntax for typeface):
Execute (Assert Syntax for typeface 2):
AssertEqual 'VimwikiBoldItalic' , GetSyntaxGroup(1, 30)
AssertEqual 'VimwikiBoldUnderline' , GetSyntaxGroup(2, 30)
AssertEqual 'VimwikiBoldItalic' , GetSyntaxGroup(3, 30)
@ -48,7 +48,7 @@ Given vimwiki (Typeface for html 3 like boldItalicUnderline):
<u><b> <i> bold italic underline </i> </b></u>
<u><i><b> bold italic underline </b></i></u>
Execute (Assert Syntax for typeface):
Execute (Assert Syntax for typeface 3):
AssertEqual 'VimwikiBoldItalicUnderline1', GetSyntaxGroup(1, 22).1
AssertEqual 'VimwikiBoldItalicUnderline2', GetSyntaxGroup(2, 22).2
AssertEqual 'VimwikiBoldItalicUnderline3', GetSyntaxGroup(3, 22).3
@ -92,16 +92,16 @@ Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax for typeface):
AssertEqual SyntaxAt(1, 4), 'VimwikiBold'
AssertEqual SyntaxAt(2, 4), 'VimwikiBold'
AssertEqual SyntaxAt(3, 4), 'VimwikiItalic'
AssertEqual SyntaxAt(4, 4), 'VimwikiItalic'
AssertEqual SyntaxAt(5, 4), 'VimwikiBoldItalic'
AssertEqual SyntaxAt(6, 4), 'VimwikiItalicBold'
AssertEqual SyntaxAt(7, 4), 'VimwikiDelText'
AssertEqual SyntaxAt(8, 4), 'VimwikiCode'
AssertEqual SyntaxAt(9, 4), 'VimwikiSuperScript'
AssertEqual SyntaxAt(10, 4), 'VimwikiSubScript'
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)
# 2 Links {{{1