Feature: Config: Normalize link so that user can choose [[]] or []() (Issue #892)
Main change: Create function: normalize_syntax_settings(syntax) Problem: Some user prefer [[]] links more than [](). As vimwiki know both of them, they should be able to choose without regex mastery and with tests Solution: let g:vimwiki_syntax_variables.markdown.Link1 = vimwiki#vars#get_global('WikiLinkTemplate1')
This commit is contained in:
parent
4672deb44e
commit
d9d14cc3f7
@ -429,11 +429,7 @@ function! vimwiki#base#generate_links(create, ...) abort
|
|||||||
for link in links
|
for link in links
|
||||||
let link_infos = vimwiki#base#resolve_link(link)
|
let link_infos = vimwiki#base#resolve_link(link)
|
||||||
if !vimwiki#base#is_diary_file(link_infos.filename, copy(l:diary_file_paths))
|
if !vimwiki#base#is_diary_file(link_infos.filename, copy(l:diary_file_paths))
|
||||||
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Link1')
|
||||||
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
|
|
||||||
else
|
|
||||||
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
|
|
||||||
endif
|
|
||||||
|
|
||||||
let link_caption = vimwiki#base#read_caption(link_infos.filename)
|
let link_caption = vimwiki#base#read_caption(link_infos.filename)
|
||||||
if link_caption ==? '' " default to link if caption not found
|
if link_caption ==? '' " default to link if caption not found
|
||||||
@ -2252,7 +2248,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Treat link string towards normalization
|
" Treat link string towards normalization
|
||||||
" [__LinkDescription__](__LinkUrl__.FileExtension)
|
" [__LinkDescription__](__LinkUrl__.__FileExtension__)
|
||||||
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
|
function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort
|
||||||
let url = matchstr(a:str, a:rxUrl)
|
let url = matchstr(a:str, a:rxUrl)
|
||||||
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_wikilocal('markdown_link_ext')
|
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_wikilocal('markdown_link_ext')
|
||||||
@ -2284,6 +2280,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Normalize link in a diary file
|
" Normalize link in a diary file
|
||||||
|
" Refactor: in diary
|
||||||
function! vimwiki#base#normalize_link_in_diary(lnk) abort
|
function! vimwiki#base#normalize_link_in_diary(lnk) abort
|
||||||
let sc = vimwiki#vars#get_wikilocal('links_space_char')
|
let sc = vimwiki#vars#get_wikilocal('links_space_char')
|
||||||
let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
|
let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
|
||||||
@ -2313,7 +2310,7 @@ function! vimwiki#base#normalize_link_in_diary(lnk) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if vimwiki#vars#get_wikilocal('syntax') ==? 'markdown'
|
if vimwiki#vars#get_wikilocal('syntax') ==? 'markdown'
|
||||||
let template = vimwiki#vars#get_syntaxlocal('Weblink1Template')
|
let template = vimwiki#vars#get_syntaxlocal('Link1')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
|
return vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
|
||||||
@ -2380,13 +2377,8 @@ function! s:normalize_link_syntax_v() abort
|
|||||||
if vimwiki#base#is_diary_file(expand('%:p'))
|
if vimwiki#base#is_diary_file(expand('%:p'))
|
||||||
let link = vimwiki#base#normalize_link_in_diary(visual_selection)
|
let link = vimwiki#base#normalize_link_in_diary(visual_selection)
|
||||||
else
|
else
|
||||||
" Warning nested syntax discrimination
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Link1')
|
||||||
if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown'
|
let link = s:safesubstitute(link_tpl, '__LinkUrl__', visual_selection, '')
|
||||||
let template = vimwiki#vars#get_syntaxlocal('Weblink1Template')
|
|
||||||
else
|
|
||||||
let template = vimwiki#vars#get_global('WikiLinkTemplate1')
|
|
||||||
endif
|
|
||||||
let link = s:safesubstitute(template, '__LinkUrl__', visual_selection, '')
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Transform link:
|
" Transform link:
|
||||||
|
@ -102,7 +102,7 @@ function! s:normalize_link_syntax_n() abort
|
|||||||
else
|
else
|
||||||
let sub = vimwiki#base#normalize_link_helper(lnk,
|
let sub = vimwiki#base#normalize_link_helper(lnk,
|
||||||
\ vimwiki#vars#get_global('rxWord'), '',
|
\ vimwiki#vars#get_global('rxWord'), '',
|
||||||
\ vimwiki#vars#get_syntaxlocal('Weblink1Template'))
|
\ vimwiki#vars#get_syntaxlocal('Link1'))
|
||||||
endif
|
endif
|
||||||
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
|
call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
|
||||||
return
|
return
|
||||||
|
@ -360,7 +360,7 @@ function! vimwiki#tags#generate_tags(create, ...) abort
|
|||||||
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink3Template')
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink3Template')
|
||||||
let link_infos = vimwiki#base#resolve_link(taglink)
|
let link_infos = vimwiki#base#resolve_link(taglink)
|
||||||
if empty(link_infos.anchor)
|
if empty(link_infos.anchor)
|
||||||
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
|
let link_tpl = vimwiki#vars#get_syntaxlocal('Link1')
|
||||||
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', taglink, '')
|
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', taglink, '')
|
||||||
let entry = s:safesubstitute(entry, '__LinkDescription__', taglink, '')
|
let entry = s:safesubstitute(entry, '__LinkDescription__', taglink, '')
|
||||||
else
|
else
|
||||||
|
@ -563,7 +563,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
" Helper path
|
" Helper path
|
||||||
" TODO move to path
|
" TODO move to path: Conflict with: vimwiki#path#path_norm && vimwiki#path#normalize
|
||||||
function! s:normalize_path(path) abort
|
function! s:normalize_path(path) abort
|
||||||
" trim trailing / and \ because otherwise resolve() doesn't work quite right
|
" trim trailing / and \ because otherwise resolve() doesn't work quite right
|
||||||
let path = substitute(a:path, '[/\\]\+$', '', '')
|
let path = substitute(a:path, '[/\\]\+$', '', '')
|
||||||
@ -741,6 +741,8 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort
|
|||||||
if a:syntax ==# 'markdown'
|
if a:syntax ==# 'markdown'
|
||||||
call s:populate_extra_markdown_vars()
|
call s:populate_extra_markdown_vars()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
call s:normalize_syntax_settings(a:syntax)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
@ -975,6 +977,23 @@ function! s:populate_extra_markdown_vars() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
" Normalize syntax setting
|
||||||
|
" so that we dont have to branch for the syntax at each operation
|
||||||
|
" Called: vimwiki#vars#populate_syntax_vars
|
||||||
|
function! s:normalize_syntax_settings(syntax) abort
|
||||||
|
let syntax_dic = g:vimwiki_syntax_variables[a:syntax]
|
||||||
|
|
||||||
|
" Link1: used when:
|
||||||
|
" user press enter on a non-link (normalize_link)
|
||||||
|
" command generate link form file name (generate_link)
|
||||||
|
if a:syntax ==# 'markdown'
|
||||||
|
let syntax_dic.Link1 = syntax_dic.Weblink1Template
|
||||||
|
else
|
||||||
|
let syntax_dic.Link1 = vimwiki#vars#get_global('WikiLinkTemplate1')
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" ----------------------------------------------------------
|
" ----------------------------------------------------------
|
||||||
" 4. Getter, Setter (exported)
|
" 4. Getter, Setter (exported)
|
||||||
" ----------------------------------------------------------
|
" ----------------------------------------------------------
|
||||||
|
@ -1,5 +1,30 @@
|
|||||||
Include: vader_includes/vader_setup.vader
|
Include: vader_includes/vader_setup.vader
|
||||||
|
|
||||||
|
# Link Normalisation {{{1
|
||||||
|
# And configuration
|
||||||
|
# Issues: #892
|
||||||
|
####################
|
||||||
|
|
||||||
|
Execute (Log):
|
||||||
|
Log 'Markdown change Link1 : Pressing enter to create a [[double bracket]] #892'
|
||||||
|
|
||||||
|
Given vimwiki (abc def ghi jkl):
|
||||||
|
abc def ghi jkl
|
||||||
|
|
||||||
|
Execute (Set filename wiki_test.md):
|
||||||
|
call SetSyntax('markdown')
|
||||||
|
let save_link = g:vimwiki_syntax_variables.markdown.Link1
|
||||||
|
let g:vimwiki_syntax_variables.markdown.Link1 = vimwiki#vars#get_global('WikiLinkTemplate1')
|
||||||
|
|
||||||
|
Do (vee<CR>):
|
||||||
|
vee\<CR>
|
||||||
|
|
||||||
|
Expect (append md suffix):
|
||||||
|
[[abc def]] ghi jkl
|
||||||
|
|
||||||
|
Execute (restore):
|
||||||
|
let g:vimwiki_syntax_variables.markdown.Link1 = save_link
|
||||||
|
|
||||||
|
|
||||||
# vimwiki_markdown_link_ext {{{1
|
# vimwiki_markdown_link_ext {{{1
|
||||||
####################
|
####################
|
||||||
|
Loading…
Reference in New Issue
Block a user