Fix resolution of leading-slash links, add link tests (#1108)

Hopefully this solves #1084, "Page links with leading slash lead to a
file in working directory, not a page at the root of the wiki", introduced
in 850aace.

It also adds a set of tests for different kinds of wiki links:

  - api_base_resolve_link.vader
  - link_syntax_markdown.vader
  - link_syntax_vimwiki.vader

Includes some fixes for locally-failing tests, removes a test from
test/map.vader and comments out test/config_vars.vader entirely for the
moment.

Code by : Brennen Bearnes <code@p1k3.com>
This commit is contained in:
Brennen Bearnes
2021-04-06 20:09:37 -06:00
committed by GitHub
parent 618893be00
commit f396e8a494
17 changed files with 484 additions and 124 deletions
+9 -6
View File
@@ -187,19 +187,20 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
endif
endif
" Check if absolute or relative path
" TODO Clean that => just one call
let is_absolute = 0
if vimwiki#path#is_absolute(link_text)
let is_absolute = 1
let link_text = expand(link_text)
endif
" This gets set for leading // links, which point to an absolute path to a
" wiki page (minus the .md or .wiki extension):
let is_absolute_wiki_link = 0
if is_wiki_link && link_text[0] ==# '/'
if link_text !=# '/'
if link_text !=# '//' && link_text[0:1] ==# '//'
let link_text = resolve(expand(link_text))
let link_text = link_text[2:]
let is_absolute = 1
let is_absolute_wiki_link = 1
else
let link_text = link_text[1:]
endif
@@ -246,7 +247,9 @@ function! vimwiki#base#resolve_link(link_text, ...) abort
endif
endif
if is_absolute
if is_absolute_wiki_link
" Leading // link to the absolute path of a wiki page somewhere on the
" filesystem.
let root_dir = ''
elseif !is_relative || link_infos.index != source_wiki
let root_dir = vimwiki#vars#get_wikilocal('path', link_infos.index)
+1 -1
View File
@@ -213,7 +213,7 @@ function! vimwiki#path#is_absolute(path) abort
let res += a:path =~# '\m^/\|\~/'
endif
" Do not prepent root_path to scp files
" Do not prepend root_path to scp files
" See: https://vim.fandom.com/wiki/Editing_remote_files_via_scp_in_vim
let res += a:path =~# '\m^scp:'