slightly change the semantics of file: and local: scheme
This commit is contained in:
parent
99494655c2
commit
77607f635a
@ -270,7 +270,6 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
|||||||
\ 'scheme': '',
|
\ 'scheme': '',
|
||||||
\ 'filename': '',
|
\ 'filename': '',
|
||||||
\ 'anchor': '',
|
\ 'anchor': '',
|
||||||
\ 'relative': 0,
|
|
||||||
\ }
|
\ }
|
||||||
|
|
||||||
|
|
||||||
@ -303,12 +302,14 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
|||||||
|
|
||||||
" check if absolute or relative path
|
" check if absolute or relative path
|
||||||
if is_wiki_link && link_text[0] == '/'
|
if is_wiki_link && link_text[0] == '/'
|
||||||
let link_text = link_text[1:]
|
if link_text != '/'
|
||||||
let link_infos.relative = 0
|
let link_text = link_text[1:]
|
||||||
|
endif
|
||||||
|
let is_relative = 0
|
||||||
elseif !is_wiki_link && vimwiki#path#is_absolute(link_text)
|
elseif !is_wiki_link && vimwiki#path#is_absolute(link_text)
|
||||||
let link_infos.relative = 0
|
let is_relative = 0
|
||||||
else
|
else
|
||||||
let link_infos.relative = 1
|
let is_relative = 1
|
||||||
let root_dir = fnamemodify(source_file, ':p:h') . '/'
|
let root_dir = fnamemodify(source_file, ':p:h') . '/'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -321,7 +322,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
|||||||
return link_infos
|
return link_infos
|
||||||
endif
|
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)
|
let root_dir = VimwikiGet('path', link_infos.index)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -345,7 +346,7 @@ function! vimwiki#base#resolve_link(link_text, ...) "{{{
|
|||||||
\ link_text .
|
\ link_text .
|
||||||
\ VimwikiGet('ext', link_infos.index)
|
\ VimwikiGet('ext', link_infos.index)
|
||||||
elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local')
|
elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local')
|
||||||
\ && link_infos.relative
|
\ && is_relative
|
||||||
let link_infos.filename = simplify(root_dir . link_text)
|
let link_infos.filename = simplify(root_dir . link_text)
|
||||||
else " absolute file link
|
else " absolute file link
|
||||||
" collapse repeated leading "/"'s within a link
|
" collapse repeated leading "/"'s within a link
|
||||||
|
@ -380,12 +380,16 @@ function! s:tag_wikiincl(value) "{{{
|
|||||||
echom string(link_infos)
|
echom string(link_infos)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let url = link_infos.filename
|
if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary'
|
||||||
|
let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'),
|
||||||
" strip the .html extension when we have wiki links, so that the user can
|
\ link_infos.filename)
|
||||||
" simply write {{image.png}} to include an image from the wiki directory
|
" strip the .html extension when we have wiki links, so that the user can
|
||||||
if link_infos.scheme =~# '\mwiki\d\+\|diary'
|
" simply write {{image.png}} to include an image from the wiki directory
|
||||||
let url = fnamemodify(url, ':r')
|
if link_infos.scheme =~# '\mwiki\d\+\|diary'
|
||||||
|
let url = fnamemodify(url, ':r')
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let url = link_infos.filename
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let url = escape(url, '#')
|
let url = escape(url, '#')
|
||||||
@ -412,16 +416,17 @@ function! s:tag_wikilink(value) "{{{
|
|||||||
if line == ''
|
if line == ''
|
||||||
let link_infos = vimwiki#base#resolve_link(url, s:current_wiki_file)
|
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
|
" external file links are always absolute
|
||||||
let html_link = link_infos.filename
|
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
|
else
|
||||||
" wiki links are always relative to the current file
|
" 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(
|
let html_link = vimwiki#path#relpath(
|
||||||
\ fnamemodify(s:current_wiki_file, ':h'),
|
\ fnamemodify(s:current_wiki_file, ':h'),
|
||||||
\ fnamemodify(link_infos.filename, ':r'))
|
\ fnamemodify(link_infos.filename, ':r'))
|
||||||
echom html_link
|
|
||||||
if html_link !~ '\m/$'
|
if html_link !~ '\m/$'
|
||||||
let html_link .= '.html'
|
let html_link .= '.html'
|
||||||
endif
|
endif
|
||||||
|
115
doc/vimwiki.txt
115
doc/vimwiki.txt
@ -755,7 +755,7 @@ To jump from that file back to the index file, use this link: >
|
|||||||
[[../index]]
|
[[../index]]
|
||||||
or: >
|
or: >
|
||||||
[[/index]]
|
[[/index]]
|
||||||
The latter works, because wiki links starting with "/" are considered to be
|
The latter works because wiki links starting with "/" are considered to be
|
||||||
absolute to the wiki root directory, that is, the link [[/index]] always opens
|
absolute to the wiki root directory, that is, the link [[/index]] always opens
|
||||||
the file /path/to/your/wiki/index.wiki, no matter in which subdirectory you
|
the file /path/to/your/wiki/index.wiki, no matter in which subdirectory you
|
||||||
are currently in.
|
are currently in.
|
||||||
@ -776,6 +776,13 @@ Raw URLs are also supported: >
|
|||||||
mailto:habamax@gmail.com
|
mailto:habamax@gmail.com
|
||||||
ftp://vim.org
|
ftp://vim.org
|
||||||
|
|
||||||
|
External files~
|
||||||
|
|
||||||
|
You can open arbitrary files like this: >
|
||||||
|
[[file:/important/documents/document.pdf]]
|
||||||
|
|
||||||
|
See |vimwiki-syntax-schemes|.
|
||||||
|
|
||||||
Anchors~
|
Anchors~
|
||||||
|
|
||||||
A URL can be followed by a '#' and the name of an anchor. When opening a
|
A URL can be followed by a '#' and the name of an anchor. When opening a
|
||||||
@ -826,11 +833,6 @@ as a wiki page.
|
|||||||
To scan the page for new or changed definitions for reference-links, simply
|
To scan the page for new or changed definitions for reference-links, simply
|
||||||
re-open the page ":e<CR>".
|
re-open the page ":e<CR>".
|
||||||
|
|
||||||
Typing wikilinks can be simplified by using Vim's omni completion (see
|
|
||||||
|compl-omni|) like so: >
|
|
||||||
[[ind<C-X><C-O>
|
|
||||||
which opens up a popup menu with all the wiki files starting with "ind".
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
5.3. Headers *vimwiki-syntax-headers*
|
5.3. Headers *vimwiki-syntax-headers*
|
||||||
|
|
||||||
@ -1114,24 +1116,24 @@ E.g.: >
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
5.12. Schemes *vimwiki-syntax-schemes*
|
5.12. Schemes *vimwiki-syntax-schemes*
|
||||||
|
|
||||||
In addition to standard web schemes (e.g. `http:`, `https:`, `ftp:`, etc.) a
|
In addition to standard web schemes (e.g. "http:", "https:", "ftp:", etc.) a
|
||||||
number of special schemes are supported: "wiki#:", "local:", "diary:",
|
number of special schemes are supported: "wikiX:", "diary:", "file:", "local:"
|
||||||
"file:", and schemeless.
|
and schemeless.
|
||||||
|
|
||||||
While "wiki:#", "diary" and schemeless links are automatically opened in Vi,
|
While "wikiX", "diary" and schemeless links are automatically opened in Vim,
|
||||||
all other links are opened with the system command. To customize this
|
all other links are opened with the system command. To customize this
|
||||||
behavior, see |VimwikiLinkHandler|.
|
behavior, see |VimwikiLinkHandler|.
|
||||||
|
|
||||||
Interwiki:~
|
Interwiki:~
|
||||||
|
|
||||||
If you maintain more than one wiki, you can create interwiki links between them
|
If you maintain more than one wiki, you can create interwiki links between them
|
||||||
by adding a numbered prefix "wiki#:" in front of a link: >
|
by adding a numbered prefix "wikiX:" in front of a link: >
|
||||||
[[wiki#:This is a link]]
|
[[wiki1:This is a link]]
|
||||||
or: >
|
or: >
|
||||||
[[wiki#:This is a link source|Description of the link]]
|
[[wiki1:This is a link source|Description of the link]]
|
||||||
|
|
||||||
The number "#", in the range 0..N-1, identifies the destination wiki in
|
The number behind "wiki" is in the range 0..N-1 and identifies the destination
|
||||||
|g:vimwiki_list|.
|
wiki in |g:vimwiki_list|.
|
||||||
|
|
||||||
Diary:~
|
Diary:~
|
||||||
|
|
||||||
@ -1142,32 +1144,27 @@ This scheme precludes explicit inclusion of |vimwiki-option-diary_rel_path|,
|
|||||||
and is most useful on subwiki pages to avoid links such as: >
|
and is most useful on subwiki pages to avoid links such as: >
|
||||||
[[../../diary/2012-03-05]]
|
[[../../diary/2012-03-05]]
|
||||||
|
|
||||||
Local:~
|
External files:~
|
||||||
|
|
||||||
A local resource that is not a wiki page may be specified with a path relative
|
The file and local schemes allow you to directly link to arbitray resources
|
||||||
to the current page: >
|
using absolute or relative paths with extension: >
|
||||||
[[local:../assets/data.csv|data (CSV)]]
|
[[file:/home/somebody/a/b/c/music.mp3]]
|
||||||
|
|
||||||
When followed or converted to HTML, extensions of local-scheme links are not
|
|
||||||
modified.
|
|
||||||
|
|
||||||
File:~
|
|
||||||
|
|
||||||
The file scheme allows you to directly link to arbitray resources using
|
|
||||||
absolute paths and extensions: >
|
|
||||||
[[file:///home/somebody/a/b/c/music.mp3]]
|
|
||||||
[[file:C:/Users/somebody/d/e/f/music.mp3]]
|
[[file:C:/Users/somebody/d/e/f/music.mp3]]
|
||||||
|
[[file:~/a/b/c/music.mp3]]
|
||||||
|
[[file:../assets/data.csv|data (CSV)]]
|
||||||
|
[[local:C:/Users/somebody/d/e/f/music.mp3]]
|
||||||
|
|
||||||
|
In Vim, "file:" and "local:" behave the same, i.e. you can use them with both
|
||||||
|
relative and absolute links. When converted to HTML, however, "file:" links
|
||||||
|
will become absolute links, while "local:" links become relative to the HTML
|
||||||
|
output directory. The latter can be useful if you copy your HTML files to
|
||||||
|
another computer.
|
||||||
|
To customize the HTML conversion of links, see |VimwikiLinkConverter|.
|
||||||
|
|
||||||
Schemeless:~
|
Schemeless:~
|
||||||
|
|
||||||
Schemeless URLs, which are the default, are treated internally as "wiki#:"
|
Schemeless URLs, which are the default, are treated internally as "wikiX:"
|
||||||
URLs in all respects except when converted to Html.
|
URLs in all respects, where X is the number of the current wiki.
|
||||||
|
|
||||||
Schemeless links convert to plain relative path URLs, nearly verbatim: >
|
|
||||||
relpath/wikipage.html
|
|
||||||
|
|
||||||
The "wiki#:", "local:", and "diary:" schemes use absolute paths as URLs: >
|
|
||||||
file:///abs_path_to_html#/relpath/wikipage.html
|
|
||||||
|
|
||||||
When |vimwiki-option-maxhi| equals 1, a distinct highlighting style is used to
|
When |vimwiki-option-maxhi| equals 1, a distinct highlighting style is used to
|
||||||
identify schemeless links whose targets are not found. All other links appear
|
identify schemeless links whose targets are not found. All other links appear
|
||||||
@ -1188,7 +1185,7 @@ relative, and need not end with an extension.
|
|||||||
The primary purpose for wiki-include links is to include images.
|
The primary purpose for wiki-include links is to include images.
|
||||||
|
|
||||||
Transclude from a local URL: >
|
Transclude from a local URL: >
|
||||||
{{local:../../images/vimwiki_logo.png}}
|
{{file:../../images/vimwiki_logo.png}}
|
||||||
or from a universal URL: >
|
or from a universal URL: >
|
||||||
{{http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png}}
|
{{http://vimwiki.googlecode.com/hg/images/vimwiki_logo.png}}
|
||||||
|
|
||||||
@ -2228,9 +2225,9 @@ wiki-include link or a weblink, is first passed to |VimwikiLinkHandler| to see
|
|||||||
if it can be handled. The return value 1/0 indicates success.
|
if it can be handled. The return value 1/0 indicates success.
|
||||||
|
|
||||||
If the link is not handled successfully, the behavior of Vimwiki depends on
|
If the link is not handled successfully, the behavior of Vimwiki depends on
|
||||||
the scheme. Wiki:, diary: or schemeless links are opened in Vim. All others,
|
the scheme. "wiki:", "diary:" or schemeless links are opened in Vim. "file:"
|
||||||
including local: and file: schemes, are opened with a system default handler;
|
and "local:" links are opened with a system default handler; i.e. Linux
|
||||||
i.e. Linux (!xdg-open), Mac (!open), and Windows (!start).
|
(!xdg-open), Mac (!open), and Windows (!start).
|
||||||
|
|
||||||
You can redefine |VimwikiLinkHandler| function to do something else: >
|
You can redefine |VimwikiLinkHandler| function to do something else: >
|
||||||
|
|
||||||
@ -2245,34 +2242,31 @@ You can redefine |VimwikiLinkHandler| function to do something else: >
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
A second example handles two new schemes, 'vlocal:' and 'vfile:', which behave
|
A second example handles a new scheme, 'vfile:', which behaves similar to
|
||||||
similar to 'local:' and 'file:' schemes, but are always opened with Vim: >
|
'file:', but the files are always opened with Vim: >
|
||||||
|
|
||||||
function! VimwikiLinkHandler(link) "{{{ Use Vim to open links with the
|
function! VimwikiLinkHandler(link)
|
||||||
" 'vlocal:' or 'vfile:' schemes. E.g.:
|
" Use Vim to open external files with the 'vfile:' scheme. E.g.:
|
||||||
" 1) [[vfile:///~/Code/PythonProject/abc123.py]], and
|
" 1) [[vfile:~/Code/PythonProject/abc123.py]]
|
||||||
" 2) [[vlocal:./|Wiki Home]]
|
" 2) [[vfile:./|Wiki Home]]
|
||||||
let link = a:link
|
let link = a:link
|
||||||
if link =~ "vlocal:" || link =~ "vfile:"
|
if link =~ "vfile:"
|
||||||
let link = link[1:]
|
let link = link[1:]
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let [idx, scheme, path, subdir, lnk, ext, url, anchor] =
|
let link_infos = vimwiki#base#resolve_link(link)
|
||||||
\ vimwiki#base#resolve_scheme(link, 0)
|
if link_infos.filename == ''
|
||||||
if g:vimwiki_debug
|
|
||||||
echom 'LinkHandler: idx='.idx.', scheme=[v]'.scheme.', path='.path.
|
|
||||||
\ ', subdir='.subdir.', lnk='.lnk.', ext='.ext.', url='.url.
|
|
||||||
\ ', anchor='.anchor
|
|
||||||
endif
|
|
||||||
if url == '' && anchor == ''
|
|
||||||
echom 'Vimwiki Error: Unable to resolve link!'
|
echom 'Vimwiki Error: Unable to resolve link!'
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
call vimwiki#base#edit_file('tabnew', url, anchor, [], 0)
|
exe 'tabnew ' . fnameescape(link_infos.filename)
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
endfunction " }}}
|
endfunction
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*VimwikiLinkConverter*
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
@ -2291,13 +2285,12 @@ cannot otherwise convert the link. A customized handler might look like this: >
|
|||||||
" complete URL
|
" complete URL
|
||||||
let url_0 = matchstr(str, g:vimwiki_rxWikiInclMatchUrl)
|
let url_0 = matchstr(str, g:vimwiki_rxWikiInclMatchUrl)
|
||||||
" URL parts
|
" URL parts
|
||||||
let [scheme, path, subdir, lnk, ext, url, anchor] =
|
let link_infos = vimwiki#base#resolve_link(url_0)
|
||||||
\ vimwiki#base#resolve_scheme(url_0, VimwikiGet('ext'))
|
|
||||||
let arg1 = matchstr(str, VimwikiWikiInclMatchArg(1))
|
let arg1 = matchstr(str, VimwikiWikiInclMatchArg(1))
|
||||||
let arg2 = matchstr(str, VimwikiWikiInclMatchArg(2))
|
let arg2 = matchstr(str, VimwikiWikiInclMatchArg(2))
|
||||||
|
|
||||||
if arg1 =~ '#'
|
if arg1 =~ '#'
|
||||||
return url.'#'.arg2
|
return link_infos.filename.'#'.arg2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Return the empty string when unable to process link
|
" Return the empty string when unable to process link
|
||||||
@ -2624,7 +2617,7 @@ Vim plugins: http://www.vim.org/scripts/script.php?script_id=2226
|
|||||||
|
|
||||||
???~
|
???~
|
||||||
|
|
||||||
* Spport for |g:vimwiki_auto_chdir| option.
|
* Support for |g:vimwiki_auto_chdir| option.
|
||||||
* Support for anchors, see |vimwiki-anchors|
|
* Support for anchors, see |vimwiki-anchors|
|
||||||
* in this context, add support for TOC, see |vimwiki-toc|
|
* in this context, add support for TOC, see |vimwiki-toc|
|
||||||
* remove the now useless %toc placeholder
|
* remove the now useless %toc placeholder
|
||||||
|
@ -365,9 +365,15 @@ if !exists("*VimwikiLinkHandler") "{{{
|
|||||||
endfunction
|
endfunction
|
||||||
endif "}}}
|
endif "}}}
|
||||||
|
|
||||||
|
if !exists("*VimwikiLinkConverter") "{{{
|
||||||
|
function VimwikiLinkConverter(url, source, target)
|
||||||
|
" Return the empty string when unable to process link
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
endif "}}}
|
||||||
|
|
||||||
if !exists("*VimwikiWikiIncludeHandler") "{{{
|
if !exists("*VimwikiWikiIncludeHandler") "{{{
|
||||||
function! VimwikiWikiIncludeHandler(value) "{{{
|
function! VimwikiWikiIncludeHandler(value) "{{{
|
||||||
" Return the empty string when unable to process link
|
|
||||||
return ''
|
return ''
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
endif "}}}
|
endif "}}}
|
||||||
|
Loading…
Reference in New Issue
Block a user