Fix: Link substitution of __FileExtension__ #914
This commit is contained in:
parent
865b402c06
commit
e1826702b7
@ -2189,7 +2189,7 @@ endfunction
|
||||
" Construct a regular expression matching from template (with special
|
||||
" characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc
|
||||
" for __LinkDescription__, rxStyle for __LinkStyle__ and rxExtension for
|
||||
" __FileExtention__. The four arguments rxUrl, rxDesc, rxStyle and
|
||||
" __FileExtension__. The four arguments rxUrl, rxDesc, rxStyle and
|
||||
" rxExtension are copied verbatim, without any special character escapes or
|
||||
" substitutions.
|
||||
function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtension) abort
|
||||
@ -2204,7 +2204,7 @@ function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle, rxExtens
|
||||
let lnk = s:safesubstitute(lnk, '__LinkStyle__', a:rxStyle, 'g')
|
||||
endif
|
||||
if a:rxExtension !=? ''
|
||||
let lnk = s:safesubstitute(lnk, '__FileExtention__', a:rxExtension, 'g')
|
||||
let lnk = s:safesubstitute(lnk, '__FileExtension__', a:rxExtension, 'g')
|
||||
endif
|
||||
return lnk
|
||||
endfunction
|
||||
@ -2254,6 +2254,7 @@ endfunction
|
||||
|
||||
|
||||
" Treat link string towards normalization
|
||||
" [__LinkDescription__](__LinkUrl__.FileExtension)
|
||||
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
|
||||
let url = matchstr(a:str, a:rxUrl)
|
||||
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_global('markdown_link_ext')
|
||||
@ -2266,8 +2267,11 @@ function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
|
||||
let descr = s:clean_url(url)
|
||||
if descr ==# '' | return url | endif
|
||||
endif
|
||||
" Substiture placeholders
|
||||
let lnk = s:safesubstitute(a:template, '__LinkDescription__', descr, '')
|
||||
let lnk = s:safesubstitute(lnk, '__LinkUrl__', url, '')
|
||||
let file_extension = vimwiki#vars#get_wikilocal('ext', vimwiki#vars#get_bufferlocal('wiki_nr'))
|
||||
let lnk = s:safesubstitute(lnk, '__FileExtension__', file_extension , '')
|
||||
return lnk
|
||||
endfunction
|
||||
|
||||
@ -2358,12 +2362,16 @@ function! s:normalize_link_syntax_n() abort
|
||||
let sub = s:safesubstitute(
|
||||
\ vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', lnk, '')
|
||||
endif
|
||||
" Replace file extension
|
||||
let file_extension = vimwiki#vars#get_wikilocal('ext', vimwiki#vars#get_bufferlocal('wiki_nr'))
|
||||
let sub = s:safesubstitute(sub, '__FileExtension__', file_extension , '')
|
||||
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
|
||||
return
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" TODO mutualize most code with syntax_n
|
||||
" Normalize link in visual mode Enter keypress
|
||||
function! s:normalize_link_syntax_v() abort
|
||||
let sel_save = &selection
|
||||
@ -2376,12 +2384,16 @@ function! s:normalize_link_syntax_v() abort
|
||||
normal! gv""y
|
||||
|
||||
" Set substitution
|
||||
" Replace Url
|
||||
if vimwiki#base#is_diary_file(expand('%:p'))
|
||||
let sub = vimwiki#base#normalize_link_in_diary(@")
|
||||
else
|
||||
let sub = s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
|
||||
\ '__LinkUrl__', @", '')
|
||||
endif
|
||||
" Replace file extension
|
||||
let file_extension = vimwiki#vars#get_wikilocal('ext', vimwiki#vars#get_bufferlocal('wiki_nr'))
|
||||
let sub = s:safesubstitute(sub, '__FileExtension__', file_extension , '')
|
||||
|
||||
" Put substitution in register " and change text
|
||||
let sc = vimwiki#vars#get_wikilocal('links_space_char')
|
||||
|
@ -130,10 +130,16 @@ function! s:normalize_link_syntax_v() abort
|
||||
\ '__LinkUrl__', visual_selection, '')
|
||||
endif
|
||||
|
||||
" replace spaces with new character if option is set
|
||||
" Replace spaces with new character if option is set
|
||||
let link = substitute(link, '\s', vimwiki#vars#get_wikilocal('links_space_char'), 'g')
|
||||
|
||||
" Replace description
|
||||
let link = s:safesubstitute(link, '__LinkDescription__', visual_selection, '')
|
||||
|
||||
" Replace file extension
|
||||
let file_extension = vimwiki#vars#get_wikilocal('ext', vimwiki#vars#get_bufferlocal('wiki_nr'))
|
||||
let link = s:safesubstitute(link, '__FileExtension__', file_extension , '')
|
||||
|
||||
call setreg('"', substitute(link, '\n', '', ''), visualmode())
|
||||
|
||||
" paste result
|
||||
@ -148,15 +154,12 @@ endfunction
|
||||
|
||||
|
||||
function! vimwiki#markdown_base#normalize_link(is_visual_mode) abort
|
||||
if 0
|
||||
" Syntax-specific links
|
||||
else
|
||||
|
||||
if !a:is_visual_mode
|
||||
call s:normalize_link_syntax_n()
|
||||
elseif line("'<") == line("'>")
|
||||
" action undefined for multi-line visual mode selections
|
||||
call s:normalize_link_syntax_v()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -874,10 +874,12 @@ function! s:populate_extra_markdown_vars() abort
|
||||
let mkd_syntax.rxWeblink1Suffix = ')'
|
||||
let mkd_syntax.rxWeblink1EscapeCharsSuffix = '\(\\\)\@<!\()\)'
|
||||
let mkd_syntax.rxWeblink1Separator = ']('
|
||||
|
||||
let rxWeblink1Ext = ''
|
||||
if vimwiki#vars#get_global('markdown_link_ext')
|
||||
let rxWeblink1Ext = '__FileExtention__'
|
||||
let rxWeblink1Ext = '__FileExtension__'
|
||||
endif
|
||||
|
||||
" [DESCRIPTION](URL)
|
||||
let mkd_syntax.Weblink1Template = mkd_syntax.rxWeblink1Prefix . '__LinkDescription__'.
|
||||
\ mkd_syntax.rxWeblink1Separator. '__LinkUrl__'. rxWeblink1Ext.
|
||||
@ -902,18 +904,18 @@ function! s:populate_extra_markdown_vars() abort
|
||||
\ mkd_syntax.rx_wikilink_md_prefix .
|
||||
\ '.*' .
|
||||
\ rx_wikilink_md_separator .
|
||||
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%(__FileExtention__\)\?'.
|
||||
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%(__FileExtension__\)\?'.
|
||||
\ mkd_syntax.rx_wikilink_md_suffix .
|
||||
\ '\|' .
|
||||
\ mkd_syntax.rx_wikilink_md_prefix .
|
||||
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%(__FileExtention__\)\?'.
|
||||
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%(__FileExtension__\)\?'.
|
||||
\ rx_wikilink_md_separator .
|
||||
\ mkd_syntax.rx_wikilink_md_suffix .
|
||||
\ '\|' .
|
||||
\ mkd_syntax.rxWeblink1Prefix.
|
||||
\ '.*' .
|
||||
\ mkd_syntax.rxWeblink1Separator.
|
||||
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%(__FileExtention__\)\?'.
|
||||
\ '\zs__LinkUrl__\ze\%(#.*\)\?\%(__FileExtension__\)\?'.
|
||||
\ mkd_syntax.rxWeblink1EscapeCharsSuffix
|
||||
|
||||
" 1. [DESCRIPTION](URL)
|
||||
|
Loading…
Reference in New Issue
Block a user