commit 61a6ce668621359056d4b252ca8fbc6d1e3d2534
parent d34abf9fa5bba6e9232a8d865baeff2a87210014
Author: Levi Rizki Saputra <42236775+levirs565@users.noreply.github.com>
Date: Fri, 5 Feb 2021 18:58:02 +0700
Fix Renaming and HTML Exporting Issue (#1057)
On Windows.
Commits squashed from first to be committed to most recent:
* fix subdir not correct when path using `\`
* fix slice by variable value not supported in vim 7.3
* remove last '\' from path in CustomWiki2HTML
* fix CSS path in CustomWiki2HTML wrong
* remove unused confirm CustomWiki2HTML
* use ==# rather than == in shellescape html.vim
* remove "FIXME this can terminate in the middle of a path component! from
base#subdir
* update doc/vimwiki.txt
* update contributor to doc/vimwiki.txt
* add comment in html#shellescape
Diffstat:
3 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -62,12 +62,18 @@ function! vimwiki#base#subdir(path, filename) abort
let filename = a:filename
endif
let idx = 0
- "FIXME this can terminate in the middle of a path component!
- while path[idx] ==? filename[idx]
+ let pathelement = split(path, '[/\\]')
+ let fileelement = split(filename, '[/\\]')
+ let minlen = min([len(pathelement), len(fileelement)])
+ let p = fileelement[:]
+ while pathelement[idx] ==? fileelement[idx]
+ let p = p[1:]
let idx = idx + 1
+ if idx == minlen
+ break
+ endif
endwhile
- let p = split(strpart(filename, idx), '[/\\]')
let res = join(p[:-2], '/')
if len(res) > 0
let res = res.'/'
diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim
@@ -1679,26 +1679,34 @@ function! s:use_custom_wiki2html() abort
\ (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html))
endfunction
+function! s:shellescape(str) abort
+ let result = a:str
+ "" This fix CustomWiki2HTML at root dir problem in Windows
+ if result[len(result) - 1] ==# '\'
+ let result = result[:-2]
+ endif
+ return shellescape(result)
+endfunction
-function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) abort
+function! vimwiki#html#CustomWiki2HTML(root_path, path, wikifile, force) abort
call vimwiki#path#mkdir(a:path)
let output = system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '.
\ a:force. ' '.
\ vimwiki#vars#get_wikilocal('syntax'). ' '.
\ strpart(vimwiki#vars#get_wikilocal('ext'), 1). ' '.
- \ shellescape(a:path). ' '.
- \ shellescape(a:wikifile). ' '.
- \ shellescape(s:default_CSS_full_name(a:path)). ' '.
+ \ s:shellescape(a:path). ' '.
+ \ s:shellescape(a:wikifile). ' '.
+ \ s:shellescape(s:default_CSS_full_name(a:root_path)). ' '.
\ (len(vimwiki#vars#get_wikilocal('template_path')) > 1 ?
- \ shellescape(expand(vimwiki#vars#get_wikilocal('template_path'))) : '-'). ' '.
+ \ s:shellescape(expand(vimwiki#vars#get_wikilocal('template_path'))) : '-'). ' '.
\ (len(vimwiki#vars#get_wikilocal('template_default')) > 0 ?
\ vimwiki#vars#get_wikilocal('template_default') : '-'). ' '.
\ (len(vimwiki#vars#get_wikilocal('template_ext')) > 0 ?
\ vimwiki#vars#get_wikilocal('template_ext') : '-'). ' '.
\ (len(vimwiki#vars#get_bufferlocal('subdir')) > 0 ?
- \ shellescape(s:root_path(vimwiki#vars#get_bufferlocal('subdir'))) : '-'). ' '.
+ \ s:shellescape(s:root_path(vimwiki#vars#get_bufferlocal('subdir'))) : '-'). ' '.
\ (len(vimwiki#vars#get_wikilocal('custom_wiki2html_args')) > 0 ?
- \ vimwiki#vars#get_wikilocal('custom_wiki2html_args') : '-'))
+ \ vimwiki#vars#get_wikilocal('custom_wiki2html_args') : '-'))
" Print if non void
if output !~? '^\s*$'
call vimwiki#u#echo(string(output))
@@ -1850,13 +1858,14 @@ endfunction
function! s:convert_file(path_html, wikifile) abort
let done = 0
+ let root_path_html = a:path_html
let wikifile = fnamemodify(a:wikifile, ':p')
let path_html = expand(a:path_html).vimwiki#vars#get_bufferlocal('subdir')
let htmlfile = fnamemodify(wikifile, ':t:r').'.html'
if s:use_custom_wiki2html()
let force = 1
- call vimwiki#html#CustomWiki2HTML(path_html, wikifile, force)
+ call vimwiki#html#CustomWiki2HTML(root_path_html, path_html, wikifile, force)
let done = 1
return path_html . htmlfile
endif
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
@@ -3892,6 +3892,7 @@ Contributors and their Github usernames in roughly chronological order:
- Amit Beka (@amitbeka)
- Yuuy Wei
- Yifan Hu (@yhu266)
+ - Levi Rizki Saputra (@levirs565)
==============================================================================
16. Changelog *vimwiki-changelog*
@@ -3946,6 +3947,8 @@ New:~
Changed:~
* PR #1047: Allow to replace default mapping of VimwikiToggleListItem
* VimwikiCheckLinks work on current wiki or on range
+ * PR #1057: Change how resolve subdir work
+ Change how shell escaping work when using CustomWiki2HTML
Removed:~
@@ -3977,6 +3980,8 @@ Fixed:~
* PR #959: Fix :VimwikiNextTask
* PR #986: Fix typo in help file
* PR #1030: Allow overwriting insert mode mappings
+ * PR #1057: Fix renaming, updating link, and exporting HTML subdir wrong
+ Fix resolve subdir return wrong path in Windows
2.5 (2020-05-26)~