commit e7124290a25f54225251bccec36e29f85db25360
parent 788a961052b843eeaa198dee0168fdf492f373c8
Author: Tinmarino <tinmarino@gmail.com>
Date: Sun, 10 Jan 2021 12:27:35 -0300
Fix: Typeface font highlight VimwikiBoldItalicUnderline was not bold
Fix 2: s:setup_cleared_syntax() was reconfiguring badly
Test: for hi VimwikiBold -> cterm=bold
Diffstat:
6 files changed, 96 insertions(+), 37 deletions(-)
diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim
@@ -189,7 +189,7 @@ endfunction
function! s:populate_global_variables() abort
- " Populate global variable <- user & default
+ " Populate: global variable <- user & default
" Called: s:vimwiki#vars#init
call s:read_global_settings_from_user()
call s:normalize_global_settings()
@@ -198,25 +198,32 @@ endfunction
function! s:internal_global_settings() abort
- " Read nromalized settings and create some more usefull variables to use internally
+ " Declare: normalized settings -> more usefull variables to use internally
" non-configurable global variables:
" Scheme regexes must be defined even if syntax file is not loaded yet cause users should be
" able to <leader>w<leader>w without opening any vimwiki file first
+
+ " Know internal schemes
let g:vimwiki_global_vars.schemes = join(['wiki\d\+', 'diary', 'local'], '\|')
+
+ " Are used in markdown for image links
let g:vimwiki_global_vars.web_schemes1 = join(['http', 'https', 'file', 'ftp', 'gopher',
\ 'telnet', 'nntp', 'ldap', 'rsync', 'imap', 'pop', 'irc', 'ircs', 'cvs', 'svn', 'svn+ssh',
\ 'git', 'ssh', 'fish', 'sftp'], '\|')
+
+ " Other possible schemes
let web_schemes2 =
\ join(['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data'], '\|')
+ " Concatenate known schemes => regex
let g:vimwiki_global_vars.rxSchemes = '\%('.
\ g:vimwiki_global_vars.schemes . '\|'.
\ g:vimwiki_global_vars.web_schemes1 . '\|'.
\ web_schemes2 .
\ '\)'
- " match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
+ " Match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme
" http://tools.ietf.org/html/rfc3986
let rxWebProtocols =
\ '\%('.
@@ -227,7 +234,6 @@ function! s:internal_global_settings() abort
\ '\|'.
\ '\%('.web_schemes2.'\):'.
\ '\)'
-
let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\='
let wikilink_prefix = '[['
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
@@ -1150,24 +1150,24 @@ The primary purpose for wiki-include links is to include images.
Transclude from a local URL: >
{{file:../../images/vimwiki_logo.png}}
or from a universal URL: >
- {{http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png}}
+ {{https://raw.githubusercontent.com/vimwiki/vimwiki/master/doc/splash.png}}
Transclude image with alternate text: >
- {{http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png|Vimwiki}}
+ {{https://raw.githubusercontent.com/vimwiki/vimwiki/master/doc/splash.png|Vimwiki}}
in HTML: >
- <img src="http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png"
+ <img src="https://raw.githubusercontent.com/vimwiki/vimwiki/master/doc/splash.png"
alt="Vimwiki"/>
Transclude image with alternate text and some style: >
{{http://.../vimwiki_logo.png|cool stuff|style="width:150px;height:120px;"}}
in HTML: >
- <img src="http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png"
+ <img src="https://raw.githubusercontent.com/vimwiki/vimwiki/master/doc/splash.png"
alt="cool stuff" style="width:150px; height:120px"/>
Transclude image _without_ alternate text and with a CSS class: >
{{http://.../vimwiki_logo.png||class="center flow blabla"}}
in HTML: >
- <img src="http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png"
+ <img src="https://raw.githubusercontent.com/vimwiki/vimwiki/master/doc/splash.png"
alt="" class="center flow blabla"/>
A trial feature allows you to supply your own handler for wiki-include links.
diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim
@@ -129,8 +129,8 @@ function! s:setup_cleared_syntax() abort
" on colorscheme change because they are not linked to Vim-predefined groups
hi def VimwikiBold term=bold cterm=bold gui=bold
hi def VimwikiItalic term=italic cterm=italic gui=italic
- hi def VimwikiBoldItalic term=bold cterm=bold gui=bold,italic
- hi def VimwikiUnderline gui=underline
+ hi def VimwikiBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic
+ hi def VimwikiUnderline term=underline cterm=underline gui=underline
if vimwiki#vars#get_global('hl_headers') == 1
for i in range(1,6)
execute 'hi def VimwikiHeader'.i.' guibg=bg guifg='
diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim
@@ -257,10 +257,12 @@ endif
" Horizontal Rule: <hr>
execute 'syntax match VimwikiHR /'.vimwiki#vars#get_syntaxlocal('rxHR').'/'
+" Preformated Text: `like that`
let concealpre = vimwiki#vars#get_global('conceal_pre') ? ' concealends' : ''
execute 'syntax region VimwikiPre matchgroup=VimwikiPreDelim start=/'.vimwiki#vars#get_syntaxlocal('rxPreStart').
\ '/ end=/'.vimwiki#vars#get_syntaxlocal('rxPreEnd').'/ contains=@NoSpell'.concealpre
+" Equation Text: $like that$
execute 'syntax region VimwikiMath start=/'.vimwiki#vars#get_syntaxlocal('rxMathStart').
\ '/ end=/'.vimwiki#vars#get_syntaxlocal('rxMathEnd').'/ contains=@NoSpell'
@@ -281,7 +283,7 @@ 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*/\?>#'
- " Typeface:
+ " Html Typeface: <b>bold text</b>
let html_typeface = {
\ 'bold': [['<b>', '</b\_s*>'], ['<strong>', '</strong\_s*>']],
\ 'italic': [['<i>', '</i\_s*>'], ['<em>', '</em\_s*>']],
@@ -292,6 +294,7 @@ if vimwiki#vars#get_global('valid_html_tags') !=? ''
\ 'sup': [['<sup>', '</sup\_s*>']],
\ 'sub': [['<sub>', '</sub\_s*>']],
\ }
+ " Highlight now
call vimwiki#u#hi_typeface(html_typeface)
endif
@@ -401,16 +404,13 @@ hi def VimwikiItalicUnderline term=italic,underline cterm=italic,underline gui=i
hi def link VimwikiUnderlineItalic VimwikiItalicUnderline
" Typeface 3
-hi def VimwikiItalicUnderline term=italic,underline cterm=italic,underline gui=italic,underline
+hi def VimwikiBoldItalicUnderline term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
hi def link VimwikiBoldUnderlineItalic VimwikiBoldItalicUnderline
hi def link VimwikiItalicBoldUnderline VimwikiBoldItalicUnderline
hi def link VimwikiItalicUnderlineBold VimwikiBoldItalicUnderline
hi def link VimwikiUnderlineBoldItalic VimwikiBoldItalicUnderline
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
diff --git a/test/syntax.vader b/test/syntax.vader
@@ -1,7 +1,5 @@
# Syntax and Highlight
-#Given vimwiki (bold and pre):
-
# 1 Typeface {{{1
#################
@@ -726,4 +724,40 @@ Execute (Assert math syntax 2):
let syntax_12 = SyntaxAt(12, 1)
Assert syntax_12 == 'texStatement' || syntax_5 == 'texMathSymbol'
+# 21 Highlight {{{1
+##################
+Given vimwiki (One line):
+ content
+
+Execute (Assert highlight typeface 1):
+ " Typeface 1
+ AssertEqual ['bold'], GetHighlightTerm('VimwikiBold', 'term')
+ AssertEqual ['bold'], GetHighlightTerm('VimwikiBold', 'cterm')
+ AssertEqual ['bold'], GetHighlightTerm('VimwikiBold', 'gui')
+
+ AssertEqual ['italic'], GetHighlightTerm('VimwikiItalic', 'cterm')
+ AssertEqual ['underline'], GetHighlightTerm('VimwikiUnderline', 'gui')
+
+Execute (Assert highlight typeface 2):
+ " Bold > Italic > Underline
+ AssertEqual sort(['bold', 'italic', '1']), sort(add(GetHighlightTerm('VimwikiBoldItalic', 'gui'), '1'))
+ AssertEqual sort(['bold', 'italic', '2']), sort(add(GetHighlightTerm('VimwikiBoldItalic', 'term'), '2'))
+
+ AssertEqual sort(['bold', 'underline', '3']), sort(add(GetHighlightTerm('VimwikiBoldUnderline', 'cterm'), '3'))
+ AssertEqual sort(['bold', 'underline', '4']), sort(add(GetHighlightTerm('VimwikiUnderlineBold', 'term'), '4'))
+
+ AssertEqual sort(['italic', 'underline', '5']), sort(add(GetHighlightTerm('VimwikiItalicUnderline', 'cterm'), '5'))
+
+Execute (Assert highlight typeface 3):
+ AssertEqual sort(['bold', 'italic', 'underline', '1']), sort(add(GetHighlightTerm('VimwikiBoldItalicUnderline', 'gui'), '1'))
+ AssertEqual sort(['bold', 'italic', 'underline', '2']), sort(add(GetHighlightTerm('VimwikiBoldUnderlineItalic', 'cterm'), '2'))
+ AssertEqual sort(['bold', 'italic', 'underline', '3']), sort(add(GetHighlightTerm('VimwikiItalicBoldUnderline', 'term'), '3'))
+ AssertEqual sort(['bold', 'italic', 'underline', '4']), sort(add(GetHighlightTerm('VimwikiItalicUnderlineBold', 'gui'), '4'))
+ AssertEqual sort(['bold', 'italic', 'underline', '5']), sort(add(GetHighlightTerm('VimwikiUnderlineBoldItalic', 'cterm'), '5'))
+ AssertEqual sort(['bold', 'italic', 'underline', '6']), sort(add(GetHighlightTerm('VimwikiUnderlineItalicBold', 'term'), '6'))
+
+Expect (One line):
+ content
+
+
# vim: foldmethod=marker foldlevel=30 sw=2
diff --git a/test/vimrc b/test/vimrc
@@ -87,8 +87,8 @@
endif
" Define functions
- " Change the syntax using a temporary wiki
function! SetSyntax(vw_syn)
+ " Change the syntax using a temporary wiki
" Change extension and wiki_nr
let index=0
if a:vw_syn ==# 'default'
@@ -164,13 +164,13 @@
endif
endfunction
- " Source plugin
function! LoadVimwiki()
+ " Source plugin
runtime! plugin/vimwiki.vim
endfunction
- " Reload plugin to change settings
function! ReloadVimwiki()
+ " Reload plugin to change settings
call UnloadVimwiki()
" Reset list
@@ -185,17 +185,17 @@
call vimwiki#vars#init()
endfunction
- " Copy wiki test resources so that vimtest user can write them
function! CopyResources()
+ " Copy wiki test resources so that vimtest user can write them
call system('cp -r /testplugin/test/resources/* $HOME/')
" Make diary directory
call system('mkdir $HOME/testwiki/diary')
call system('mkdir $HOME/testmarkdown/diary')
endfunction
- " Delete Hidden buffer, usefull to clean
- " Stole from: https://stackoverflow.com/a/8459043/2544873
function! DeleteHiddenBuffers()
+ " Delete Hidden buffer, usefull to clean
+ " See: https://stackoverflow.com/a/8459043/2544873
let tpbl=[]
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
@@ -206,14 +206,14 @@
endfor
endfunction
- " Write current file: helper to hide `set bt=`
function! WriteMe()
+ " Write current file: helper to hide `set bt=`
set buftype=
write! %
endfunction
- " Delete a file <- path <string>
function! DeleteFile(path)
+ " Delete a file <- path <string>
let path = expand(a:path)
" Delete file
try
@@ -225,8 +225,8 @@
catch | endtry
endfunction
- " Print a command output to the buffer
function! PrintCommand(cmd)
+ " Print a command output to the buffer
redir => message
silent execute a:cmd
redir END
@@ -237,21 +237,21 @@
endif
endfunction
- " Destroy a variable is exists (unlet)
function! DestroyVar(var)
+ " Destroy a variable is exists (unlet)
if ! exists(a:var) | return | endif
execute 'unlet ' . a:var
endfunction
- " Assert current tab is desired tab
function! AssertTab(nr)
+ " Assert current tab is desired tab
" Vader is creating 2 tabs
AssertEqual a:nr + 2, tabpagenr()
endfunction
- " Convert current buffer: wiki -> html
- " No side effect (if no bug)
function! ConvertWiki2Html()
+ " Convert current buffer: wiki -> html
+ " No side effect (if no bug)
" Save fbuffer number (to come back)
let g:buf_vader = bufnr('%')
@@ -287,8 +287,8 @@
call DeleteFile('$HOME/testwiki/test_Convert2Html.wiki')
endfunction
- " Get only body
function! ConvertWiki2Body()
+ " Get only body
call ConvertWiki2Html()
" Empty b register
@@ -307,28 +307,47 @@
0d
endfunction
- " Get normalized syntax group: usefull for boldItalic Vs italicBold
- " -- Here, Vader's SyntaxAt is not enough
- " From: https://stackoverflow.com/questions/9464844
function! GetSyntaxGroup(line, col)
+ " Get normalized syntax group: usefull for boldItalic Vs italicBold
+ " -- Here, Vader's SyntaxAt is not enough
+ " From: https://stackoverflow.com/questions/9464844
let l:s = synID(a:line, a:col, 1)
return synIDattr(synIDtrans(l:s), 'name')
endfun
- " Debug helper
function! GetSyntaxStack()
+ " Debug helper
if !exists('*synstack')
return
endif
return map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
- " Run Assert only if vim version higth enough
function! AssertIfVersion(version, one, two)
+ " Run Assert only if vim version higth enough
if v:version < a:version | return | endif
AssertEqual a:one, a:two
endfunction
+ function! GetHighlightTerm(group, term)
+ " Get output of `hi group`
+ " From: https://vi.stackexchange.com/a/12294/5026
+ " Return list ['bold','underline']
+ " Store output of group to variable
+ let out = execute('hi ' . a:group)
+
+ " If links to, call parent
+ let parent = matchstr(out, 'links to *\zs[^ \t\n\r]*')
+ if parent !=# ''
+ " Return list_of_parent, parent
+ return GetHighlightTerm(parent, a:term)
+ endif
+
+ " Return the unique term we are looking for
+ let stg = matchstr(out, a:term.'=\zs[^ \t\n\r]*')
+ return split(stg, ',')
+ endfunction
+
" Copy Wiki's Resources
call CopyResources()