commit 1852c6c54212d56a9e4f7c8f423b3005ef750809
parent 39812e5c96cc3523a69e5ec65766d3d86241b47e
Author: Tinmarino <tinmarino@gmail.com>
Date: Tue, 12 May 2020 11:42:41 -0400
Fix: clean_url removing Chinese character
Issue: <Enter> create link bug with Chinese characters #849
Thank: @BSDxxxx
Diffstat:
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -2119,6 +2119,7 @@ function! s:clean_url(url) abort
let url = substitute(a:url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '')
" remove protocol and tld
let url = substitute(url, '^\a\+\d*:', '', '')
+ " remove absolute path prefix
let url = substitute(url, '^//', '', '')
let url = substitute(url, '^\([^/]\+\)\.\a\{2,4}/', '\1/', '')
let url_l = split(url, '/\|=\|-\|&\|?\|\.')
@@ -2129,8 +2130,10 @@ function! s:clean_url(url) abort
if url_l[-1] =~# '^\(htm\|html\|php\)$'
let url_l = url_l[0:-2]
endif
- " remove words consisting of only hexadecimal digits or non-word characters
- let url_l = filter(url_l, 'v:val !~? "^\\A\\{4,}$"')
+ " remove words with black listed codepoints
+ " TODO mutualize blacklist in a variable
+ let url_l = filter(url_l, 'v:val !~? "[!\"$%&''()*+,:;<=>?\[\]\\^`{}]"')
+ " remove words consisting of only hexadecimal digits
let url_l = filter(url_l, 'v:val !~? "^\\x\\{4,}$" || v:val !~? "\\d"')
return join(url_l, ' ')
endfunction
diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim
@@ -86,6 +86,7 @@ function! s:populate_global_variables() abort
" buffer (and not on a link) to create a link
" basically, it's Ascii alphanumeric characters plus #|./@-_~ plus all
" non-Ascii characters, except that . is not accepted as the last character
+ " TODO look behind for . reduces the second part of the regex that is the same with '.' added
let g:vimwiki_global_vars.rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]*[^[:blank:]!"$%&''()*+.,:;<=>?\[\]\\^`{}]'
let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix .