vimwiki-backup / vimwiki

Automatically exported from code.google.com/p/vimwiki
1 stars 1 forks source link

relative link to arbitrary file in html conversions #411

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I like vim wiki for taking notes and linking files. But I also like the easy 
way to convert the wiki into static HTML that I can easily publish.
I used it for many years but decided to update the old version I had for the 
last one. I managed to update all my syntax etc.

However I could not figure how to link an arbitrary file from a static 
directory as I was doing with previously.

I tried many 'schemes':
   [[file:URL]] does not add the server address into the url 
   [[local:URL]] add my local disk path
   {{URL}} consider only images
   [[URL]] adds a .html at the end
   [[URL/]] adds a / at the end but almost do what I need.

in other words none of the schemes I tried converted the link as follow:
[[<scheme>:URL]] into http://BASE/URL (with the appropriate html syntax)

I managed to hack something, but I'd rather the proper way to do this (if any). 

Below is the patch corresponding to what I did to define a 'remote:' which may 
not be the best name:

diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
index ad99ba8..5707faa 100644
--- a/autoload/vimwiki/base.vim
+++ b/autoload/vimwiki/base.vim
@@ -329,7 +329,7 @@ function! vimwiki#base#resolve_scheme(lnk, as_html) " {{{ 
Resolve scheme

   " do nothing if scheme is unknown to vimwiki
   if !(scheme =~ 'wiki.*' || scheme =~ 'diary' || scheme =~ 'local'
-        \ || scheme =~ 'file')
+        \ || scheme =~ 'file' || scheme =~ 'remote')
     return [idx, scheme, path, subdir, lnk, ext, scheme.':'.lnk]
   endif

@@ -415,6 +415,18 @@ function! vimwiki#base#resolve_scheme(lnk, as_html) " {{{ 
Resolve scheme
     endif
     let lnk = fnamemodify(lnk, ":p:t")
     let subdir = ''
+  elseif scheme =~ 'remote'
+    " RM repeated leading "/"'s within a link
+    let lnk = substitute(lnk, '^/*', '/', '')
+    " convert "/~..." into "~..." for fnamemodify
+    let lnk = substitute(lnk, '^/\~', '\~', '')
+    " convert /C: to C: (or fnamemodify(...":p:h") interpret it as C:\C:
+    if vimwiki#u#is_windows()
+      let lnk = substitute(lnk, '^/\ze[[:alpha:]]:', '', '')
+    endif
+    let path = fnamemodify(lnk, ":p:h").'/'
+    let lnk = fnamemodify(lnk, ":p:t")
+    let subdir = ''
   endif

diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim
index 95d85d5..4eb53ed 100644
--- a/plugin/vimwiki.vim
+++ b/plugin/vimwiki.vim
@@ -413,7 +413,7 @@ call s:default('current_idx', 0)
 " cause users should be able to <leader>w<leader>w without opening any
 " vimwiki file first
 " Scheme regexes {{{
-call s:default('schemes', 'wiki\d\+,diary,local')
+call s:default('schemes', 'wiki\d\+,diary,local,remote')
 call s:default('web_schemes1', 'http,https,file,ftp,gopher,telnet,nntp,ldap,'.
         \ 'rsync,imap,pop,irc,ircs,cvs,svn,svn+ssh,git,ssh,fish,sftp')
 call s:default('web_schemes2', 'mailto,news,xmpp,sip,sips,doi,urn,tel')

Original issue reported on code.google.com by morgan.f...@gmail.com on 23 Apr 2013 at 1:47