slightly change the semantics of file: and local: scheme
This commit is contained in:
@ -270,7 +270,6 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
||||
\ 'scheme': '',
|
||||
\ 'filename': '',
|
||||
\ 'anchor': '',
|
||||
\ 'relative': 0,
|
||||
\ }
|
||||
|
||||
|
||||
@ -303,12 +302,14 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
||||
|
||||
" check if absolute or relative path
|
||||
if is_wiki_link && link_text[0] == '/'
|
||||
let link_text = link_text[1:]
|
||||
let link_infos.relative = 0
|
||||
if link_text != '/'
|
||||
let link_text = link_text[1:]
|
||||
endif
|
||||
let is_relative = 0
|
||||
elseif !is_wiki_link && vimwiki#path#is_absolute(link_text)
|
||||
let link_infos.relative = 0
|
||||
let is_relative = 0
|
||||
else
|
||||
let link_infos.relative = 1
|
||||
let is_relative = 1
|
||||
let root_dir = fnamemodify(source_file, ':p:h') . '/'
|
||||
endif
|
||||
|
||||
@ -321,7 +322,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
||||
return link_infos
|
||||
endif
|
||||
|
||||
if !link_infos.relative || link_infos.index != source_wiki
|
||||
if !is_relative || link_infos.index != source_wiki
|
||||
let root_dir = VimwikiGet('path', link_infos.index)
|
||||
endif
|
||||
|
||||
@ -345,7 +346,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
||||
\ link_text .
|
||||
\ VimwikiGet('ext', link_infos.index)
|
||||
elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local')
|
||||
\ && link_infos.relative
|
||||
\ && is_relative
|
||||
let link_infos.filename = simplify(root_dir . link_text)
|
||||
else " absolute file link
|
||||
" collapse repeated leading "/"'s within a link
|
||||
|
@ -380,12 +380,16 @@ function! s:tag_wikiincl(value) "{{{
|
||||
echom string(link_infos)
|
||||
endif
|
||||
|
||||
let url = link_infos.filename
|
||||
|
||||
" strip the .html extension when we have wiki links, so that the user can
|
||||
" simply write {{image.png}} to include an image from the wiki directory
|
||||
if link_infos.scheme =~# '\mwiki\d\+\|diary'
|
||||
let url = fnamemodify(url, ':r')
|
||||
if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary'
|
||||
let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'),
|
||||
\ link_infos.filename)
|
||||
" strip the .html extension when we have wiki links, so that the user can
|
||||
" simply write {{image.png}} to include an image from the wiki directory
|
||||
if link_infos.scheme =~# '\mwiki\d\+\|diary'
|
||||
let url = fnamemodify(url, ':r')
|
||||
endif
|
||||
else
|
||||
let url = link_infos.filename
|
||||
endif
|
||||
|
||||
let url = escape(url, '#')
|
||||
@ -412,16 +416,17 @@ function! s:tag_wikilink(value) "{{{
|
||||
if line == ''
|
||||
let link_infos = vimwiki#base#resolve_link(url, s:current_wiki_file)
|
||||
|
||||
if link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local'
|
||||
if link_infos.scheme ==# 'file'
|
||||
" external file links are always absolute
|
||||
let html_link = link_infos.filename
|
||||
elseif link_infos.scheme ==# 'local'
|
||||
let html_link = vimwiki#path#relpath(fnamemodify(s:current_html_file,
|
||||
\ ':h'), link_infos.filename)
|
||||
else
|
||||
" wiki links are always relative to the current file
|
||||
echom link_infos.filename fnamemodify(s:current_wiki_file, ':h') fnamemodify(link_infos.filename, ':r')
|
||||
let html_link = vimwiki#path#relpath(
|
||||
\ fnamemodify(s:current_wiki_file, ':h'),
|
||||
\ fnamemodify(link_infos.filename, ':r'))
|
||||
echom html_link
|
||||
if html_link !~ '\m/$'
|
||||
let html_link .= '.html'
|
||||
endif
|
||||
|
Reference in New Issue
Block a user