From 86cad979e5c53007bb1b0fc6acb13203a8a115a9 Mon Sep 17 00:00:00 2001 From: Rane Brown Date: Wed, 17 Jul 2019 07:10:47 -0600 Subject: [PATCH] Better handling of extensions when normalizing links. For markdown syntax the extension was added to the url multiple times if the option g:vimwiki_markdown_link_ext was set which is now fixed. Normalizing links no longer adds the extension to the description field. --- autoload/vimwiki/base.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 2630e82..79ffa5c 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -2061,8 +2061,10 @@ endfunction function! s:clean_url(url) + " don't use an extension as part of the description + let url = substitute(a:url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '') " remove protocol and tld - let url = substitute(a:url, '^\a\+\d*:', '', '') + let url = substitute(url, '^\a\+\d*:', '', '') let url = substitute(url, '^//', '', '') let url = substitute(url, '^\([^/]\+\)\.\a\{2,4}/', '\1/', '') let url_l = split(url, '/\|=\|-\|&\|?\|\.') @@ -2090,8 +2092,12 @@ endfunction function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) let url = matchstr(a:str, a:rxUrl) + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_global('markdown_link_ext') + " strip the extension if it exists so it doesn't get added multiple times + let url = substitute(url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '') + endif let descr = matchstr(a:str, a:rxDesc) - if descr == "" + if descr ==# '' let descr = s:clean_url(url) endif let lnk = s:safesubstitute(a:template, '__LinkDescription__', descr, '')