Stylistic changes to pass vint tests.
Two non-stylistic errors were also fixed: 1. Removed duplicate function with invalid argument usage 2. Added missing quotes to a function call argument
This commit is contained in:
@ -4,30 +4,30 @@
|
||||
" Home: https://github.com/vimwiki/vimwiki/
|
||||
|
||||
|
||||
if exists("g:loaded_vimwiki_html_auto") || &cp
|
||||
if exists('g:loaded_vimwiki_html_auto') || &compatible
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_html_auto = 1
|
||||
|
||||
|
||||
function! s:root_path(subdir)
|
||||
function! s:root_path(subdir) abort
|
||||
return repeat('../', len(split(a:subdir, '[/\\]')))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:syntax_supported()
|
||||
return vimwiki#vars#get_wikilocal('syntax') ==? "default"
|
||||
function! s:syntax_supported() abort
|
||||
return vimwiki#vars#get_wikilocal('syntax') ==? 'default'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:remove_blank_lines(lines)
|
||||
function! s:remove_blank_lines(lines) abort
|
||||
while !empty(a:lines) && a:lines[-1] =~# '^\s*$'
|
||||
call remove(a:lines, -1)
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:is_web_link(lnk)
|
||||
function! s:is_web_link(lnk) abort
|
||||
if a:lnk =~# '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)'
|
||||
return 1
|
||||
endif
|
||||
@ -35,7 +35,7 @@ function! s:is_web_link(lnk)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:is_img_link(lnk)
|
||||
function! s:is_img_link(lnk) abort
|
||||
if tolower(a:lnk) =~# '\.\%(png\|jpg\|gif\|jpeg\)$'
|
||||
return 1
|
||||
endif
|
||||
@ -43,7 +43,7 @@ function! s:is_img_link(lnk)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:has_abs_path(fname)
|
||||
function! s:has_abs_path(fname) abort
|
||||
if a:fname =~# '\(^.:\)\|\(^/\)'
|
||||
return 1
|
||||
endif
|
||||
@ -51,10 +51,10 @@ function! s:has_abs_path(fname)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:find_autoload_file(name)
|
||||
function! s:find_autoload_file(name) abort
|
||||
for path in split(&runtimepath, ',')
|
||||
let fname = path.'/autoload/vimwiki/'.a:name
|
||||
if glob(fname) != ''
|
||||
if glob(fname) !=? ''
|
||||
return fname
|
||||
endif
|
||||
endfor
|
||||
@ -62,19 +62,19 @@ function! s:find_autoload_file(name)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:default_CSS_full_name(path)
|
||||
function! s:default_CSS_full_name(path) abort
|
||||
let path = expand(a:path)
|
||||
let css_full_name = path . vimwiki#vars#get_wikilocal('css_name')
|
||||
return css_full_name
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:create_default_CSS(path)
|
||||
function! s:create_default_CSS(path) abort
|
||||
let css_full_name = s:default_CSS_full_name(a:path)
|
||||
if glob(css_full_name) == ""
|
||||
if glob(css_full_name) ==? ''
|
||||
call vimwiki#path#mkdir(fnamemodify(css_full_name, ':p:h'))
|
||||
let default_css = s:find_autoload_file('style.css')
|
||||
if default_css != ''
|
||||
if default_css !=? ''
|
||||
let lines = readfile(default_css)
|
||||
call writefile(lines, css_full_name)
|
||||
return 1
|
||||
@ -84,8 +84,8 @@ function! s:create_default_CSS(path)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:template_full_name(name)
|
||||
if a:name == ''
|
||||
function! s:template_full_name(name) abort
|
||||
if a:name ==? ''
|
||||
let name = vimwiki#vars#get_wikilocal('template_default')
|
||||
else
|
||||
let name = a:name
|
||||
@ -102,11 +102,11 @@ function! s:template_full_name(name)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_html_template(template)
|
||||
function! s:get_html_template(template) abort
|
||||
" TODO: refactor it!!!
|
||||
let lines=[]
|
||||
|
||||
if a:template != ''
|
||||
if a:template !=? ''
|
||||
let template_name = s:template_full_name(a:template)
|
||||
try
|
||||
let lines = readfile(template_name)
|
||||
@ -118,7 +118,7 @@ function! s:get_html_template(template)
|
||||
|
||||
let default_tpl = s:template_full_name('')
|
||||
|
||||
if default_tpl == ''
|
||||
if default_tpl ==? ''
|
||||
let default_tpl = s:find_autoload_file('default.tpl')
|
||||
endif
|
||||
|
||||
@ -127,19 +127,19 @@ function! s:get_html_template(template)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:safe_html_preformatted(line)
|
||||
function! s:safe_html_preformatted(line) abort
|
||||
let line = substitute(a:line,'<','\<', 'g')
|
||||
let line = substitute(line,'>','\>', 'g')
|
||||
return line
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:escape_html_attribute(string)
|
||||
function! s:escape_html_attribute(string) abort
|
||||
return substitute(a:string, '"', '\"', 'g')
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:safe_html_line(line)
|
||||
function! s:safe_html_line(line) abort
|
||||
" escape & < > when producing HTML text
|
||||
" s:lt_pattern, s:gt_pattern depend on g:vimwiki_valid_html_tags
|
||||
" and are set in vimwiki#html#Wiki2HTML()
|
||||
@ -151,18 +151,18 @@ function! s:safe_html_line(line)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:delete_html_files(path)
|
||||
function! s:delete_html_files(path) abort
|
||||
let htmlfiles = split(glob(a:path.'**/*.html'), '\n')
|
||||
for fname in htmlfiles
|
||||
" ignore user html files, e.g. search.html,404.html
|
||||
if stridx(vimwiki#vars#get_global('user_htmls'), fnamemodify(fname, ":t")) >= 0
|
||||
if stridx(vimwiki#vars#get_global('user_htmls'), fnamemodify(fname, ':t')) >= 0
|
||||
continue
|
||||
endif
|
||||
|
||||
" delete if there is no corresponding wiki file
|
||||
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path_html'), fname)
|
||||
let wikifile = vimwiki#vars#get_wikilocal('path').subdir.
|
||||
\fnamemodify(fname, ":t:r").vimwiki#vars#get_wikilocal('ext')
|
||||
\fnamemodify(fname, ':t:r').vimwiki#vars#get_wikilocal('ext')
|
||||
if filereadable(wikifile)
|
||||
continue
|
||||
endif
|
||||
@ -176,22 +176,22 @@ function! s:delete_html_files(path)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:mid(value, cnt)
|
||||
function! s:mid(value, cnt) abort
|
||||
return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:subst_func(line, regexp, func, ...)
|
||||
function! s:subst_func(line, regexp, func, ...) abort
|
||||
" Substitute text found by regexp with result of
|
||||
" func(matched) function.
|
||||
|
||||
let pos = 0
|
||||
let lines = split(a:line, a:regexp, 1)
|
||||
let res_line = ""
|
||||
let res_line = ''
|
||||
for line in lines
|
||||
let res_line = res_line.line
|
||||
let matched = matchstr(a:line, a:regexp, pos)
|
||||
if matched != ""
|
||||
if matched !=? ''
|
||||
if a:0
|
||||
let res_line = res_line.{a:func}(matched, a:1)
|
||||
else
|
||||
@ -204,7 +204,7 @@ function! s:subst_func(line, regexp, func, ...)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_date(placeholders, default_date)
|
||||
function! s:process_date(placeholders, default_date) abort
|
||||
if !empty(a:placeholders)
|
||||
for [placeholder, row, idx] in a:placeholders
|
||||
let [type, param] = placeholder
|
||||
@ -217,7 +217,7 @@ function! s:process_date(placeholders, default_date)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_title(placeholders, default_title)
|
||||
function! s:process_title(placeholders, default_title) abort
|
||||
if !empty(a:placeholders)
|
||||
for [placeholder, row, idx] in a:placeholders
|
||||
let [type, param] = placeholder
|
||||
@ -230,15 +230,15 @@ function! s:process_title(placeholders, default_title)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:is_html_uptodate(wikifile)
|
||||
function! s:is_html_uptodate(wikifile) abort
|
||||
let tpl_time = -1
|
||||
|
||||
let tpl_file = s:template_full_name('')
|
||||
if tpl_file != ''
|
||||
if tpl_file !=? ''
|
||||
let tpl_time = getftime(tpl_file)
|
||||
endif
|
||||
|
||||
let wikifile = fnamemodify(a:wikifile, ":p")
|
||||
let wikifile = fnamemodify(a:wikifile, ':p')
|
||||
|
||||
if vimwiki#vars#get_wikilocal('html_filename_parameterization')
|
||||
let parameterized_wikiname = s:parameterized_wikiname(wikifile)
|
||||
@ -246,7 +246,7 @@ function! s:is_html_uptodate(wikifile)
|
||||
\ vimwiki#vars#get_bufferlocal('subdir') . parameterized_wikiname)
|
||||
else
|
||||
let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') .
|
||||
\ vimwiki#vars#get_bufferlocal('subdir') . fnamemodify(wikifile, ":t:r").".html")
|
||||
\ vimwiki#vars#get_bufferlocal('subdir') . fnamemodify(wikifile, ':t:r').'.html')
|
||||
endif
|
||||
|
||||
if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile)
|
||||
@ -255,17 +255,17 @@ function! s:is_html_uptodate(wikifile)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:parameterized_wikiname(wikifile)
|
||||
let initial = fnamemodify(a:wikifile, ":t:r")
|
||||
function! s:parameterized_wikiname(wikifile) abort
|
||||
let initial = fnamemodify(a:wikifile, ':t:r')
|
||||
let lower_sanitized = tolower(initial)
|
||||
let substituted = substitute(lower_sanitized, '[^a-z0-9_-]\+',"-", "g")
|
||||
let substituted = substitute(substituted, '\-\+',"-", "g")
|
||||
let substituted = substitute(substituted, '^-', '', "g")
|
||||
let substituted = substitute(substituted, '-$', '', "g")
|
||||
return substitute(substituted, '\-\+',"-", "g") . ".html"
|
||||
let substituted = substitute(lower_sanitized, '[^a-z0-9_-]\+','-', 'g')
|
||||
let substituted = substitute(substituted, '\-\+','-', 'g')
|
||||
let substituted = substitute(substituted, '^-', '', 'g')
|
||||
let substituted = substitute(substituted, '-$', '', 'g')
|
||||
return substitute(substituted, '\-\+','-', 'g') . '.html'
|
||||
endfunction
|
||||
|
||||
function! s:html_insert_contents(html_lines, content)
|
||||
function! s:html_insert_contents(html_lines, content) abort
|
||||
let lines = []
|
||||
for line in a:html_lines
|
||||
if line =~# '%content%'
|
||||
@ -288,27 +288,27 @@ function! s:html_insert_contents(html_lines, content)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_eqin(value)
|
||||
function! s:tag_eqin(value) abort
|
||||
" mathJAX wants \( \) for inline maths
|
||||
return '\('.s:mid(a:value, 1).'\)'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_em(value)
|
||||
function! s:tag_em(value) abort
|
||||
return '<em>'.s:mid(a:value, 1).'</em>'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_strong(value, header_ids)
|
||||
function! s:tag_strong(value, header_ids) abort
|
||||
let text = s:mid(a:value, 1)
|
||||
let id = s:escape_html_attribute(text)
|
||||
let complete_id = ''
|
||||
for l in range(6)
|
||||
if a:header_ids[l][0] != ''
|
||||
if a:header_ids[l][0] !=? ''
|
||||
let complete_id .= a:header_ids[l][0].'-'
|
||||
endif
|
||||
endfor
|
||||
if a:header_ids[5][0] == ''
|
||||
if a:header_ids[5][0] ==? ''
|
||||
let complete_id = complete_id[:-2]
|
||||
endif
|
||||
let complete_id .= '-'.id
|
||||
@ -317,14 +317,14 @@ function! s:tag_strong(value, header_ids)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_tags(value, header_ids)
|
||||
function! s:tag_tags(value, header_ids) abort
|
||||
let complete_id = ''
|
||||
for level in range(6)
|
||||
if a:header_ids[level][0] != ''
|
||||
if a:header_ids[level][0] !=? ''
|
||||
let complete_id .= a:header_ids[level][0].'-'
|
||||
endif
|
||||
endfor
|
||||
if a:header_ids[5][0] == ''
|
||||
if a:header_ids[5][0] ==? ''
|
||||
let complete_id = complete_id[:-2]
|
||||
endif
|
||||
let complete_id = s:escape_html_attribute(complete_id)
|
||||
@ -339,44 +339,44 @@ function! s:tag_tags(value, header_ids)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_todo(value)
|
||||
function! s:tag_todo(value) abort
|
||||
return '<span class="todo">'.a:value.'</span>'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_strike(value)
|
||||
function! s:tag_strike(value) abort
|
||||
return '<del>'.s:mid(a:value, 2).'</del>'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_super(value)
|
||||
function! s:tag_super(value) abort
|
||||
return '<sup><small>'.s:mid(a:value, 1).'</small></sup>'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_sub(value)
|
||||
function! s:tag_sub(value) abort
|
||||
return '<sub><small>'.s:mid(a:value, 2).'</small></sub>'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_code(value)
|
||||
function! s:tag_code(value) abort
|
||||
let l:retstr = '<code'
|
||||
|
||||
let l:str = s:mid(a:value, 1)
|
||||
let l:match = match(l:str, '^#[a-fA-F0-9]\{6\}$')
|
||||
|
||||
if l:match != -1
|
||||
let l:r = eval("0x".l:str[1:2])
|
||||
let l:g = eval("0x".l:str[3:4])
|
||||
let l:b = eval("0x".l:str[5:6])
|
||||
let l:r = eval('0x'.l:str[1:2])
|
||||
let l:g = eval('0x'.l:str[3:4])
|
||||
let l:b = eval('0x'.l:str[5:6])
|
||||
|
||||
let l:fg_color =
|
||||
\ (((0.299 * r + 0.587 * g + 0.114 * b) / 0xFF) > 0.5)
|
||||
\ ? "black" : "white"
|
||||
\ ? 'black' : 'white'
|
||||
|
||||
let l:retstr .=
|
||||
\ " style='background-color:" . l:str .
|
||||
\ ";color:" . l:fg_color . ";'"
|
||||
\ ';color:' . l:fg_color . ";'"
|
||||
endif
|
||||
|
||||
let l:retstr .= '>'.s:safe_html_preformatted(l:str).'</code>'
|
||||
@ -386,7 +386,7 @@ endfunction
|
||||
|
||||
" match n-th ARG within {{URL[|ARG1|ARG2|...]}}
|
||||
" *c,d,e),...
|
||||
function! s:incl_match_arg(nn_index)
|
||||
function! s:incl_match_arg(nn_index) abort
|
||||
let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl')
|
||||
let rx = rx . repeat(vimwiki#vars#get_global('rxWikiInclSeparator') .
|
||||
\ vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1)
|
||||
@ -400,10 +400,10 @@ function! s:incl_match_arg(nn_index)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:linkify_link(src, descr)
|
||||
function! s:linkify_link(src, descr) abort
|
||||
let src_str = ' href="'.s:escape_html_attribute(a:src).'"'
|
||||
let descr = vimwiki#u#trim(a:descr)
|
||||
let descr = (descr == "" ? a:src : descr)
|
||||
let descr = (descr ==? '' ? a:src : descr)
|
||||
let descr_str = (descr =~# vimwiki#vars#get_global('rxWikiIncl')
|
||||
\ ? s:tag_wikiincl(descr)
|
||||
\ : descr)
|
||||
@ -411,15 +411,15 @@ function! s:linkify_link(src, descr)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:linkify_image(src, descr, verbatim_str)
|
||||
function! s:linkify_image(src, descr, verbatim_str) abort
|
||||
let src_str = ' src="'.a:src.'"'
|
||||
let descr_str = (a:descr != '' ? ' alt="'.a:descr.'"' : '')
|
||||
let verbatim_str = (a:verbatim_str != '' ? ' '.a:verbatim_str : '')
|
||||
let descr_str = (a:descr !=? '' ? ' alt="'.a:descr.'"' : '')
|
||||
let verbatim_str = (a:verbatim_str !=? '' ? ' '.a:verbatim_str : '')
|
||||
return '<img'.src_str.descr_str.verbatim_str.' />'
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_weblink(value)
|
||||
function! s:tag_weblink(value) abort
|
||||
" Weblink Template -> <a href="url">descr</a>
|
||||
let str = a:value
|
||||
let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
|
||||
@ -429,7 +429,7 @@ function! s:tag_weblink(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_wikiincl(value)
|
||||
function! s:tag_wikiincl(value) abort
|
||||
" {{imgurl|arg1|arg2}} -> ???
|
||||
" {{imgurl}} -> <img src="imgurl"/>
|
||||
" {{imgurl|descr|style="A"}} -> <img src="imgurl" alt="descr" style="A" />
|
||||
@ -438,7 +438,7 @@ function! s:tag_wikiincl(value)
|
||||
" custom transclusions
|
||||
let line = VimwikiWikiIncludeHandler(str)
|
||||
" otherwise, assume image transclusion
|
||||
if line == ''
|
||||
if line ==? ''
|
||||
let url_0 = matchstr(str, vimwiki#vars#get_global('rxWikiInclMatchUrl'))
|
||||
let descr = matchstr(str, s:incl_match_arg(1))
|
||||
let verbatim_str = matchstr(str, s:incl_match_arg(2))
|
||||
@ -463,7 +463,7 @@ function! s:tag_wikiincl(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_wikilink(value)
|
||||
function! s:tag_wikilink(value) abort
|
||||
" [[url]] -> <a href="url.html">url</a>
|
||||
" [[url|descr]] -> <a href="url.html">descr</a>
|
||||
" [[url|{{...}}]] -> <a href="url.html"> ... </a>
|
||||
@ -475,10 +475,10 @@ function! s:tag_wikilink(value)
|
||||
let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
|
||||
let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'))
|
||||
let descr = vimwiki#u#trim(descr)
|
||||
let descr = (descr != '' ? descr : url)
|
||||
let descr = (descr !=? '' ? descr : url)
|
||||
|
||||
let line = VimwikiLinkConverter(url, s:current_wiki_file, s:current_html_file)
|
||||
if line == ''
|
||||
if line ==? ''
|
||||
let link_infos = vimwiki#base#resolve_link(url, s:current_wiki_file)
|
||||
|
||||
if link_infos.scheme ==# 'file'
|
||||
@ -492,14 +492,14 @@ function! s:tag_wikilink(value)
|
||||
let html_link = vimwiki#path#relpath(
|
||||
\ fnamemodify(s:current_wiki_file, ':h'),
|
||||
\ fnamemodify(link_infos.filename, ':r'))
|
||||
if html_link !~ '\m/$'
|
||||
if html_link !~? '\m/$'
|
||||
let html_link .= '.html'
|
||||
endif
|
||||
else " other schemes, like http, are left untouched
|
||||
let html_link = link_infos.filename
|
||||
endif
|
||||
|
||||
if link_infos.anchor != ''
|
||||
if link_infos.anchor !=? ''
|
||||
let anchor = substitute(link_infos.anchor, '#', '-', 'g')
|
||||
let html_link .= '#'.anchor
|
||||
endif
|
||||
@ -511,19 +511,19 @@ function! s:tag_wikilink(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_remove_internal_link(value)
|
||||
function! s:tag_remove_internal_link(value) abort
|
||||
let value = s:mid(a:value, 2)
|
||||
|
||||
let line = ''
|
||||
if value =~# '|'
|
||||
let link_parts = split(value, "|", 1)
|
||||
let link_parts = split(value, '|', 1)
|
||||
else
|
||||
let link_parts = split(value, "][", 1)
|
||||
let link_parts = split(value, '][', 1)
|
||||
endif
|
||||
|
||||
if len(link_parts) > 1
|
||||
if len(link_parts) < 3
|
||||
let style = ""
|
||||
let style = ''
|
||||
else
|
||||
let style = link_parts[2]
|
||||
endif
|
||||
@ -535,7 +535,7 @@ function! s:tag_remove_internal_link(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:tag_remove_external_link(value)
|
||||
function! s:tag_remove_external_link(value) abort
|
||||
let value = s:mid(a:value, 1)
|
||||
|
||||
let line = ''
|
||||
@ -543,7 +543,7 @@ function! s:tag_remove_external_link(value)
|
||||
let lnkElements = split(value)
|
||||
let head = lnkElements[0]
|
||||
let rest = join(lnkElements[1:])
|
||||
if rest == ""
|
||||
if rest ==? ''
|
||||
let rest = head
|
||||
endif
|
||||
let line = rest
|
||||
@ -558,7 +558,7 @@ function! s:tag_remove_external_link(value)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:make_tag(line, regexp, func, ...)
|
||||
function! s:make_tag(line, regexp, func, ...) abort
|
||||
" Make tags for a given matched regexp.
|
||||
" Exclude preformatted text and href links.
|
||||
" FIXME
|
||||
@ -584,7 +584,7 @@ function! s:make_tag(line, regexp, func, ...)
|
||||
" result:
|
||||
" ['hello world ', ' simple ', 'type of', ' prg']
|
||||
let lines = split(a:line, patt_splitter, 1)
|
||||
let res_line = ""
|
||||
let res_line = ''
|
||||
for line in lines
|
||||
if a:0
|
||||
let res_line = res_line.s:subst_func(line, a:regexp, a:func, a:1)
|
||||
@ -599,7 +599,7 @@ function! s:make_tag(line, regexp, func, ...)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tags_remove_links(line)
|
||||
function! s:process_tags_remove_links(line) abort
|
||||
let line = a:line
|
||||
let line = s:make_tag(line, '\[\[.\{-}\]\]', 's:tag_remove_internal_link')
|
||||
let line = s:make_tag(line, '\[.\{-}\]', 's:tag_remove_external_link')
|
||||
@ -607,7 +607,7 @@ function! s:process_tags_remove_links(line)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tags_typefaces(line, header_ids)
|
||||
function! s:process_tags_typefaces(line, header_ids) abort
|
||||
let line = a:line
|
||||
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxItalic'), 's:tag_em')
|
||||
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxBold'), 's:tag_strong', a:header_ids)
|
||||
@ -622,7 +622,7 @@ function! s:process_tags_typefaces(line, header_ids)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tags_links(line)
|
||||
function! s:process_tags_links(line) abort
|
||||
let line = a:line
|
||||
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWikiLink'), 's:tag_wikilink')
|
||||
let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiIncl'), 's:tag_wikiincl')
|
||||
@ -631,23 +631,23 @@ function! s:process_tags_links(line)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_inline_tags(line, header_ids)
|
||||
function! s:process_inline_tags(line, header_ids) abort
|
||||
let line = s:process_tags_links(a:line)
|
||||
let line = s:process_tags_typefaces(line, a:header_ids)
|
||||
return line
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_pre(pre, ldest)
|
||||
function! s:close_tag_pre(pre, ldest) abort
|
||||
if a:pre[0]
|
||||
call insert(a:ldest, "</pre>")
|
||||
call insert(a:ldest, '</pre>')
|
||||
return 0
|
||||
endif
|
||||
return a:pre
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_math(math, ldest)
|
||||
function! s:close_tag_math(math, ldest) abort
|
||||
if a:math[0]
|
||||
call insert(a:ldest, "\\\]")
|
||||
return 0
|
||||
@ -656,25 +656,25 @@ function! s:close_tag_math(math, ldest)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_quote(quote, ldest)
|
||||
function! s:close_tag_quote(quote, ldest) abort
|
||||
if a:quote
|
||||
call insert(a:ldest, "</blockquote>")
|
||||
call insert(a:ldest, '</blockquote>')
|
||||
return 0
|
||||
endif
|
||||
return a:quote
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_para(para, ldest)
|
||||
function! s:close_tag_para(para, ldest) abort
|
||||
if a:para
|
||||
call insert(a:ldest, "</p>")
|
||||
call insert(a:ldest, '</p>')
|
||||
return 0
|
||||
endif
|
||||
return a:para
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_table(table, ldest, header_ids)
|
||||
function! s:close_tag_table(table, ldest, header_ids) abort
|
||||
" The first element of table list is a string which tells us if table should be centered.
|
||||
" The rest elements are rows which are lists of columns:
|
||||
" ['center',
|
||||
@ -684,7 +684,7 @@ function! s:close_tag_table(table, ldest, header_ids)
|
||||
" ]
|
||||
" And CELLx is: { 'body': 'col_x', 'rowspan': r, 'colspan': c }
|
||||
|
||||
function! s:sum_rowspan(table)
|
||||
function! s:sum_rowspan(table) abort
|
||||
let table = a:table
|
||||
|
||||
" Get max cells
|
||||
@ -716,7 +716,7 @@ function! s:close_tag_table(table, ldest, header_ids)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:sum_colspan(table)
|
||||
function! s:sum_colspan(table) abort
|
||||
for row in a:table[1:]
|
||||
let cols = 1
|
||||
|
||||
@ -731,7 +731,7 @@ function! s:close_tag_table(table, ldest, header_ids)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:close_tag_row(row, header, ldest, header_ids)
|
||||
function! s:close_tag_row(row, header, ldest, header_ids) abort
|
||||
call add(a:ldest, '<tr>')
|
||||
|
||||
" Set tag element of columns
|
||||
@ -775,7 +775,7 @@ function! s:close_tag_table(table, ldest, header_ids)
|
||||
if table[0] ==# 'center'
|
||||
call add(ldest, "<table class='center'>")
|
||||
else
|
||||
call add(ldest, "<table>")
|
||||
call add(ldest, '<table>')
|
||||
endif
|
||||
|
||||
" Empty lists are table separators.
|
||||
@ -803,14 +803,14 @@ function! s:close_tag_table(table, ldest, header_ids)
|
||||
call s:close_tag_row(row, 0, ldest, a:header_ids)
|
||||
endfor
|
||||
endif
|
||||
call add(ldest, "</table>")
|
||||
call add(ldest, '</table>')
|
||||
let table = []
|
||||
endif
|
||||
return table
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_list(lists, ldest)
|
||||
function! s:close_tag_list(lists, ldest) abort
|
||||
while len(a:lists)
|
||||
let item = remove(a:lists, 0)
|
||||
call insert(a:ldest, item[0])
|
||||
@ -818,16 +818,16 @@ function! s:close_tag_list(lists, ldest)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:close_tag_def_list(deflist, ldest)
|
||||
function! s:close_tag_def_list(deflist, ldest) abort
|
||||
if a:deflist
|
||||
call insert(a:ldest, "</dl>")
|
||||
call insert(a:ldest, '</dl>')
|
||||
return 0
|
||||
endif
|
||||
return a:deflist
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_pre(line, pre)
|
||||
function! s:process_tag_pre(line, pre) abort
|
||||
" pre is the list of [is_in_pre, indent_of_pre]
|
||||
"XXX always outputs a single line or empty list!
|
||||
let lines = []
|
||||
@ -839,16 +839,16 @@ function! s:process_tag_pre(line, pre)
|
||||
let class = matchstr(a:line, '{{{\zs.*$')
|
||||
"FIXME class cannot contain arbitrary strings
|
||||
let class = substitute(class, '\s\+$', '', 'g')
|
||||
if class != ""
|
||||
call add(lines, "<pre ".class.">")
|
||||
if class !=? ''
|
||||
call add(lines, '<pre '.class.'>')
|
||||
else
|
||||
call add(lines, "<pre>")
|
||||
call add(lines, '<pre>')
|
||||
endif
|
||||
let pre = [1, len(matchstr(a:line, '^\s*\ze{{{'))]
|
||||
let processed = 1
|
||||
elseif pre[0] && a:line =~# '^\s*}}}\s*$'
|
||||
let pre = [0, 0]
|
||||
call add(lines, "</pre>")
|
||||
call add(lines, '</pre>')
|
||||
let processed = 1
|
||||
elseif pre[0]
|
||||
let processed = 1
|
||||
@ -860,7 +860,7 @@ function! s:process_tag_pre(line, pre)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_math(line, math)
|
||||
function! s:process_tag_math(line, math) abort
|
||||
" math is the list of [is_in_math, indent_of_math]
|
||||
let lines = []
|
||||
let math = a:math
|
||||
@ -872,9 +872,9 @@ function! s:process_tag_math(line, math)
|
||||
" store the environment name in a global variable in order to close the
|
||||
" environment properly
|
||||
let s:current_math_env = matchstr(class, '^%\zs\S\+\ze%')
|
||||
if s:current_math_env != ""
|
||||
if s:current_math_env !=? ''
|
||||
call add(lines, substitute(class, '^%\(\S\+\)%', '\\begin{\1}', ''))
|
||||
elseif class != ""
|
||||
elseif class !=? ''
|
||||
call add(lines, "\\\[".class)
|
||||
else
|
||||
call add(lines, "\\\[")
|
||||
@ -883,8 +883,8 @@ function! s:process_tag_math(line, math)
|
||||
let processed = 1
|
||||
elseif math[0] && a:line =~# '^\s*}}\$\s*$'
|
||||
let math = [0, 0]
|
||||
if s:current_math_env != ""
|
||||
call add(lines, "\\end{".s:current_math_env."}")
|
||||
if s:current_math_env !=? ''
|
||||
call add(lines, "\\end{".s:current_math_env.'}')
|
||||
else
|
||||
call add(lines, "\\\]")
|
||||
endif
|
||||
@ -897,28 +897,28 @@ function! s:process_tag_math(line, math)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_quote(line, quote)
|
||||
function! s:process_tag_quote(line, quote) abort
|
||||
let lines = []
|
||||
let quote = a:quote
|
||||
let processed = 0
|
||||
if a:line =~# '^\s\{4,}\S'
|
||||
if !quote
|
||||
call add(lines, "<blockquote>")
|
||||
call add(lines, '<blockquote>')
|
||||
let quote = 1
|
||||
endif
|
||||
let processed = 1
|
||||
call add(lines, substitute(a:line, '^\s*', '', ''))
|
||||
elseif quote
|
||||
call add(lines, "</blockquote>")
|
||||
call add(lines, '</blockquote>')
|
||||
let quote = 0
|
||||
endif
|
||||
return [processed, lines, quote]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_list(line, lists)
|
||||
function! s:process_tag_list(line, lists) abort
|
||||
|
||||
function! s:add_checkbox(line, rx_list)
|
||||
function! s:add_checkbox(line, rx_list) abort
|
||||
let st_tag = '<li>'
|
||||
let chk = matchlist(a:line, a:rx_list)
|
||||
if !empty(chk) && len(chk[1]) > 0
|
||||
@ -969,7 +969,7 @@ function! s:process_tag_list(line, lists)
|
||||
let lstRegExp = ''
|
||||
endif
|
||||
|
||||
if lstSym != ''
|
||||
if lstSym !=? ''
|
||||
" To get proper indent level 'retab' the line -- change all tabs
|
||||
" to spaces*tabstop
|
||||
let line = substitute(a:line, '\t', repeat(' ', &tabstop), 'g')
|
||||
@ -1015,55 +1015,55 @@ function! s:process_tag_list(line, lists)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_def_list(line, deflist)
|
||||
function! s:process_tag_def_list(line, deflist) abort
|
||||
let lines = []
|
||||
let deflist = a:deflist
|
||||
let processed = 0
|
||||
let matches = matchlist(a:line, '\(^.*\)::\%(\s\|$\)\(.*\)')
|
||||
if !deflist && len(matches) > 0
|
||||
call add(lines, "<dl>")
|
||||
call add(lines, '<dl>')
|
||||
let deflist = 1
|
||||
endif
|
||||
if deflist && len(matches) > 0
|
||||
if matches[1] != ''
|
||||
call add(lines, "<dt>".matches[1]."</dt>")
|
||||
if matches[1] !=? ''
|
||||
call add(lines, '<dt>'.matches[1].'</dt>')
|
||||
endif
|
||||
if matches[2] != ''
|
||||
call add(lines, "<dd>".matches[2]."</dd>")
|
||||
if matches[2] !=? ''
|
||||
call add(lines, '<dd>'.matches[2].'</dd>')
|
||||
endif
|
||||
let processed = 1
|
||||
elseif deflist
|
||||
let deflist = 0
|
||||
call add(lines, "</dl>")
|
||||
call add(lines, '</dl>')
|
||||
endif
|
||||
return [processed, lines, deflist]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_para(line, para)
|
||||
function! s:process_tag_para(line, para) abort
|
||||
let lines = []
|
||||
let para = a:para
|
||||
let processed = 0
|
||||
if a:line =~# '^\s\{,3}\S'
|
||||
if !para
|
||||
call add(lines, "<p>")
|
||||
call add(lines, '<p>')
|
||||
let para = 1
|
||||
endif
|
||||
let processed = 1
|
||||
if vimwiki#vars#get_global('text_ignore_newline')
|
||||
call add(lines, a:line)
|
||||
else
|
||||
call add(lines, a:line."<br />")
|
||||
call add(lines, a:line.'<br />')
|
||||
endif
|
||||
elseif para && a:line =~# '^\s*$'
|
||||
call add(lines, "</p>")
|
||||
call add(lines, '</p>')
|
||||
let para = 0
|
||||
endif
|
||||
return [processed, lines, para]
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_h(line, id)
|
||||
function! s:process_tag_h(line, id) abort
|
||||
let line = a:line
|
||||
let processed = 0
|
||||
let h_level = 0
|
||||
@ -1092,7 +1092,7 @@ function! s:process_tag_h(line, id)
|
||||
|
||||
for l in range(h_level-1)
|
||||
let h_number .= a:id[l][1].'.'
|
||||
if a:id[l][0] != ''
|
||||
if a:id[l][0] !=? ''
|
||||
let h_complete_id .= a:id[l][0].'-'
|
||||
endif
|
||||
endfor
|
||||
@ -1134,7 +1134,7 @@ function! s:process_tag_h(line, id)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_hr(line)
|
||||
function! s:process_tag_hr(line) abort
|
||||
let line = a:line
|
||||
let processed = 0
|
||||
if a:line =~# '^-----*$'
|
||||
@ -1145,8 +1145,8 @@ function! s:process_tag_hr(line)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:process_tag_table(line, table, header_ids)
|
||||
function! s:table_empty_cell(value)
|
||||
function! s:process_tag_table(line, table, header_ids) abort
|
||||
function! s:table_empty_cell(value) abort
|
||||
let cell = {}
|
||||
|
||||
if a:value =~# '^\s*\\/\s*$'
|
||||
@ -1170,7 +1170,7 @@ function! s:process_tag_table(line, table, header_ids)
|
||||
return cell
|
||||
endfunction
|
||||
|
||||
function! s:table_add_row(table, line)
|
||||
function! s:table_add_row(table, line) abort
|
||||
if empty(a:table)
|
||||
if a:line =~# '^\s\+'
|
||||
let row = ['center', []]
|
||||
@ -1205,7 +1205,7 @@ function! s:process_tag_table(line, table, header_ids)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:parse_line(line, state)
|
||||
function! s:parse_line(line, state) abort
|
||||
let state = {}
|
||||
let state.para = a:state.para
|
||||
let state.quote = a:state.quote
|
||||
@ -1428,14 +1428,14 @@ function! s:parse_line(line, state)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:use_custom_wiki2html()
|
||||
function! s:use_custom_wiki2html() abort
|
||||
let custom_wiki2html = vimwiki#vars#get_wikilocal('custom_wiki2html')
|
||||
return !empty(custom_wiki2html) &&
|
||||
\ (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html))
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#html#CustomWiki2HTML(path, wikifile, force)
|
||||
function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) abort
|
||||
call vimwiki#path#mkdir(a:path)
|
||||
let output = system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '.
|
||||
\ a:force. ' '.
|
||||
@ -1455,19 +1455,19 @@ function! vimwiki#html#CustomWiki2HTML(path, wikifile, force)
|
||||
\ (len(vimwiki#vars#get_wikilocal('custom_wiki2html_args')) > 0 ?
|
||||
\ vimwiki#vars#get_wikilocal('custom_wiki2html_args') : '-'))
|
||||
" Echo if non void
|
||||
if output !~ "^\s*$"
|
||||
if output !~? '^\s*$'
|
||||
echomsg output
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:convert_file(path_html, wikifile)
|
||||
function! s:convert_file(path_html, wikifile) abort
|
||||
let done = 0
|
||||
|
||||
let wikifile = fnamemodify(a:wikifile, ":p")
|
||||
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'
|
||||
let htmlfile = fnamemodify(wikifile, ':t:r').'.html'
|
||||
|
||||
" the currently processed file name is needed when processing links
|
||||
" yeah yeah, shame on me for using (quasi-) global variables
|
||||
@ -1511,7 +1511,7 @@ function! s:convert_file(path_html, wikifile)
|
||||
" prepare constants for s:safe_html_line()
|
||||
let s:lt_pattern = '<'
|
||||
let s:gt_pattern = '>'
|
||||
if vimwiki#vars#get_global('valid_html_tags') != ''
|
||||
if vimwiki#vars#get_global('valid_html_tags') !=? ''
|
||||
let tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|')
|
||||
let s:lt_pattern = '\c<\%(/\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!'
|
||||
let s:gt_pattern = '\c\%(</\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?\)\@<!>'
|
||||
@ -1549,7 +1549,7 @@ function! s:convert_file(path_html, wikifile)
|
||||
|
||||
|
||||
if nohtml
|
||||
echon "\r"."%nohtml placeholder found"
|
||||
echon "\r".'%nohtml placeholder found'
|
||||
return ''
|
||||
endif
|
||||
|
||||
@ -1567,7 +1567,7 @@ function! s:convert_file(path_html, wikifile)
|
||||
call s:close_tag_table(state.table, lines, state.header_ids)
|
||||
call extend(ldest, lines)
|
||||
|
||||
let title = s:process_title(placeholders, fnamemodify(a:wikifile, ":t:r"))
|
||||
let title = s:process_title(placeholders, fnamemodify(a:wikifile, ':t:r'))
|
||||
let date = s:process_date(placeholders, strftime('%Y-%m-%d'))
|
||||
let wiki_path = strpart(s:current_wiki_file, strlen(vimwiki#vars#get_wikilocal('path')))
|
||||
|
||||
@ -1585,7 +1585,7 @@ function! s:convert_file(path_html, wikifile)
|
||||
call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")')
|
||||
|
||||
let enc = &fileencoding
|
||||
if enc == ''
|
||||
if enc ==? ''
|
||||
let enc = &encoding
|
||||
endif
|
||||
call map(html_lines, 'substitute(v:val, "%encoding%", "'. enc .'", "g")')
|
||||
@ -1606,16 +1606,16 @@ function! s:convert_file(path_html, wikifile)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#html#Wiki2HTML(path_html, wikifile)
|
||||
function! vimwiki#html#Wiki2HTML(path_html, wikifile) abort
|
||||
let result = s:convert_file(a:path_html, a:wikifile)
|
||||
if result != ''
|
||||
if result !=? ''
|
||||
call s:create_default_CSS(a:path_html)
|
||||
endif
|
||||
return result
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#html#WikiAll2HTML(path_html, force)
|
||||
function! vimwiki#html#WikiAll2HTML(path_html, force) abort
|
||||
if !s:syntax_supported() && !s:use_custom_wiki2html()
|
||||
echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax'
|
||||
return
|
||||
@ -1623,7 +1623,7 @@ function! vimwiki#html#WikiAll2HTML(path_html, force)
|
||||
|
||||
echomsg 'Vimwiki: Saving Vimwiki files ...'
|
||||
let save_eventignore = &eventignore
|
||||
let &eventignore = "all"
|
||||
let &eventignore = 'all'
|
||||
try
|
||||
wall
|
||||
catch
|
||||
@ -1650,7 +1650,7 @@ function! vimwiki#html#WikiAll2HTML(path_html, force)
|
||||
let wikifiles = split(glob(vimwiki#vars#get_wikilocal('path').'**/*'.
|
||||
\ vimwiki#vars#get_wikilocal('ext')), '\n')
|
||||
for wikifile in wikifiles
|
||||
let wikifile = fnamemodify(wikifile, ":p")
|
||||
let wikifile = fnamemodify(wikifile, ':p')
|
||||
|
||||
" temporarily adjust 'subdir' and 'invsubdir' state variables
|
||||
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), wikifile)
|
||||
@ -1680,29 +1680,29 @@ function! vimwiki#html#WikiAll2HTML(path_html, force)
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:file_exists(fname)
|
||||
function! s:file_exists(fname) abort
|
||||
return !empty(getftype(expand(a:fname)))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:binary_exists(fname)
|
||||
function! s:binary_exists(fname) abort
|
||||
return executable(expand(a:fname))
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:get_wikifile_url(wikifile)
|
||||
function! s:get_wikifile_url(wikifile) abort
|
||||
return vimwiki#vars#get_wikilocal('path_html') .
|
||||
\ vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), a:wikifile).
|
||||
\ fnamemodify(a:wikifile, ":t:r").'.html'
|
||||
\ fnamemodify(a:wikifile, ':t:r').'.html'
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#html#PasteUrl(wikifile)
|
||||
function! vimwiki#html#PasteUrl(wikifile) abort
|
||||
execute 'r !echo file://'.s:get_wikifile_url(a:wikifile)
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#html#CatUrl(wikifile)
|
||||
function! vimwiki#html#CatUrl(wikifile) abort
|
||||
execute '!echo file://'.s:get_wikifile_url(a:wikifile)
|
||||
endfunction
|
||||
|
||||
|
Reference in New Issue
Block a user