2018-04-20 07:03:53 +02:00
|
|
|
" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
|
2010-01-20 01:00:00 +01:00
|
|
|
" Vimwiki autoload plugin file
|
2018-04-20 07:03:53 +02:00
|
|
|
" Description: HTML export
|
2015-02-23 12:10:42 +01:00
|
|
|
" Home: https://github.com/vimwiki/vimwiki/
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if exists('g:loaded_vimwiki_html_auto') || &compatible
|
2010-01-20 01:00:00 +01:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_vimwiki_html_auto = 1
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:root_path(subdir) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
return repeat('../', len(split(a:subdir, '[/\\]')))
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:syntax_supported() abort
|
|
|
|
return vimwiki#vars#get_wikilocal('syntax') ==? 'default'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:remove_blank_lines(lines) abort
|
2015-02-09 20:47:11 +01:00
|
|
|
while !empty(a:lines) && a:lines[-1] =~# '^\s*$'
|
2010-01-20 01:00:00 +01:00
|
|
|
call remove(a:lines, -1)
|
|
|
|
endwhile
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:is_web_link(lnk) abort
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:lnk =~# '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)'
|
2010-01-20 01:00:00 +01:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:is_img_link(lnk) abort
|
2015-02-09 20:47:11 +01:00
|
|
|
if tolower(a:lnk) =~# '\.\%(png\|jpg\|gif\|jpeg\)$'
|
2010-01-20 01:00:00 +01:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:has_abs_path(fname) abort
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:fname =~# '\(^.:\)\|\(^/\)'
|
2010-01-20 01:00:00 +01:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:find_autoload_file(name) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
for path in split(&runtimepath, ',')
|
|
|
|
let fname = path.'/autoload/vimwiki/'.a:name
|
2019-12-21 04:41:03 +01:00
|
|
|
if glob(fname) !=? ''
|
2011-06-11 02:00:00 +02:00
|
|
|
return fname
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
return ''
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:default_CSS_full_name(path) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let path = expand(a:path)
|
2016-12-22 19:55:20 +01:00
|
|
|
let css_full_name = path . vimwiki#vars#get_wikilocal('css_name')
|
2012-06-07 02:00:00 +02:00
|
|
|
return css_full_name
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:create_default_CSS(path) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
let css_full_name = s:default_CSS_full_name(a:path)
|
2019-12-21 04:41:03 +01:00
|
|
|
if glob(css_full_name) ==? ''
|
2014-12-04 21:12:04 +01:00
|
|
|
call vimwiki#path#mkdir(fnamemodify(css_full_name, ':p:h'))
|
2011-06-11 02:00:00 +02:00
|
|
|
let default_css = s:find_autoload_file('style.css')
|
2019-12-21 04:41:03 +01:00
|
|
|
if default_css !=? ''
|
2011-06-11 02:00:00 +02:00
|
|
|
let lines = readfile(default_css)
|
|
|
|
call writefile(lines, css_full_name)
|
2016-03-19 22:01:25 +01:00
|
|
|
return 1
|
2011-06-11 02:00:00 +02:00
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
2016-03-19 22:01:25 +01:00
|
|
|
return 0
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:template_full_name(name) abort
|
|
|
|
if a:name ==? ''
|
2016-12-22 19:12:03 +01:00
|
|
|
let name = vimwiki#vars#get_wikilocal('template_default')
|
2011-06-11 02:00:00 +02:00
|
|
|
else
|
|
|
|
let name = a:name
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2016-12-22 19:12:03 +01:00
|
|
|
let fname = expand(vimwiki#vars#get_wikilocal('template_path').
|
|
|
|
\ name . vimwiki#vars#get_wikilocal('template_ext'))
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2011-06-11 02:00:00 +02:00
|
|
|
if filereadable(fname)
|
|
|
|
return fname
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:get_html_template(template) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
" TODO: refactor it!!!
|
2010-01-20 01:00:00 +01:00
|
|
|
let lines=[]
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if a:template !=? ''
|
2012-06-07 02:00:00 +02:00
|
|
|
let template_name = s:template_full_name(a:template)
|
2010-01-20 01:00:00 +01:00
|
|
|
try
|
2011-06-11 02:00:00 +02:00
|
|
|
let lines = readfile(template_name)
|
2010-01-20 01:00:00 +01:00
|
|
|
return lines
|
|
|
|
catch /E484/
|
2018-04-20 07:03:53 +02:00
|
|
|
echomsg 'Vimwiki: HTML template '.template_name. ' does not exist!'
|
2010-01-20 01:00:00 +01:00
|
|
|
endtry
|
|
|
|
endif
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
let default_tpl = s:template_full_name('')
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if default_tpl ==? ''
|
2012-06-07 02:00:00 +02:00
|
|
|
let default_tpl = s:find_autoload_file('default.tpl')
|
2011-06-11 02:00:00 +02:00
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
let lines = readfile(default_tpl)
|
2010-01-20 01:00:00 +01:00
|
|
|
return lines
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:safe_html_preformatted(line) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
let line = substitute(a:line,'<','\<', 'g')
|
|
|
|
let line = substitute(line,'>','\>', 'g')
|
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-16 20:40:18 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:escape_html_attribute(string) abort
|
2018-04-16 20:40:18 +02:00
|
|
|
return substitute(a:string, '"', '\"', 'g')
|
|
|
|
endfunction
|
|
|
|
|
2014-02-13 12:42:24 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:safe_html_line(line) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
" escape & < > when producing HTML text
|
2013-04-19 05:46:58 +02:00
|
|
|
" s:lt_pattern, s:gt_pattern depend on g:vimwiki_valid_html_tags
|
|
|
|
" and are set in vimwiki#html#Wiki2HTML()
|
2010-01-20 01:00:00 +01:00
|
|
|
let line = substitute(a:line, '&', '\&', 'g')
|
2012-06-07 02:00:00 +02:00
|
|
|
let line = substitute(line,s:lt_pattern,'\<', 'g')
|
|
|
|
let line = substitute(line,s:gt_pattern,'\>', 'g')
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:delete_html_files(path) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let htmlfiles = split(glob(a:path.'**/*.html'), '\n')
|
|
|
|
for fname in htmlfiles
|
2011-06-11 02:00:00 +02:00
|
|
|
" ignore user html files, e.g. search.html,404.html
|
2019-12-21 04:41:03 +01:00
|
|
|
if stridx(vimwiki#vars#get_global('user_htmls'), fnamemodify(fname, ':t')) >= 0
|
2011-06-11 02:00:00 +02:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
" delete if there is no corresponding wiki file
|
2016-12-22 19:55:20 +01:00
|
|
|
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path_html'), fname)
|
|
|
|
let wikifile = vimwiki#vars#get_wikilocal('path').subdir.
|
2019-12-21 04:41:03 +01:00
|
|
|
\fnamemodify(fname, ':t:r').vimwiki#vars#get_wikilocal('ext')
|
2011-06-11 02:00:00 +02:00
|
|
|
if filereadable(wikifile)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
try
|
|
|
|
call delete(fname)
|
|
|
|
catch
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki Error: Cannot delete '.fname
|
2010-01-20 01:00:00 +01:00
|
|
|
endtry
|
|
|
|
endfor
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:mid(value, cnt) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt)
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:subst_func(line, regexp, func, ...) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
" Substitute text found by regexp with result of
|
|
|
|
" func(matched) function.
|
|
|
|
|
|
|
|
let pos = 0
|
|
|
|
let lines = split(a:line, a:regexp, 1)
|
2019-12-21 04:41:03 +01:00
|
|
|
let res_line = ''
|
2010-01-20 01:00:00 +01:00
|
|
|
for line in lines
|
|
|
|
let res_line = res_line.line
|
|
|
|
let matched = matchstr(a:line, a:regexp, pos)
|
2019-12-21 04:41:03 +01:00
|
|
|
if matched !=? ''
|
2014-02-13 12:42:24 +01:00
|
|
|
if a:0
|
|
|
|
let res_line = res_line.{a:func}(matched, a:1)
|
|
|
|
else
|
|
|
|
let res_line = res_line.{a:func}(matched)
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
let pos = matchend(a:line, a:regexp, pos)
|
|
|
|
endfor
|
|
|
|
return res_line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_date(placeholders, default_date) abort
|
2017-07-08 21:04:54 +02:00
|
|
|
if !empty(a:placeholders)
|
|
|
|
for [placeholder, row, idx] in a:placeholders
|
|
|
|
let [type, param] = placeholder
|
|
|
|
if type ==# 'date' && !empty(param)
|
|
|
|
return param
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return a:default_date
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2017-07-08 21:04:54 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_title(placeholders, default_title) abort
|
2010-08-24 02:00:00 +02:00
|
|
|
if !empty(a:placeholders)
|
|
|
|
for [placeholder, row, idx] in a:placeholders
|
|
|
|
let [type, param] = placeholder
|
2015-02-09 20:05:25 +01:00
|
|
|
if type ==# 'title' && !empty(param)
|
2010-08-24 02:00:00 +02:00
|
|
|
return param
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
2010-08-24 02:00:00 +02:00
|
|
|
return a:default_title
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:is_html_uptodate(wikifile) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
let tpl_time = -1
|
|
|
|
|
|
|
|
let tpl_file = s:template_full_name('')
|
2019-12-21 04:41:03 +01:00
|
|
|
if tpl_file !=? ''
|
2011-06-11 02:00:00 +02:00
|
|
|
let tpl_time = getftime(tpl_file)
|
|
|
|
endif
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
let wikifile = fnamemodify(a:wikifile, ':p')
|
2019-03-30 02:34:31 +01:00
|
|
|
|
|
|
|
if vimwiki#vars#get_wikilocal('html_filename_parameterization')
|
|
|
|
let parameterized_wikiname = s:parameterized_wikiname(wikifile)
|
|
|
|
let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') .
|
|
|
|
\ vimwiki#vars#get_bufferlocal('subdir') . parameterized_wikiname)
|
|
|
|
else
|
|
|
|
let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') .
|
2019-12-21 04:41:03 +01:00
|
|
|
\ vimwiki#vars#get_bufferlocal('subdir') . fnamemodify(wikifile, ':t:r').'.html')
|
2019-03-30 02:34:31 +01:00
|
|
|
endif
|
2011-06-11 02:00:00 +02:00
|
|
|
|
|
|
|
if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile)
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
return 0
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:parameterized_wikiname(wikifile) abort
|
|
|
|
let initial = fnamemodify(a:wikifile, ':t:r')
|
2019-03-30 02:34:31 +01:00
|
|
|
let lower_sanitized = tolower(initial)
|
2019-12-21 04:41:03 +01:00
|
|
|
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'
|
2019-03-30 02:34:31 +01:00
|
|
|
endfunction
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:html_insert_contents(html_lines, content) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
let lines = []
|
|
|
|
for line in a:html_lines
|
2015-02-09 20:47:11 +01:00
|
|
|
if line =~# '%content%'
|
2011-06-11 02:00:00 +02:00
|
|
|
let parts = split(line, '%content%', 1)
|
|
|
|
if empty(parts)
|
|
|
|
call extend(lines, a:content)
|
|
|
|
else
|
|
|
|
for idx in range(len(parts))
|
|
|
|
call add(lines, parts[idx])
|
|
|
|
if idx < len(parts) - 1
|
|
|
|
call extend(lines, a:content)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call add(lines, line)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
return lines
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_eqin(value) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
" mathJAX wants \( \) for inline maths
|
|
|
|
return '\('.s:mid(a:value, 1).'\)'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_em(value) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
return '<em>'.s:mid(a:value, 1).'</em>'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_strong(value, header_ids) abort
|
2014-02-13 12:42:24 +01:00
|
|
|
let text = s:mid(a:value, 1)
|
2018-04-16 20:40:18 +02:00
|
|
|
let id = s:escape_html_attribute(text)
|
2014-02-13 12:42:24 +01:00
|
|
|
let complete_id = ''
|
|
|
|
for l in range(6)
|
2019-12-21 04:41:03 +01:00
|
|
|
if a:header_ids[l][0] !=? ''
|
2014-02-13 12:42:24 +01:00
|
|
|
let complete_id .= a:header_ids[l][0].'-'
|
|
|
|
endif
|
|
|
|
endfor
|
2019-12-21 04:41:03 +01:00
|
|
|
if a:header_ids[5][0] ==? ''
|
2014-02-13 12:42:24 +01:00
|
|
|
let complete_id = complete_id[:-2]
|
|
|
|
endif
|
|
|
|
let complete_id .= '-'.id
|
2018-04-16 20:40:18 +02:00
|
|
|
return '<span id="'.s:escape_html_attribute(complete_id).'"></span><strong id="'
|
2014-02-13 12:42:24 +01:00
|
|
|
\ .id.'">'.text.'</strong>'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_tags(value, header_ids) abort
|
2015-11-10 14:37:25 +01:00
|
|
|
let complete_id = ''
|
|
|
|
for level in range(6)
|
2019-12-21 04:41:03 +01:00
|
|
|
if a:header_ids[level][0] !=? ''
|
2015-11-10 14:37:25 +01:00
|
|
|
let complete_id .= a:header_ids[level][0].'-'
|
|
|
|
endif
|
|
|
|
endfor
|
2019-12-21 04:41:03 +01:00
|
|
|
if a:header_ids[5][0] ==? ''
|
2015-11-10 14:37:25 +01:00
|
|
|
let complete_id = complete_id[:-2]
|
|
|
|
endif
|
2018-04-16 20:40:18 +02:00
|
|
|
let complete_id = s:escape_html_attribute(complete_id)
|
2015-11-10 14:37:25 +01:00
|
|
|
|
|
|
|
let result = []
|
|
|
|
for tag in split(a:value, ':')
|
2018-04-16 20:40:18 +02:00
|
|
|
let id = s:escape_html_attribute(tag)
|
2015-11-10 14:37:25 +01:00
|
|
|
call add(result, '<span id="'.complete_id.'-'.id.'"></span><span class="tag" id="'
|
|
|
|
\ .id.'">'.tag.'</span>')
|
|
|
|
endfor
|
|
|
|
return join(result)
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2015-11-10 14:37:25 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_todo(value) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
return '<span class="todo">'.a:value.'</span>'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_strike(value) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
return '<del>'.s:mid(a:value, 2).'</del>'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_super(value) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
return '<sup><small>'.s:mid(a:value, 1).'</small></sup>'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_sub(value) abort
|
2018-04-20 07:03:53 +02:00
|
|
|
return '<sub><small>'.s:mid(a:value, 2).'</small></sub>'
|
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_code(value) abort
|
2019-01-26 10:29:29 +01:00
|
|
|
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
|
2019-12-21 04:41:03 +01:00
|
|
|
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])
|
2019-03-17 22:40:34 +01:00
|
|
|
|
|
|
|
let l:fg_color =
|
|
|
|
\ (((0.299 * r + 0.587 * g + 0.114 * b) / 0xFF) > 0.5)
|
2019-12-21 04:41:03 +01:00
|
|
|
\ ? 'black' : 'white'
|
2019-02-19 21:04:57 +01:00
|
|
|
|
2019-03-17 22:40:34 +01:00
|
|
|
let l:retstr .=
|
|
|
|
\ " style='background-color:" . l:str .
|
2019-12-21 04:41:03 +01:00
|
|
|
\ ';color:' . l:fg_color . ";'"
|
2019-01-26 10:29:29 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
let l:retstr .= '>'.s:safe_html_preformatted(l:str).'</code>'
|
|
|
|
return l:retstr
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" match n-th ARG within {{URL[|ARG1|ARG2|...]}}
|
2012-06-07 02:00:00 +02:00
|
|
|
" *c,d,e),...
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:incl_match_arg(nn_index) abort
|
2017-01-07 21:51:15 +01:00
|
|
|
let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl')
|
2018-04-20 07:03:53 +02:00
|
|
|
let rx = rx . repeat(vimwiki#vars#get_global('rxWikiInclSeparator') .
|
|
|
|
\ vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1)
|
2012-06-07 02:00:00 +02:00
|
|
|
if a:nn_index > 0
|
2018-04-20 07:03:53 +02:00
|
|
|
let rx = rx. vimwiki#vars#get_global('rxWikiInclSeparator'). '\zs' .
|
|
|
|
\ vimwiki#vars#get_global('rxWikiInclArg') . '\ze'
|
2010-05-12 02:00:00 +02:00
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
let rx = rx . vimwiki#vars#get_global('rxWikiInclArgs') .
|
|
|
|
\ vimwiki#vars#get_global('rxWikiInclSuffix')
|
2012-06-07 02:00:00 +02:00
|
|
|
return rx
|
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:linkify_link(src, descr) abort
|
2018-04-16 20:40:18 +02:00
|
|
|
let src_str = ' href="'.s:escape_html_attribute(a:src).'"'
|
2018-11-25 17:56:43 +01:00
|
|
|
let descr = vimwiki#u#trim(a:descr)
|
2019-12-21 04:41:03 +01:00
|
|
|
let descr = (descr ==? '' ? a:src : descr)
|
2017-01-07 21:51:15 +01:00
|
|
|
let descr_str = (descr =~# vimwiki#vars#get_global('rxWikiIncl')
|
2018-04-20 07:03:53 +02:00
|
|
|
\ ? s:tag_wikiincl(descr)
|
2012-06-07 02:00:00 +02:00
|
|
|
\ : descr)
|
|
|
|
return '<a'.src_str.'>'.descr_str.'</a>'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:linkify_image(src, descr, verbatim_str) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
let src_str = ' src="'.a:src.'"'
|
2019-12-21 04:41:03 +01:00
|
|
|
let descr_str = (a:descr !=? '' ? ' alt="'.a:descr.'"' : '')
|
|
|
|
let verbatim_str = (a:verbatim_str !=? '' ? ' '.a:verbatim_str : '')
|
2012-06-07 02:00:00 +02:00
|
|
|
return '<img'.src_str.descr_str.verbatim_str.' />'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_weblink(value) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
" Weblink Template -> <a href="url">descr</a>
|
|
|
|
let str = a:value
|
2017-01-12 21:45:09 +01:00
|
|
|
let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
|
|
|
|
let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'))
|
2018-04-20 07:13:21 +02:00
|
|
|
let line = s:linkify_link(url, descr)
|
2010-05-12 02:00:00 +02:00
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_wikiincl(value) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
" {{imgurl|arg1|arg2}} -> ???
|
|
|
|
" {{imgurl}} -> <img src="imgurl"/>
|
|
|
|
" {{imgurl|descr|style="A"}} -> <img src="imgurl" alt="descr" style="A" />
|
|
|
|
" {{imgurl|descr|class="B"}} -> <img src="imgurl" alt="descr" class="B" />
|
|
|
|
let str = a:value
|
|
|
|
" custom transclusions
|
|
|
|
let line = VimwikiWikiIncludeHandler(str)
|
|
|
|
" otherwise, assume image transclusion
|
2019-12-21 04:41:03 +01:00
|
|
|
if line ==? ''
|
2017-01-07 21:51:15 +01:00
|
|
|
let url_0 = matchstr(str, vimwiki#vars#get_global('rxWikiInclMatchUrl'))
|
2018-04-20 07:13:21 +02:00
|
|
|
let descr = matchstr(str, s:incl_match_arg(1))
|
|
|
|
let verbatim_str = matchstr(str, s:incl_match_arg(2))
|
2015-04-09 14:48:26 +02:00
|
|
|
|
|
|
|
let link_infos = vimwiki#base#resolve_link(url_0)
|
|
|
|
|
2015-04-29 14:59:10 +02:00
|
|
|
if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary'
|
2018-04-20 07:03:53 +02:00
|
|
|
let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'), link_infos.filename)
|
2015-04-29 14:59:10 +02:00
|
|
|
" strip the .html extension when we have wiki links, so that the user can
|
|
|
|
" simply write {{image.png}} to include an image from the wiki directory
|
|
|
|
if link_infos.scheme =~# '\mwiki\d\+\|diary'
|
|
|
|
let url = fnamemodify(url, ':r')
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let url = link_infos.filename
|
2012-07-07 02:00:00 +02:00
|
|
|
endif
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
let url = escape(url, '#')
|
2018-04-20 07:13:21 +02:00
|
|
|
let line = s:linkify_image(url, descr, verbatim_str)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_wikilink(value) abort
|
2014-02-13 12:42:24 +01:00
|
|
|
" [[url]] -> <a href="url.html">url</a>
|
|
|
|
" [[url|descr]] -> <a href="url.html">descr</a>
|
|
|
|
" [[url|{{...}}]] -> <a href="url.html"> ... </a>
|
|
|
|
" [[fileurl.ext|descr]] -> <a href="fileurl.ext">descr</a>
|
|
|
|
" [[dirurl/|descr]] -> <a href="dirurl/index.html">descr</a>
|
|
|
|
" [[url#a1#a2]] -> <a href="url.html#a1-a2">url#a1#a2</a>
|
2014-08-18 09:16:41 +02:00
|
|
|
" [[#a1#a2]] -> <a href="#a1-a2">#a1#a2</a>
|
2012-06-07 02:00:00 +02:00
|
|
|
let str = a:value
|
2017-01-11 22:12:33 +01:00
|
|
|
let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
|
2017-01-12 21:45:09 +01:00
|
|
|
let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'))
|
2018-11-25 17:56:43 +01:00
|
|
|
let descr = vimwiki#u#trim(descr)
|
2019-12-21 04:41:03 +01:00
|
|
|
let descr = (descr !=? '' ? descr : url)
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
let line = VimwikiLinkConverter(url, s:current_wiki_file, s:current_html_file)
|
2019-12-21 04:41:03 +01:00
|
|
|
if line ==? ''
|
2015-04-09 14:48:26 +02:00
|
|
|
let link_infos = vimwiki#base#resolve_link(url, s:current_wiki_file)
|
|
|
|
|
2015-04-29 14:59:10 +02:00
|
|
|
if link_infos.scheme ==# 'file'
|
2015-04-09 14:48:26 +02:00
|
|
|
" external file links are always absolute
|
|
|
|
let html_link = link_infos.filename
|
2015-04-29 14:59:10 +02:00
|
|
|
elseif link_infos.scheme ==# 'local'
|
2018-04-16 20:40:18 +02:00
|
|
|
let html_link = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'),
|
|
|
|
\ link_infos.filename)
|
2015-05-12 15:54:53 +02:00
|
|
|
elseif link_infos.scheme =~# '\mwiki\d\+\|diary'
|
2015-04-09 14:48:26 +02:00
|
|
|
" wiki links are always relative to the current file
|
|
|
|
let html_link = vimwiki#path#relpath(
|
|
|
|
\ fnamemodify(s:current_wiki_file, ':h'),
|
|
|
|
\ fnamemodify(link_infos.filename, ':r'))
|
2019-12-21 04:41:03 +01:00
|
|
|
if html_link !~? '\m/$'
|
2015-04-09 14:48:26 +02:00
|
|
|
let html_link .= '.html'
|
|
|
|
endif
|
2015-05-12 15:54:53 +02:00
|
|
|
else " other schemes, like http, are left untouched
|
|
|
|
let html_link = link_infos.filename
|
2015-04-09 14:48:26 +02:00
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if link_infos.anchor !=? ''
|
2015-04-09 14:48:26 +02:00
|
|
|
let anchor = substitute(link_infos.anchor, '#', '-', 'g')
|
|
|
|
let html_link .= '#'.anchor
|
|
|
|
endif
|
|
|
|
let line = html_link
|
2014-03-13 16:33:39 +01:00
|
|
|
endif
|
2015-04-09 14:48:26 +02:00
|
|
|
|
2018-04-20 07:13:21 +02:00
|
|
|
let line = s:linkify_link(line, descr)
|
2010-05-12 02:00:00 +02:00
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_remove_internal_link(value) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let value = s:mid(a:value, 2)
|
|
|
|
|
|
|
|
let line = ''
|
2015-02-09 20:47:11 +01:00
|
|
|
if value =~# '|'
|
2019-12-21 04:41:03 +01:00
|
|
|
let link_parts = split(value, '|', 1)
|
2010-01-20 01:00:00 +01:00
|
|
|
else
|
2019-12-21 04:41:03 +01:00
|
|
|
let link_parts = split(value, '][', 1)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
if len(link_parts) > 1
|
|
|
|
if len(link_parts) < 3
|
2019-12-21 04:41:03 +01:00
|
|
|
let style = ''
|
2010-01-20 01:00:00 +01:00
|
|
|
else
|
|
|
|
let style = link_parts[2]
|
|
|
|
endif
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = link_parts[1]
|
2010-01-20 01:00:00 +01:00
|
|
|
else
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = value
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:tag_remove_external_link(value) abort
|
2010-05-12 02:00:00 +02:00
|
|
|
let value = s:mid(a:value, 1)
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = ''
|
|
|
|
if s:is_web_link(value)
|
|
|
|
let lnkElements = split(value)
|
|
|
|
let head = lnkElements[0]
|
|
|
|
let rest = join(lnkElements[1:])
|
2019-12-21 04:41:03 +01:00
|
|
|
if rest ==? ''
|
2015-02-09 20:05:25 +01:00
|
|
|
let rest = head
|
2010-05-12 02:00:00 +02:00
|
|
|
endif
|
|
|
|
let line = rest
|
|
|
|
elseif s:is_img_link(value)
|
|
|
|
let line = '<img src="'.value.'" />'
|
2010-01-20 01:00:00 +01:00
|
|
|
else
|
2010-05-12 02:00:00 +02:00
|
|
|
" [alskfj sfsf] shouldn't be a link. So return it as it was --
|
|
|
|
" enclosed in [...]
|
|
|
|
let line = '['.value.']'
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:make_tag(line, regexp, func, ...) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
" Make tags for a given matched regexp.
|
|
|
|
" Exclude preformatted text and href links.
|
2018-04-20 07:03:53 +02:00
|
|
|
" FIXME
|
2012-06-07 02:00:00 +02:00
|
|
|
let patt_splitter = '\(`[^`]\+`\)\|'.
|
2018-04-20 07:03:53 +02:00
|
|
|
\ '\('.vimwiki#vars#get_syntaxlocal('rxPreStart').'.\+'.
|
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxPreEnd').'\)\|'.
|
2012-06-07 02:00:00 +02:00
|
|
|
\ '\(<a href.\{-}</a>\)\|'.
|
|
|
|
\ '\(<img src.\{-}/>\)\|'.
|
2014-03-10 10:01:32 +01:00
|
|
|
\ '\(<pre.\{-}</pre>\)\|'.
|
2017-01-07 21:51:15 +01:00
|
|
|
\ '\('.vimwiki#vars#get_syntaxlocal('rxEqIn').'\)'
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
"FIXME FIXME !!! these can easily occur on the same line!
|
|
|
|
"XXX {{{ }}} ??? obsolete
|
2015-02-09 20:05:25 +01:00
|
|
|
if '`[^`]\+`' ==# a:regexp || '{{{.\+}}}' ==# a:regexp ||
|
2017-01-07 21:51:15 +01:00
|
|
|
\ vimwiki#vars#get_syntaxlocal('rxEqIn') ==# a:regexp
|
2010-01-20 01:00:00 +01:00
|
|
|
let res_line = s:subst_func(a:line, a:regexp, a:func)
|
|
|
|
else
|
|
|
|
let pos = 0
|
|
|
|
" split line with patt_splitter to have parts of line before and after
|
|
|
|
" href links, preformatted text
|
|
|
|
" ie:
|
|
|
|
" hello world `is just a` simple <a href="link.html">type of</a> prg.
|
|
|
|
" result:
|
|
|
|
" ['hello world ', ' simple ', 'type of', ' prg']
|
|
|
|
let lines = split(a:line, patt_splitter, 1)
|
2019-12-21 04:41:03 +01:00
|
|
|
let res_line = ''
|
2010-01-20 01:00:00 +01:00
|
|
|
for line in lines
|
2014-02-13 12:42:24 +01:00
|
|
|
if a:0
|
|
|
|
let res_line = res_line.s:subst_func(line, a:regexp, a:func, a:1)
|
|
|
|
else
|
|
|
|
let res_line = res_line.s:subst_func(line, a:regexp, a:func)
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
let res_line = res_line.matchstr(a:line, patt_splitter, pos)
|
|
|
|
let pos = matchend(a:line, patt_splitter, pos)
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return res_line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tags_remove_links(line) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let line = a:line
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = s:make_tag(line, '\[\[.\{-}\]\]', 's:tag_remove_internal_link')
|
|
|
|
let line = s:make_tag(line, '\[.\{-}\]', 's:tag_remove_external_link')
|
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tags_typefaces(line, header_ids) abort
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = a:line
|
2017-01-07 21:51:15 +01:00
|
|
|
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)
|
2017-01-16 22:09:49 +01:00
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_global('rxTodo'), 's:tag_todo')
|
2017-01-07 21:51:15 +01:00
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxDelText'), 's:tag_strike')
|
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSuperScript'), 's:tag_super')
|
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSubScript'), 's:tag_sub')
|
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxCode'), 's:tag_code')
|
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxEqIn'), 's:tag_eqin')
|
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxTags'), 's:tag_tags', a:header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tags_links(line) abort
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = a:line
|
2017-01-11 22:12:33 +01:00
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWikiLink'), 's:tag_wikilink')
|
2017-01-07 21:51:15 +01:00
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiIncl'), 's:tag_wikiincl')
|
2017-01-12 21:45:09 +01:00
|
|
|
let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWeblink'), 's:tag_weblink')
|
2010-05-12 02:00:00 +02:00
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_inline_tags(line, header_ids) abort
|
2010-05-12 02:00:00 +02:00
|
|
|
let line = s:process_tags_links(a:line)
|
2014-02-13 12:42:24 +01:00
|
|
|
let line = s:process_tags_typefaces(line, a:header_ids)
|
2010-05-12 02:00:00 +02:00
|
|
|
return line
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_pre(pre, ldest) abort
|
2010-08-24 02:00:00 +02:00
|
|
|
if a:pre[0]
|
2019-12-21 04:41:03 +01:00
|
|
|
call insert(a:ldest, '</pre>')
|
2010-01-20 01:00:00 +01:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return a:pre
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_math(math, ldest) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
if a:math[0]
|
|
|
|
call insert(a:ldest, "\\\]")
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return a:math
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_quote(quote, ldest) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
if a:quote
|
2019-12-21 04:41:03 +01:00
|
|
|
call insert(a:ldest, '</blockquote>')
|
2010-01-20 01:00:00 +01:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return a:quote
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-06-03 06:29:04 +02:00
|
|
|
function! s:close_tag_arrow_quote(arrow_quote, ldest) abort
|
|
|
|
if a:arrow_quote
|
|
|
|
call insert(a:ldest, '</p></blockquote>')
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return a:arrow_quote
|
|
|
|
endfunction
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_para(para, ldest) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
if a:para
|
2019-12-21 04:41:03 +01:00
|
|
|
call insert(a:ldest, '</p>')
|
2010-01-20 01:00:00 +01:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return a:para
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_table(table, ldest, header_ids) abort
|
2010-05-12 02:00:00 +02:00
|
|
|
" 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:
|
2018-04-20 07:03:53 +02:00
|
|
|
" ['center',
|
2011-06-11 02:00:00 +02:00
|
|
|
" [ CELL1, CELL2, CELL3 ],
|
|
|
|
" [ CELL1, CELL2, CELL3 ],
|
|
|
|
" [ CELL1, CELL2, CELL3 ],
|
2010-05-12 02:00:00 +02:00
|
|
|
" ]
|
2011-06-11 02:00:00 +02:00
|
|
|
" And CELLx is: { 'body': 'col_x', 'rowspan': r, 'colspan': c }
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:sum_rowspan(table) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
let table = a:table
|
|
|
|
|
|
|
|
" Get max cells
|
2018-04-20 07:03:53 +02:00
|
|
|
let max_cells = 0
|
2011-06-11 02:00:00 +02:00
|
|
|
for row in table[1:]
|
|
|
|
let n_cells = len(row)
|
|
|
|
if n_cells > max_cells
|
|
|
|
let max_cells = n_cells
|
|
|
|
end
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" Sum rowspan
|
|
|
|
for cell_idx in range(max_cells)
|
|
|
|
let rows = 1
|
|
|
|
|
|
|
|
for row_idx in range(len(table)-1, 1, -1)
|
|
|
|
if cell_idx >= len(table[row_idx])
|
|
|
|
let rows = 1
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if table[row_idx][cell_idx].rowspan == 0
|
|
|
|
let rows += 1
|
|
|
|
else " table[row_idx][cell_idx].rowspan == 1
|
|
|
|
let table[row_idx][cell_idx].rowspan = rows
|
|
|
|
let rows = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:sum_colspan(table) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
for row in a:table[1:]
|
|
|
|
let cols = 1
|
|
|
|
|
|
|
|
for cell_idx in range(len(row)-1, 0, -1)
|
|
|
|
if row[cell_idx].colspan == 0
|
|
|
|
let cols += 1
|
|
|
|
else "row[cell_idx].colspan == 1
|
|
|
|
let row[cell_idx].colspan = cols
|
|
|
|
let cols = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_row(row, header, ldest, header_ids) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
call add(a:ldest, '<tr>')
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" Set tag element of columns
|
2011-06-11 02:00:00 +02:00
|
|
|
if a:header
|
|
|
|
let tag_name = 'th'
|
|
|
|
else
|
|
|
|
let tag_name = 'td'
|
|
|
|
end
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" Close tag of columns
|
2011-06-11 02:00:00 +02:00
|
|
|
for cell in a:row
|
|
|
|
if cell.rowspan == 0 || cell.colspan == 0
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if cell.rowspan > 1
|
|
|
|
let rowspan_attr = ' rowspan="' . cell.rowspan . '"'
|
|
|
|
else "cell.rowspan == 1
|
|
|
|
let rowspan_attr = ''
|
|
|
|
endif
|
|
|
|
if cell.colspan > 1
|
|
|
|
let colspan_attr = ' colspan="' . cell.colspan . '"'
|
|
|
|
else "cell.colspan == 1
|
|
|
|
let colspan_attr = ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(a:ldest, '<' . tag_name . rowspan_attr . colspan_attr .'>')
|
2014-02-13 12:42:24 +01:00
|
|
|
call add(a:ldest, s:process_inline_tags(cell.body, a:header_ids))
|
2011-06-11 02:00:00 +02:00
|
|
|
call add(a:ldest, '</'. tag_name . '>')
|
|
|
|
endfor
|
|
|
|
|
|
|
|
call add(a:ldest, '</tr>')
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
let table = a:table
|
|
|
|
let ldest = a:ldest
|
|
|
|
if len(table)
|
2011-06-11 02:00:00 +02:00
|
|
|
call s:sum_rowspan(table)
|
|
|
|
call s:sum_colspan(table)
|
|
|
|
|
2015-02-09 20:05:25 +01:00
|
|
|
if table[0] ==# 'center'
|
2010-05-12 02:00:00 +02:00
|
|
|
call add(ldest, "<table class='center'>")
|
|
|
|
else
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(ldest, '<table>')
|
2010-05-12 02:00:00 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
" Empty lists are table separators.
|
|
|
|
" Search for the last empty list. All the above rows would be a table header.
|
|
|
|
" We should exclude the first element of the table list as it is a text tag
|
|
|
|
" that shows if table should be centered or not.
|
|
|
|
let head = 0
|
|
|
|
for idx in range(len(table)-1, 1, -1)
|
|
|
|
if empty(table[idx])
|
|
|
|
let head = idx
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
if head > 0
|
|
|
|
for row in table[1 : head-1]
|
|
|
|
if !empty(filter(row, '!empty(v:val)'))
|
2014-02-13 12:42:24 +01:00
|
|
|
call s:close_tag_row(row, 1, ldest, a:header_ids)
|
2010-05-12 02:00:00 +02:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
for row in table[head+1 :]
|
2014-02-13 12:42:24 +01:00
|
|
|
call s:close_tag_row(row, 0, ldest, a:header_ids)
|
2010-05-12 02:00:00 +02:00
|
|
|
endfor
|
|
|
|
else
|
|
|
|
for row in table[1 :]
|
2014-02-13 12:42:24 +01:00
|
|
|
call s:close_tag_row(row, 0, ldest, a:header_ids)
|
2010-05-12 02:00:00 +02:00
|
|
|
endfor
|
|
|
|
endif
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(ldest, '</table>')
|
2010-05-12 02:00:00 +02:00
|
|
|
let table = []
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
2010-05-12 02:00:00 +02:00
|
|
|
return table
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_list(lists, ldest) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
while len(a:lists)
|
2010-08-24 02:00:00 +02:00
|
|
|
let item = remove(a:lists, 0)
|
|
|
|
call insert(a:ldest, item[0])
|
2010-01-20 01:00:00 +01:00
|
|
|
endwhile
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:close_tag_def_list(deflist, ldest) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
if a:deflist
|
2019-12-21 04:41:03 +01:00
|
|
|
call insert(a:ldest, '</dl>')
|
2010-01-20 01:00:00 +01:00
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return a:deflist
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_pre(line, pre) abort
|
2010-08-24 02:00:00 +02:00
|
|
|
" pre is the list of [is_in_pre, indent_of_pre]
|
2012-06-07 02:00:00 +02:00
|
|
|
"XXX always outputs a single line or empty list!
|
2010-01-20 01:00:00 +01:00
|
|
|
let lines = []
|
|
|
|
let pre = a:pre
|
|
|
|
let processed = 0
|
2012-06-07 02:00:00 +02:00
|
|
|
"XXX huh?
|
2015-02-09 20:47:11 +01:00
|
|
|
"if !pre[0] && a:line =~# '^\s*{{{[^\(}}}\)]*\s*$'
|
|
|
|
if !pre[0] && a:line =~# '^\s*{{{'
|
2010-01-20 01:00:00 +01:00
|
|
|
let class = matchstr(a:line, '{{{\zs.*$')
|
2012-06-07 02:00:00 +02:00
|
|
|
"FIXME class cannot contain arbitrary strings
|
2010-01-20 01:00:00 +01:00
|
|
|
let class = substitute(class, '\s\+$', '', 'g')
|
2019-12-21 04:41:03 +01:00
|
|
|
if class !=? ''
|
|
|
|
call add(lines, '<pre '.class.'>')
|
2010-01-20 01:00:00 +01:00
|
|
|
else
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '<pre>')
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
2010-08-24 02:00:00 +02:00
|
|
|
let pre = [1, len(matchstr(a:line, '^\s*\ze{{{'))]
|
2010-01-20 01:00:00 +01:00
|
|
|
let processed = 1
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif pre[0] && a:line =~# '^\s*}}}\s*$'
|
2010-08-24 02:00:00 +02:00
|
|
|
let pre = [0, 0]
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '</pre>')
|
2010-01-20 01:00:00 +01:00
|
|
|
let processed = 1
|
2010-08-24 02:00:00 +02:00
|
|
|
elseif pre[0]
|
2010-01-20 01:00:00 +01:00
|
|
|
let processed = 1
|
2012-06-07 02:00:00 +02:00
|
|
|
"XXX destroys indent in general!
|
|
|
|
"call add(lines, substitute(a:line, '^\s\{'.pre[1].'}', '', ''))
|
2014-02-13 12:42:24 +01:00
|
|
|
call add(lines, s:safe_html_preformatted(a:line))
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return [processed, lines, pre]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_math(line, math) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
" math is the list of [is_in_math, indent_of_math]
|
|
|
|
let lines = []
|
|
|
|
let math = a:math
|
|
|
|
let processed = 0
|
2015-02-09 20:47:11 +01:00
|
|
|
if !math[0] && a:line =~# '^\s*{{\$[^\(}}$\)]*\s*$'
|
2012-06-07 02:00:00 +02:00
|
|
|
let class = matchstr(a:line, '{{$\zs.*$')
|
|
|
|
"FIXME class cannot be any string!
|
|
|
|
let class = substitute(class, '\s\+$', '', 'g')
|
2015-02-02 10:35:32 +01:00
|
|
|
" 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%')
|
2019-12-21 04:41:03 +01:00
|
|
|
if s:current_math_env !=? ''
|
2018-11-25 17:56:43 +01:00
|
|
|
call add(lines, substitute(class, '^%\(\S\+\)%', '\\begin{\1}', ''))
|
2019-12-21 04:41:03 +01:00
|
|
|
elseif class !=? ''
|
2012-06-07 02:00:00 +02:00
|
|
|
call add(lines, "\\\[".class)
|
|
|
|
else
|
|
|
|
call add(lines, "\\\[")
|
|
|
|
endif
|
|
|
|
let math = [1, len(matchstr(a:line, '^\s*\ze{{\$'))]
|
|
|
|
let processed = 1
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif math[0] && a:line =~# '^\s*}}\$\s*$'
|
2012-06-07 02:00:00 +02:00
|
|
|
let math = [0, 0]
|
2019-12-21 04:41:03 +01:00
|
|
|
if s:current_math_env !=? ''
|
|
|
|
call add(lines, "\\end{".s:current_math_env.'}')
|
2012-06-07 02:00:00 +02:00
|
|
|
else
|
|
|
|
call add(lines, "\\\]")
|
|
|
|
endif
|
|
|
|
let processed = 1
|
|
|
|
elseif math[0]
|
|
|
|
let processed = 1
|
|
|
|
call add(lines, substitute(a:line, '^\s\{'.math[1].'}', '', ''))
|
|
|
|
endif
|
|
|
|
return [processed, lines, math]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_quote(line, quote) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let lines = []
|
|
|
|
let quote = a:quote
|
|
|
|
let processed = 0
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:line =~# '^\s\{4,}\S'
|
2010-01-20 01:00:00 +01:00
|
|
|
if !quote
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '<blockquote>')
|
2010-01-20 01:00:00 +01:00
|
|
|
let quote = 1
|
|
|
|
endif
|
|
|
|
let processed = 1
|
|
|
|
call add(lines, substitute(a:line, '^\s*', '', ''))
|
|
|
|
elseif quote
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '</blockquote>')
|
2010-01-20 01:00:00 +01:00
|
|
|
let quote = 0
|
|
|
|
endif
|
|
|
|
return [processed, lines, quote]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-06-03 06:29:04 +02:00
|
|
|
function! s:process_tag_arrow_quote(line, arrow_quote) abort
|
|
|
|
let lines = []
|
|
|
|
let arrow_quote = a:arrow_quote
|
|
|
|
let processed = 0
|
2020-06-18 05:46:58 +02:00
|
|
|
if a:line =~# '^\s*>'
|
2020-06-03 06:29:04 +02:00
|
|
|
if !arrow_quote
|
|
|
|
call add(lines, '<blockquote>')
|
|
|
|
call add(lines, '<p>')
|
|
|
|
let arrow_quote = 1
|
|
|
|
endif
|
|
|
|
let processed = 1
|
2020-06-18 05:46:58 +02:00
|
|
|
let stripped_line = substitute(a:line, '^\s*>\s*', '', '')
|
2020-06-03 06:29:04 +02:00
|
|
|
if stripped_line =~# '^\s*$'
|
|
|
|
call add(lines, '</p>')
|
|
|
|
call add(lines, '<p>')
|
|
|
|
endif
|
|
|
|
call add(lines, stripped_line)
|
|
|
|
elseif arrow_quote
|
|
|
|
call add(lines, '</p>')
|
|
|
|
call add(lines, '</blockquote>')
|
|
|
|
let arrow_quote = 0
|
|
|
|
endif
|
|
|
|
return [processed, lines, arrow_quote]
|
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_list(line, lists) abort
|
|
|
|
function! s:add_checkbox(line, rx_list) abort
|
2014-02-03 11:41:55 +01:00
|
|
|
let st_tag = '<li>'
|
2010-01-20 01:00:00 +01:00
|
|
|
let chk = matchlist(a:line, a:rx_list)
|
2014-02-03 11:41:55 +01:00
|
|
|
if !empty(chk) && len(chk[1]) > 0
|
2020-06-04 18:33:12 +02:00
|
|
|
let completion = index(vimwiki#vars#get_wikilocal('listsyms_list'), chk[1])
|
|
|
|
let n = len(vimwiki#vars#get_wikilocal('listsyms_list'))
|
2017-01-22 20:16:10 +01:00
|
|
|
if completion == 0
|
|
|
|
let st_tag = '<li class="done0">'
|
2018-02-19 07:07:22 +01:00
|
|
|
elseif completion == -1 && chk[1] == vimwiki#vars#get_global('listsym_rejected')
|
2017-08-05 00:20:37 +02:00
|
|
|
let st_tag = '<li class="rejected">'
|
2017-01-22 20:16:10 +01:00
|
|
|
elseif completion > 0 && completion < n
|
|
|
|
let completion = float2nr(round(completion / (n-1.0) * 3.0 + 0.5 ))
|
2014-02-03 11:41:55 +01:00
|
|
|
let st_tag = '<li class="done'.completion.'">'
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
endif
|
2014-02-03 11:41:55 +01:00
|
|
|
return [st_tag, '']
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
let in_list = (len(a:lists) > 0)
|
|
|
|
|
|
|
|
" If it is not list yet then do not process line that starts from *bold*
|
|
|
|
" text.
|
2014-02-03 11:41:55 +01:00
|
|
|
" XXX necessary? in *bold* text, no space must follow the first *
|
2010-05-12 02:00:00 +02:00
|
|
|
if !in_list
|
2017-01-07 21:51:15 +01:00
|
|
|
let pos = match(a:line, '^\s*'.vimwiki#vars#get_syntaxlocal('rxBold'))
|
2014-02-03 11:41:55 +01:00
|
|
|
if pos != -1
|
2010-05-12 02:00:00 +02:00
|
|
|
return [0, []]
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
|
|
|
let lines = []
|
|
|
|
let processed = 0
|
|
|
|
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:line =~# '^\s*'.s:bullets.'\s'
|
2014-02-03 11:41:55 +01:00
|
|
|
let lstSym = matchstr(a:line, s:bullets)
|
2010-01-20 01:00:00 +01:00
|
|
|
let lstTagOpen = '<ul>'
|
|
|
|
let lstTagClose = '</ul>'
|
2014-02-03 11:41:55 +01:00
|
|
|
let lstRegExp = '^\s*'.s:bullets.'\s'
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif a:line =~# '^\s*'.s:numbers.'\s'
|
2014-02-03 11:41:55 +01:00
|
|
|
let lstSym = matchstr(a:line, s:numbers)
|
2010-01-20 01:00:00 +01:00
|
|
|
let lstTagOpen = '<ol>'
|
|
|
|
let lstTagClose = '</ol>'
|
2014-02-03 11:41:55 +01:00
|
|
|
let lstRegExp = '^\s*'.s:numbers.'\s'
|
2010-01-20 01:00:00 +01:00
|
|
|
else
|
|
|
|
let lstSym = ''
|
|
|
|
let lstTagOpen = ''
|
|
|
|
let lstTagClose = ''
|
|
|
|
let lstRegExp = ''
|
|
|
|
endif
|
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
if lstSym !=? ''
|
2010-01-20 01:00:00 +01:00
|
|
|
" To get proper indent level 'retab' the line -- change all tabs
|
|
|
|
" to spaces*tabstop
|
|
|
|
let line = substitute(a:line, '\t', repeat(' ', &tabstop), 'g')
|
|
|
|
let indent = stridx(line, lstSym)
|
|
|
|
|
2014-02-03 11:41:55 +01:00
|
|
|
let checkbox = '\s*\[\(.\)\]\s*'
|
|
|
|
let [st_tag, en_tag] = s:add_checkbox(line, lstRegExp.checkbox)
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
if !in_list
|
|
|
|
call add(a:lists, [lstTagClose, indent])
|
|
|
|
call add(lines, lstTagOpen)
|
|
|
|
elseif (in_list && indent > a:lists[-1][1])
|
|
|
|
let item = remove(a:lists, -1)
|
|
|
|
call add(lines, item[0])
|
|
|
|
|
|
|
|
call add(a:lists, [lstTagClose, indent])
|
|
|
|
call add(lines, lstTagOpen)
|
|
|
|
elseif (in_list && indent < a:lists[-1][1])
|
|
|
|
while len(a:lists) && indent < a:lists[-1][1]
|
|
|
|
let item = remove(a:lists, -1)
|
|
|
|
call add(lines, item[0])
|
|
|
|
endwhile
|
|
|
|
elseif in_list
|
|
|
|
let item = remove(a:lists, -1)
|
|
|
|
call add(lines, item[0])
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(a:lists, [en_tag, indent])
|
|
|
|
call add(lines, st_tag)
|
2018-04-20 07:03:53 +02:00
|
|
|
call add(lines, substitute(a:line, lstRegExp.'\%('.checkbox.'\)\?', '', ''))
|
2010-01-20 01:00:00 +01:00
|
|
|
let processed = 1
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif in_list && a:line =~# '^\s\+\S\+'
|
2016-12-21 21:28:48 +01:00
|
|
|
if vimwiki#vars#get_global('list_ignore_newline')
|
2010-01-20 01:00:00 +01:00
|
|
|
call add(lines, a:line)
|
|
|
|
else
|
|
|
|
call add(lines, '<br />'.a:line)
|
|
|
|
endif
|
|
|
|
let processed = 1
|
|
|
|
else
|
2010-05-12 02:00:00 +02:00
|
|
|
call s:close_tag_list(a:lists, lines)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return [processed, lines]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_def_list(line, deflist) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let lines = []
|
|
|
|
let deflist = a:deflist
|
|
|
|
let processed = 0
|
|
|
|
let matches = matchlist(a:line, '\(^.*\)::\%(\s\|$\)\(.*\)')
|
|
|
|
if !deflist && len(matches) > 0
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '<dl>')
|
2010-01-20 01:00:00 +01:00
|
|
|
let deflist = 1
|
|
|
|
endif
|
|
|
|
if deflist && len(matches) > 0
|
2019-12-21 04:41:03 +01:00
|
|
|
if matches[1] !=? ''
|
|
|
|
call add(lines, '<dt>'.matches[1].'</dt>')
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
2019-12-21 04:41:03 +01:00
|
|
|
if matches[2] !=? ''
|
|
|
|
call add(lines, '<dd>'.matches[2].'</dd>')
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
let processed = 1
|
|
|
|
elseif deflist
|
|
|
|
let deflist = 0
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '</dl>')
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return [processed, lines, deflist]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_para(line, para) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let lines = []
|
|
|
|
let para = a:para
|
|
|
|
let processed = 0
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:line =~# '^\s\{,3}\S'
|
2010-01-20 01:00:00 +01:00
|
|
|
if !para
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '<p>')
|
2010-01-20 01:00:00 +01:00
|
|
|
let para = 1
|
|
|
|
endif
|
|
|
|
let processed = 1
|
2018-02-16 07:26:42 +01:00
|
|
|
if vimwiki#vars#get_global('text_ignore_newline')
|
2017-01-06 07:01:48 +01:00
|
|
|
call add(lines, a:line)
|
|
|
|
else
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, a:line.'<br />')
|
2017-01-06 07:01:48 +01:00
|
|
|
endif
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif para && a:line =~# '^\s*$'
|
2019-12-21 04:41:03 +01:00
|
|
|
call add(lines, '</p>')
|
2010-01-20 01:00:00 +01:00
|
|
|
let para = 0
|
|
|
|
endif
|
|
|
|
return [processed, lines, para]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_h(line, id) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let line = a:line
|
|
|
|
let processed = 0
|
|
|
|
let h_level = 0
|
|
|
|
let h_text = ''
|
|
|
|
let h_id = ''
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2017-01-07 21:51:15 +01:00
|
|
|
if a:line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
|
2012-06-07 02:00:00 +02:00
|
|
|
let h_level = vimwiki#u#count_first_sym(a:line)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
if h_level > 0
|
|
|
|
|
2017-01-07 21:51:15 +01:00
|
|
|
let h_text = vimwiki#u#trim(matchstr(line, vimwiki#vars#get_syntaxlocal('rxHeader')))
|
2010-05-12 02:00:00 +02:00
|
|
|
let h_number = ''
|
2014-02-13 12:42:24 +01:00
|
|
|
let h_complete_id = ''
|
2018-04-16 20:40:18 +02:00
|
|
|
let h_id = s:escape_html_attribute(h_text)
|
2015-02-09 20:47:11 +01:00
|
|
|
let centered = (a:line =~# '^\s')
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2016-12-21 21:28:48 +01:00
|
|
|
if h_text !=# vimwiki#vars#get_global('toc_header')
|
2014-02-13 12:42:24 +01:00
|
|
|
|
|
|
|
let a:id[h_level-1] = [h_text, a:id[h_level-1][1]+1]
|
|
|
|
|
|
|
|
" reset higher level ids
|
|
|
|
for level in range(h_level, 5)
|
|
|
|
let a:id[level] = ['', 0]
|
|
|
|
endfor
|
|
|
|
|
|
|
|
for l in range(h_level-1)
|
|
|
|
let h_number .= a:id[l][1].'.'
|
2019-12-21 04:41:03 +01:00
|
|
|
if a:id[l][0] !=? ''
|
2014-02-13 12:42:24 +01:00
|
|
|
let h_complete_id .= a:id[l][0].'-'
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
let h_number .= a:id[h_level-1][1]
|
|
|
|
let h_complete_id .= a:id[h_level-1][0]
|
|
|
|
|
2016-12-21 19:43:34 +01:00
|
|
|
if vimwiki#vars#get_global('html_header_numbering')
|
2014-02-13 12:42:24 +01:00
|
|
|
let num = matchstr(h_number,
|
2016-12-21 19:43:34 +01:00
|
|
|
\ '^\(\d.\)\{'.(vimwiki#vars#get_global('html_header_numbering')-1).'}\zs.*')
|
2014-02-13 12:42:24 +01:00
|
|
|
if !empty(num)
|
2016-12-21 19:43:34 +01:00
|
|
|
let num .= vimwiki#vars#get_global('html_header_numbering_sym')
|
2014-02-13 12:42:24 +01:00
|
|
|
endif
|
|
|
|
let h_text = num.' '.h_text
|
|
|
|
endif
|
2018-04-16 20:40:18 +02:00
|
|
|
let h_complete_id = s:escape_html_attribute(h_complete_id)
|
2018-10-14 23:31:26 +02:00
|
|
|
let h_part = '<div id="'.h_complete_id.'">'
|
|
|
|
let h_part .= '<h'.h_level.' id="'.h_id.'" class="header">'
|
|
|
|
let h_part .= '<a href="#'.h_complete_id.'"'
|
2014-02-13 12:42:24 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
|
2019-03-13 15:28:22 +01:00
|
|
|
let h_part = '<div id="'.h_id.'" class="toc"><h'.h_level.' id="'.h_id.'"'
|
2014-02-13 12:42:24 +01:00
|
|
|
|
|
|
|
endif
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
if centered
|
|
|
|
let h_part .= ' class="justcenter">'
|
|
|
|
else
|
|
|
|
let h_part .= '>'
|
|
|
|
endif
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2016-01-22 13:32:01 +01:00
|
|
|
let h_text = s:process_inline_tags(h_text, a:id)
|
|
|
|
|
2018-10-14 23:31:26 +02:00
|
|
|
let line = h_part.h_text.'</a></h'.h_level.'></div>'
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
let processed = 1
|
|
|
|
endif
|
2014-02-13 12:42:24 +01:00
|
|
|
return [processed, line]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_hr(line) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let line = a:line
|
|
|
|
let processed = 0
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:line =~# '^-----*$'
|
2010-01-20 01:00:00 +01:00
|
|
|
let line = '<hr />'
|
|
|
|
let processed = 1
|
|
|
|
endif
|
|
|
|
return [processed, line]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:process_tag_table(line, table, header_ids) abort
|
|
|
|
function! s:table_empty_cell(value) abort
|
2011-06-11 02:00:00 +02:00
|
|
|
let cell = {}
|
|
|
|
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:value =~# '^\s*\\/\s*$'
|
2011-06-11 02:00:00 +02:00
|
|
|
let cell.body = ''
|
|
|
|
let cell.rowspan = 0
|
|
|
|
let cell.colspan = 1
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif a:value =~# '^\s*>\s*$'
|
2011-06-11 02:00:00 +02:00
|
|
|
let cell.body = ''
|
|
|
|
let cell.rowspan = 1
|
|
|
|
let cell.colspan = 0
|
2015-02-09 20:47:11 +01:00
|
|
|
elseif a:value =~# '^\s*$'
|
2011-06-11 02:00:00 +02:00
|
|
|
let cell.body = ' '
|
|
|
|
let cell.rowspan = 1
|
|
|
|
let cell.colspan = 1
|
|
|
|
else
|
|
|
|
let cell.body = a:value
|
|
|
|
let cell.rowspan = 1
|
|
|
|
let cell.colspan = 1
|
2010-05-12 02:00:00 +02:00
|
|
|
endif
|
2011-06-11 02:00:00 +02:00
|
|
|
|
|
|
|
return cell
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:table_add_row(table, line) abort
|
2010-05-12 02:00:00 +02:00
|
|
|
if empty(a:table)
|
2015-02-09 20:47:11 +01:00
|
|
|
if a:line =~# '^\s\+'
|
2010-05-12 02:00:00 +02:00
|
|
|
let row = ['center', []]
|
|
|
|
else
|
|
|
|
let row = ['normal', []]
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let row = [[]]
|
|
|
|
endif
|
|
|
|
return row
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
let table = a:table
|
|
|
|
let lines = []
|
|
|
|
let processed = 0
|
2010-02-23 01:00:00 +01:00
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
if vimwiki#tbl#is_separator(a:line)
|
2010-05-12 02:00:00 +02:00
|
|
|
call extend(table, s:table_add_row(a:table, a:line))
|
2010-02-23 01:00:00 +01:00
|
|
|
let processed = 1
|
2012-06-07 02:00:00 +02:00
|
|
|
elseif vimwiki#tbl#is_table(a:line)
|
2010-05-12 02:00:00 +02:00
|
|
|
call extend(table, s:table_add_row(a:table, a:line))
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
let processed = 1
|
2012-06-07 02:00:00 +02:00
|
|
|
" let cells = split(a:line, vimwiki#tbl#cell_splitter(), 1)[1: -2]
|
|
|
|
let cells = vimwiki#tbl#get_cells(a:line)
|
2010-05-12 02:00:00 +02:00
|
|
|
call map(cells, 's:table_empty_cell(v:val)')
|
|
|
|
call extend(table[-1], cells)
|
|
|
|
else
|
2014-02-13 12:42:24 +01:00
|
|
|
let table = s:close_tag_table(table, lines, a:header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
return [processed, lines, table]
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2010-08-24 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:parse_line(line, state) abort
|
2010-01-20 01:00:00 +01:00
|
|
|
let state = {}
|
|
|
|
let state.para = a:state.para
|
|
|
|
let state.quote = a:state.quote
|
2020-06-03 06:29:04 +02:00
|
|
|
let state.arrow_quote = a:state.arrow_quote
|
2010-08-24 02:00:00 +02:00
|
|
|
let state.pre = a:state.pre[:]
|
2012-06-07 02:00:00 +02:00
|
|
|
let state.math = a:state.math[:]
|
2010-02-23 01:00:00 +01:00
|
|
|
let state.table = a:state.table[:]
|
2010-01-20 01:00:00 +01:00
|
|
|
let state.lists = a:state.lists[:]
|
|
|
|
let state.deflist = a:state.deflist
|
|
|
|
let state.placeholder = a:state.placeholder
|
2014-02-13 12:42:24 +01:00
|
|
|
let state.header_ids = a:state.header_ids
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
let res_lines = []
|
|
|
|
let processed = 0
|
2020-04-20 22:13:03 +02:00
|
|
|
let line = a:line
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-11-24 17:51:51 +01:00
|
|
|
if !processed
|
|
|
|
" allows insertion of plain text to the final html conversion
|
|
|
|
" for example:
|
|
|
|
" %plainhtml <div class="mycustomdiv">
|
2020-04-20 22:13:03 +02:00
|
|
|
" inserts the line above to the final html file (without %plainhtml prefix)
|
2019-11-24 17:51:51 +01:00
|
|
|
let trigger = '%plainhtml'
|
|
|
|
if line =~# '^\s*' . trigger
|
|
|
|
let lines = []
|
|
|
|
let processed = 1
|
|
|
|
|
|
|
|
" if something precedes the plain text line,
|
|
|
|
" make sure everything gets closed properly
|
|
|
|
" before inserting plain text. this ensures that
|
|
|
|
" the plain text is not considered as
|
|
|
|
" part of the preceding structure
|
|
|
|
if processed && len(state.table)
|
|
|
|
let state.table = s:close_tag_table(state.table, lines, state.header_ids)
|
|
|
|
endif
|
|
|
|
if processed && state.deflist
|
|
|
|
let state.deflist = s:close_tag_def_list(state.deflist, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.quote
|
|
|
|
let state.quote = s:close_tag_quote(state.quote, lines)
|
|
|
|
endif
|
2020-06-03 06:29:04 +02:00
|
|
|
if processed && state.arrow_quote
|
|
|
|
let state.arrow_quote = s:close_tag_arrow_quote(state.arrow_quote, lines)
|
|
|
|
endif
|
2019-11-24 17:51:51 +01:00
|
|
|
if processed && state.para
|
|
|
|
let state.para = s:close_tag_para(state.para, lines)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" remove the trigger prefix
|
|
|
|
let pp = split(line, trigger)[0]
|
|
|
|
|
|
|
|
call add(lines, pp)
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2020-04-20 22:13:03 +02:00
|
|
|
let line = s:safe_html_line(a:line)
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" pres
|
2014-12-16 15:52:53 +01:00
|
|
|
if !processed
|
|
|
|
let [processed, lines, state.pre] = s:process_tag_pre(line, state.pre)
|
|
|
|
" pre is just fine to be in the list -- do not close list item here.
|
|
|
|
" if processed && len(state.lists)
|
|
|
|
" call s:close_tag_list(state.lists, lines)
|
|
|
|
" endif
|
|
|
|
if !processed
|
|
|
|
let [processed, lines, state.math] = s:process_tag_math(line, state.math)
|
|
|
|
endif
|
|
|
|
if processed && len(state.table)
|
|
|
|
let state.table = s:close_tag_table(state.table, lines, state.header_ids)
|
|
|
|
endif
|
|
|
|
if processed && state.deflist
|
|
|
|
let state.deflist = s:close_tag_def_list(state.deflist, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.quote
|
|
|
|
let state.quote = s:close_tag_quote(state.quote, lines)
|
|
|
|
endif
|
2020-06-03 06:29:04 +02:00
|
|
|
if processed && state.arrow_quote
|
|
|
|
let state.arrow_quote = s:close_tag_arrow_quote(state.arrow_quote, lines)
|
|
|
|
endif
|
2014-12-16 15:52:53 +01:00
|
|
|
if processed && state.para
|
|
|
|
let state.para = s:close_tag_para(state.para, lines)
|
|
|
|
endif
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2014-12-16 15:52:53 +01:00
|
|
|
|
2011-06-11 02:00:00 +02:00
|
|
|
if !processed
|
2017-01-07 21:51:15 +01:00
|
|
|
if line =~# vimwiki#vars#get_syntaxlocal('rxComment')
|
2011-06-11 02:00:00 +02:00
|
|
|
let processed = 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2010-05-12 02:00:00 +02:00
|
|
|
" nohtml -- placeholder
|
|
|
|
if !processed
|
2017-07-08 22:06:18 +02:00
|
|
|
if line =~# '\m^\s*%nohtml\s*$'
|
2010-05-12 02:00:00 +02:00
|
|
|
let processed = 1
|
|
|
|
let state.placeholder = ['nohtml']
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2010-08-24 02:00:00 +02:00
|
|
|
" title -- placeholder
|
|
|
|
if !processed
|
2017-07-08 22:06:18 +02:00
|
|
|
if line =~# '\m^\s*%title\%(\s.*\)\?$'
|
2010-08-24 02:00:00 +02:00
|
|
|
let processed = 1
|
2017-07-08 22:06:18 +02:00
|
|
|
let param = matchstr(line, '\m^\s*%title\s\+\zs.*')
|
2010-08-24 02:00:00 +02:00
|
|
|
let state.placeholder = ['title', param]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-07-08 21:04:54 +02:00
|
|
|
" date -- placeholder
|
|
|
|
if !processed
|
2017-07-08 22:06:18 +02:00
|
|
|
if line =~# '\m^\s*%date\%(\s.*\)\?$'
|
2017-07-08 21:04:54 +02:00
|
|
|
let processed = 1
|
2017-07-08 22:06:18 +02:00
|
|
|
let param = matchstr(line, '\m^\s*%date\s\+\zs.*')
|
2017-07-08 21:04:54 +02:00
|
|
|
let state.placeholder = ['date', param]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
" html template -- placeholder
|
2011-06-11 02:00:00 +02:00
|
|
|
if !processed
|
2017-07-08 22:06:18 +02:00
|
|
|
if line =~# '\m^\s*%template\%(\s.*\)\?$'
|
2011-06-11 02:00:00 +02:00
|
|
|
let processed = 1
|
2017-07-08 22:06:18 +02:00
|
|
|
let param = matchstr(line, '\m^\s*%template\s\+\zs.*')
|
2011-06-11 02:00:00 +02:00
|
|
|
let state.placeholder = ['template', param]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" tables
|
2014-06-05 09:42:59 +02:00
|
|
|
if !processed
|
2018-04-20 07:03:53 +02:00
|
|
|
let [processed, lines, state.table] = s:process_tag_table(line, state.table, state.header_ids)
|
2014-06-05 09:42:59 +02:00
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" lists
|
2010-01-20 01:00:00 +01:00
|
|
|
if !processed
|
|
|
|
let [processed, lines] = s:process_tag_list(line, state.lists)
|
|
|
|
if processed && state.quote
|
|
|
|
let state.quote = s:close_tag_quote(state.quote, lines)
|
|
|
|
endif
|
2020-06-03 06:29:04 +02:00
|
|
|
if processed && state.arrow_quote
|
|
|
|
let state.arrow_quote = s:close_tag_arrow_quote(state.arrow_quote, lines)
|
|
|
|
endif
|
2010-08-24 02:00:00 +02:00
|
|
|
if processed && state.pre[0]
|
2010-01-20 01:00:00 +01:00
|
|
|
let state.pre = s:close_tag_pre(state.pre, lines)
|
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
if processed && state.math[0]
|
|
|
|
let state.math = s:close_tag_math(state.math, lines)
|
|
|
|
endif
|
2010-02-23 01:00:00 +01:00
|
|
|
if processed && len(state.table)
|
2014-02-13 12:42:24 +01:00
|
|
|
let state.table = s:close_tag_table(state.table, lines, state.header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
if processed && state.deflist
|
|
|
|
let state.deflist = s:close_tag_def_list(state.deflist, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.para
|
|
|
|
let state.para = s:close_tag_para(state.para, lines)
|
|
|
|
endif
|
|
|
|
|
2014-02-13 12:42:24 +01:00
|
|
|
call map(lines, 's:process_inline_tags(v:val, state.header_ids)')
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" headers
|
2010-01-20 01:00:00 +01:00
|
|
|
if !processed
|
2014-02-13 12:42:24 +01:00
|
|
|
let [processed, line] = s:process_tag_h(line, state.header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
if processed
|
|
|
|
call s:close_tag_list(state.lists, res_lines)
|
2018-04-20 07:03:53 +02:00
|
|
|
let state.table = s:close_tag_table(state.table, res_lines, state.header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
let state.pre = s:close_tag_pre(state.pre, res_lines)
|
2012-06-07 02:00:00 +02:00
|
|
|
let state.math = s:close_tag_math(state.math, res_lines)
|
2020-06-03 06:29:04 +02:00
|
|
|
let state.quote = s:close_tag_quote(state.quote || state.arrow_quote, res_lines)
|
|
|
|
let state.arrow_quote = s:close_tag_arrow_quote(state.arrow_quote, lines)
|
2011-06-11 02:00:00 +02:00
|
|
|
let state.para = s:close_tag_para(state.para, res_lines)
|
2010-02-23 01:00:00 +01:00
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
call add(res_lines, line)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" quotes
|
2010-01-20 01:00:00 +01:00
|
|
|
if !processed
|
|
|
|
let [processed, lines, state.quote] = s:process_tag_quote(line, state.quote)
|
|
|
|
if processed && len(state.lists)
|
|
|
|
call s:close_tag_list(state.lists, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.deflist
|
|
|
|
let state.deflist = s:close_tag_def_list(state.deflist, lines)
|
|
|
|
endif
|
2020-06-03 06:29:04 +02:00
|
|
|
if processed && state.arrow_quote
|
|
|
|
let state.quote = s:close_tag_arrow_quote(state.arrow_quote, lines)
|
|
|
|
endif
|
|
|
|
if processed && len(state.table)
|
|
|
|
let state.table = s:close_tag_table(state.table, lines, state.header_ids)
|
|
|
|
endif
|
|
|
|
if processed && state.pre[0]
|
|
|
|
let state.pre = s:close_tag_pre(state.pre, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.math[0]
|
|
|
|
let state.math = s:close_tag_math(state.math, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.para
|
|
|
|
let state.para = s:close_tag_para(state.para, lines)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call map(lines, 's:process_inline_tags(v:val, state.header_ids)')
|
|
|
|
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" arrow quotes
|
|
|
|
if !processed
|
|
|
|
let [processed, lines, state.arrow_quote] = s:process_tag_arrow_quote(line, state.arrow_quote)
|
|
|
|
if processed && state.quote
|
|
|
|
let state.quote = s:close_tag_quote(state.quote, lines)
|
|
|
|
endif
|
|
|
|
if processed && len(state.lists)
|
|
|
|
call s:close_tag_list(state.lists, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.deflist
|
|
|
|
let state.deflist = s:close_tag_def_list(state.deflist, lines)
|
|
|
|
endif
|
2010-02-23 01:00:00 +01:00
|
|
|
if processed && len(state.table)
|
2014-02-13 12:42:24 +01:00
|
|
|
let state.table = s:close_tag_table(state.table, lines, state.header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
2010-08-24 02:00:00 +02:00
|
|
|
if processed && state.pre[0]
|
2010-01-20 01:00:00 +01:00
|
|
|
let state.pre = s:close_tag_pre(state.pre, lines)
|
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
if processed && state.math[0]
|
|
|
|
let state.math = s:close_tag_math(state.math, lines)
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
if processed && state.para
|
|
|
|
let state.para = s:close_tag_para(state.para, lines)
|
|
|
|
endif
|
|
|
|
|
2014-02-13 12:42:24 +01:00
|
|
|
call map(lines, 's:process_inline_tags(v:val, state.header_ids)')
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" horizontal rules
|
2010-01-20 01:00:00 +01:00
|
|
|
if !processed
|
|
|
|
let [processed, line] = s:process_tag_hr(line)
|
|
|
|
if processed
|
|
|
|
call s:close_tag_list(state.lists, res_lines)
|
2018-04-20 07:03:53 +02:00
|
|
|
let state.table = s:close_tag_table(state.table, res_lines, state.header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
let state.pre = s:close_tag_pre(state.pre, res_lines)
|
2012-06-07 02:00:00 +02:00
|
|
|
let state.math = s:close_tag_math(state.math, res_lines)
|
2010-01-20 01:00:00 +01:00
|
|
|
call add(res_lines, line)
|
|
|
|
endif
|
|
|
|
endif
|
2010-02-23 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
" definition lists
|
2010-02-23 01:00:00 +01:00
|
|
|
if !processed
|
|
|
|
let [processed, lines, state.deflist] = s:process_tag_def_list(line, state.deflist)
|
|
|
|
|
2014-02-13 12:42:24 +01:00
|
|
|
call map(lines, 's:process_inline_tags(v:val, state.header_ids)')
|
2010-02-23 01:00:00 +01:00
|
|
|
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
|
|
|
"" P
|
2010-01-20 01:00:00 +01:00
|
|
|
if !processed
|
|
|
|
let [processed, lines, state.para] = s:process_tag_para(line, state.para)
|
|
|
|
if processed && len(state.lists)
|
|
|
|
call s:close_tag_list(state.lists, lines)
|
|
|
|
endif
|
2020-06-03 06:29:04 +02:00
|
|
|
if processed && (state.quote || state.arrow_quote)
|
|
|
|
let state.quote = s:close_tag_quote(state.quote || state.arrow_quote, lines)
|
|
|
|
endif
|
|
|
|
if processed && state.arrow_quote
|
|
|
|
let state.arrow_quote = s:close_tag_arrow_quote(state.arrow_quote, lines)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
2010-08-24 02:00:00 +02:00
|
|
|
if processed && state.pre[0]
|
2010-01-20 01:00:00 +01:00
|
|
|
let state.pre = s:close_tag_pre(state.pre, res_lines)
|
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
if processed && state.math[0]
|
|
|
|
let state.math = s:close_tag_math(state.math, res_lines)
|
|
|
|
endif
|
2010-02-23 01:00:00 +01:00
|
|
|
if processed && len(state.table)
|
2018-04-20 07:03:53 +02:00
|
|
|
let state.table = s:close_tag_table(state.table, res_lines, state.header_ids)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2014-02-13 12:42:24 +01:00
|
|
|
call map(lines, 's:process_inline_tags(v:val, state.header_ids)')
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
call extend(res_lines, lines)
|
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
"" add the rest
|
|
|
|
if !processed
|
|
|
|
call add(res_lines, line)
|
|
|
|
endif
|
|
|
|
|
|
|
|
return [res_lines, state]
|
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:use_custom_wiki2html() abort
|
2016-12-22 18:16:05 +01:00
|
|
|
let custom_wiki2html = vimwiki#vars#get_wikilocal('custom_wiki2html')
|
2018-04-20 07:03:53 +02:00
|
|
|
return !empty(custom_wiki2html) &&
|
|
|
|
\ (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html))
|
|
|
|
endfunction
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) abort
|
2014-12-04 21:12:04 +01:00
|
|
|
call vimwiki#path#mkdir(a:path)
|
2019-11-29 08:03:27 +01:00
|
|
|
let output = system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '.
|
2012-06-07 02:00:00 +02:00
|
|
|
\ a:force. ' '.
|
2016-12-23 20:05:53 +01:00
|
|
|
\ vimwiki#vars#get_wikilocal('syntax'). ' '.
|
2016-12-22 21:00:19 +01:00
|
|
|
\ strpart(vimwiki#vars#get_wikilocal('ext'), 1). ' '.
|
2014-03-03 09:19:59 +01:00
|
|
|
\ shellescape(a:path). ' '.
|
|
|
|
\ shellescape(a:wikifile). ' '.
|
|
|
|
\ shellescape(s:default_CSS_full_name(a:path)). ' '.
|
2018-04-20 07:03:53 +02:00
|
|
|
\ (len(vimwiki#vars#get_wikilocal('template_path')) > 1 ?
|
|
|
|
\ 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'))) : '-'). ' '.
|
|
|
|
\ (len(vimwiki#vars#get_wikilocal('custom_wiki2html_args')) > 0 ?
|
|
|
|
\ vimwiki#vars#get_wikilocal('custom_wiki2html_args') : '-'))
|
2019-11-29 08:03:27 +01:00
|
|
|
" Echo if non void
|
2019-12-21 04:41:03 +01:00
|
|
|
if output !~? '^\s*$'
|
2019-11-29 08:03:27 +01:00
|
|
|
echomsg output
|
|
|
|
endif
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2020-07-05 17:54:46 +02:00
|
|
|
function! s:convert_file_to_lines(wikifile, current_html_file) abort
|
2020-07-05 17:53:56 +02:00
|
|
|
let result = {}
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2015-04-09 14:48:26 +02:00
|
|
|
" the currently processed file name is needed when processing links
|
|
|
|
" yeah yeah, shame on me for using (quasi-) global variables
|
2020-07-05 17:53:56 +02:00
|
|
|
let s:current_wiki_file = a:wikifile
|
|
|
|
let s:current_html_file = a:current_html_file
|
2015-04-09 14:48:26 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
let lsource = readfile(a:wikifile)
|
|
|
|
let ldest = []
|
2010-05-12 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" nohtml placeholder -- to skip html generation.
|
|
|
|
let nohtml = 0
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" template placeholder
|
|
|
|
let template_name = ''
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" for table of contents placeholders.
|
|
|
|
let placeholders = []
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" current state of converter
|
|
|
|
let state = {}
|
|
|
|
let state.para = 0
|
|
|
|
let state.quote = 0
|
|
|
|
let state.arrow_quote = 0
|
|
|
|
let state.pre = [0, 0] " [in_pre, indent_pre]
|
|
|
|
let state.math = [0, 0] " [in_math, indent_math]
|
|
|
|
let state.table = []
|
|
|
|
let state.deflist = 0
|
|
|
|
let state.lists = []
|
|
|
|
let state.placeholder = []
|
|
|
|
let state.header_ids = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]]
|
|
|
|
" [last seen header text in this level, number]
|
|
|
|
|
|
|
|
" prepare constants for s:safe_html_line()
|
|
|
|
let s:lt_pattern = '<'
|
|
|
|
let s:gt_pattern = '>'
|
|
|
|
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\{-}\)\{-}/\?\)\@<!>'
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" prepare regexps for lists
|
|
|
|
let s:bullets = vimwiki#vars#get_wikilocal('rx_bullet_char')
|
|
|
|
let s:numbers = '\C\%(#\|\d\+)\|\d\+\.\|[ivxlcdm]\+)\|[IVXLCDM]\+)\|\l\{1,2})\|\u\{1,2})\)'
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
for line in lsource
|
|
|
|
let oldquote = state.quote
|
|
|
|
let [lines, state] = s:parse_line(line, state)
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" Hack: There could be a lot of empty strings before s:process_tag_quote
|
|
|
|
" find out `quote` is over. So we should delete them all. Think of the way
|
|
|
|
" to refactor it out.
|
|
|
|
if oldquote != state.quote
|
|
|
|
call s:remove_blank_lines(ldest)
|
2010-01-20 01:00:00 +01:00
|
|
|
endif
|
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
if !empty(state.placeholder)
|
|
|
|
if state.placeholder[0] ==# 'nohtml'
|
|
|
|
let nohtml = 1
|
|
|
|
break
|
|
|
|
elseif state.placeholder[0] ==# 'template'
|
|
|
|
let template_name = state.placeholder[1]
|
|
|
|
else
|
|
|
|
call add(placeholders, [state.placeholder, len(ldest), len(placeholders)])
|
|
|
|
endif
|
|
|
|
let state.placeholder = []
|
|
|
|
endif
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
call extend(ldest, lines)
|
2020-07-05 17:53:56 +02:00
|
|
|
endfor
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
let result['nohtml'] = nohtml
|
|
|
|
if nohtml
|
|
|
|
echon "\r".'%nohtml placeholder found'
|
|
|
|
return result
|
|
|
|
endif
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
call s:remove_blank_lines(ldest)
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
" process end of file
|
|
|
|
" close opened tags if any
|
|
|
|
let lines = []
|
|
|
|
call s:close_tag_quote(state.quote, lines)
|
|
|
|
call s:close_tag_arrow_quote(state.arrow_quote, lines)
|
|
|
|
call s:close_tag_para(state.para, lines)
|
|
|
|
call s:close_tag_pre(state.pre, lines)
|
|
|
|
call s:close_tag_math(state.math, lines)
|
|
|
|
call s:close_tag_list(state.lists, lines)
|
|
|
|
call s:close_tag_def_list(state.deflist, lines)
|
|
|
|
call s:close_tag_table(state.table, lines, state.header_ids)
|
|
|
|
call extend(ldest, lines)
|
|
|
|
|
|
|
|
let result['html'] = ldest
|
|
|
|
|
|
|
|
let result['template_name'] = template_name
|
|
|
|
let result['title'] = s:process_title(placeholders, fnamemodify(a:wikifile, ':t:r'))
|
|
|
|
let result['date'] = s:process_date(placeholders, strftime('%Y-%m-%d'))
|
|
|
|
let result['wiki_path'] = strpart(s:current_wiki_file, strlen(vimwiki#vars#get_wikilocal('path')))
|
|
|
|
|
|
|
|
return result
|
|
|
|
endfunction
|
|
|
|
|
2020-07-05 17:54:46 +02:00
|
|
|
function! s:convert_file_to_lines_template(wikifile, current_html_file) abort
|
2020-07-05 17:53:56 +02:00
|
|
|
let converted = s:convert_file_to_lines(a:wikifile, a:current_html_file)
|
|
|
|
if converted['nohtml'] == 1
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
let html_lines = s:get_html_template(converted['template_name'])
|
|
|
|
|
|
|
|
" processing template variables (refactor to a function)
|
|
|
|
call map(html_lines, 'substitute(v:val, "%title%", "'. converted['title'] .'", "g")')
|
|
|
|
call map(html_lines, 'substitute(v:val, "%date%", "'. converted['date'] .'", "g")')
|
|
|
|
call map(html_lines, 'substitute(v:val, "%root_path%", "'.
|
|
|
|
\ s:root_path(vimwiki#vars#get_bufferlocal('subdir')) .'", "g")')
|
|
|
|
call map(html_lines, 'substitute(v:val, "%wiki_path%", "'. converted['wiki_path'] .'", "g")')
|
|
|
|
|
|
|
|
let css_name = expand(vimwiki#vars#get_wikilocal('css_name'))
|
|
|
|
let css_name = substitute(css_name, '\', '/', 'g')
|
|
|
|
call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")')
|
|
|
|
|
2020-07-05 17:54:46 +02:00
|
|
|
let rss_name = expand(vimwiki#vars#get_wikilocal('rss_name'))
|
|
|
|
let rss_name = substitute(rss_name, '\', '/', 'g')
|
|
|
|
call map(html_lines, 'substitute(v:val, "%rss%", "'. rss_name .'", "g")')
|
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
let enc = &fileencoding
|
|
|
|
if enc ==? ''
|
|
|
|
let enc = &encoding
|
|
|
|
endif
|
|
|
|
call map(html_lines, 'substitute(v:val, "%encoding%", "'. enc .'", "g")')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
let html_lines = s:html_insert_contents(html_lines, converted['html']) " %contents%
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
return html_lines
|
|
|
|
endfunction
|
2015-12-07 12:29:25 +01:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
function! s:convert_file(path_html, wikifile) abort
|
|
|
|
let done = 0
|
|
|
|
let wikifile = fnamemodify(a:wikifile, ':p')
|
|
|
|
let path_html = expand(a:path_html).vimwiki#vars#get_bufferlocal('subdir')
|
|
|
|
|
|
|
|
if s:use_custom_wiki2html()
|
|
|
|
let force = 1
|
|
|
|
call vimwiki#html#CustomWiki2HTML(path_html, wikifile, force)
|
2012-06-07 02:00:00 +02:00
|
|
|
let done = 1
|
2020-07-24 06:14:28 +02:00
|
|
|
return ''
|
2020-07-05 17:53:56 +02:00
|
|
|
endif
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2020-07-05 17:53:56 +02:00
|
|
|
if s:syntax_supported() && done == 0
|
|
|
|
let htmlfile = fnamemodify(wikifile, ':t:r').'.html'
|
|
|
|
let html_lines = s:convert_file_to_lines_template(wikifile, path_html . htmlfile)
|
|
|
|
if html_lines == []
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
call vimwiki#path#mkdir(path_html)
|
|
|
|
call writefile(html_lines, path_html.htmlfile)
|
2020-07-24 06:14:28 +02:00
|
|
|
return path_html.htmlfile
|
2010-05-12 02:00:00 +02:00
|
|
|
endif
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2020-07-24 06:14:28 +02:00
|
|
|
echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax'
|
|
|
|
return ''
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! vimwiki#html#Wiki2HTML(path_html, wikifile) abort
|
2016-03-19 22:01:25 +01:00
|
|
|
let result = s:convert_file(a:path_html, a:wikifile)
|
2019-12-21 04:41:03 +01:00
|
|
|
if result !=? ''
|
2016-03-19 22:01:25 +01:00
|
|
|
call s:create_default_CSS(a:path_html)
|
|
|
|
endif
|
|
|
|
return result
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2011-06-11 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! vimwiki#html#WikiAll2HTML(path_html, force) abort
|
2012-06-07 02:00:00 +02:00
|
|
|
if !s:syntax_supported() && !s:use_custom_wiki2html()
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax'
|
2010-01-20 01:00:00 +01:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki: Saving Vimwiki files ...'
|
2010-08-24 02:00:00 +02:00
|
|
|
let save_eventignore = &eventignore
|
2019-12-21 04:41:03 +01:00
|
|
|
let &eventignore = 'all'
|
2018-10-26 16:35:02 +02:00
|
|
|
try
|
|
|
|
wall
|
|
|
|
catch
|
|
|
|
" just ignore errors
|
|
|
|
endtry
|
2010-08-24 02:00:00 +02:00
|
|
|
let &eventignore = save_eventignore
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
let path_html = expand(a:path_html)
|
2014-12-04 21:12:04 +01:00
|
|
|
call vimwiki#path#mkdir(path_html)
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2019-03-30 02:34:31 +01:00
|
|
|
if !vimwiki#vars#get_wikilocal('html_filename_parameterization')
|
|
|
|
echomsg 'Vimwiki: Deleting non-wiki html files ...'
|
|
|
|
call s:delete_html_files(path_html)
|
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki: Converting wiki to html files ...'
|
2010-01-20 01:00:00 +01:00
|
|
|
let setting_more = &more
|
|
|
|
setlocal nomore
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
" temporarily adjust current_subdir global state variable
|
2017-01-07 21:51:15 +01:00
|
|
|
let current_subdir = vimwiki#vars#get_bufferlocal('subdir')
|
|
|
|
let current_invsubdir = vimwiki#vars#get_bufferlocal('invsubdir')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
let wikifiles = split(glob(vimwiki#vars#get_wikilocal('path').'**/*'.
|
|
|
|
\ vimwiki#vars#get_wikilocal('ext')), '\n')
|
2010-01-20 01:00:00 +01:00
|
|
|
for wikifile in wikifiles
|
2019-12-21 04:41:03 +01:00
|
|
|
let wikifile = fnamemodify(wikifile, ':p')
|
2012-06-07 02:00:00 +02:00
|
|
|
|
|
|
|
" temporarily adjust 'subdir' and 'invsubdir' state variables
|
2016-12-22 19:55:20 +01:00
|
|
|
let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), wikifile)
|
2017-01-07 21:51:15 +01:00
|
|
|
call vimwiki#vars#set_bufferlocal('subdir', subdir)
|
|
|
|
call vimwiki#vars#set_bufferlocal('invsubdir', vimwiki#base#invsubdir(subdir))
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-05-20 16:22:15 +02:00
|
|
|
if a:force || !s:is_html_uptodate(wikifile)
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki: Processing '.wikifile
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2016-03-19 22:01:25 +01:00
|
|
|
call s:convert_file(path_html, wikifile)
|
2011-06-11 02:00:00 +02:00
|
|
|
else
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki: Skipping '.wikifile
|
2011-06-11 02:00:00 +02:00
|
|
|
endif
|
2010-01-20 01:00:00 +01:00
|
|
|
endfor
|
2012-06-07 02:00:00 +02:00
|
|
|
" reset 'subdir' state variable
|
2017-01-07 21:51:15 +01:00
|
|
|
call vimwiki#vars#set_bufferlocal('subdir', current_subdir)
|
|
|
|
call vimwiki#vars#set_bufferlocal('invsubdir', current_invsubdir)
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2016-03-19 22:01:25 +01:00
|
|
|
let created = s:create_default_CSS(path_html)
|
|
|
|
if created
|
|
|
|
echomsg 'Vimwiki: Default style.css has been created'
|
|
|
|
endif
|
2016-03-19 21:29:42 +01:00
|
|
|
echomsg 'Vimwiki: HTML exported to '.path_html
|
|
|
|
echomsg 'Vimwiki: Done!'
|
2010-01-20 01:00:00 +01:00
|
|
|
|
|
|
|
let &more = setting_more
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:file_exists(fname) abort
|
2013-04-19 05:46:58 +02:00
|
|
|
return !empty(getftype(expand(a:fname)))
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2018-04-20 07:03:53 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:binary_exists(fname) abort
|
2014-10-14 04:39:46 +02:00
|
|
|
return executable(expand(a:fname))
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2014-10-14 04:39:46 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! s:get_wikifile_url(wikifile) abort
|
2016-12-22 19:55:20 +01:00
|
|
|
return vimwiki#vars#get_wikilocal('path_html') .
|
|
|
|
\ vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), a:wikifile).
|
2019-12-21 04:41:03 +01:00
|
|
|
\ fnamemodify(a:wikifile, ':t:r').'.html'
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! vimwiki#html#PasteUrl(wikifile) abort
|
2015-02-03 13:53:56 +01:00
|
|
|
execute 'r !echo file://'.s:get_wikifile_url(a:wikifile)
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
|
|
|
|
2012-06-07 02:00:00 +02:00
|
|
|
|
2019-12-21 04:41:03 +01:00
|
|
|
function! vimwiki#html#CatUrl(wikifile) abort
|
2015-02-03 13:53:56 +01:00
|
|
|
execute '!echo file://'.s:get_wikifile_url(a:wikifile)
|
2018-04-20 07:03:53 +02:00
|
|
|
endfunction
|
2020-07-05 17:54:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
function! s:rss_header() abort
|
|
|
|
let title = vimwiki#vars#get_wikilocal('diary_header')
|
|
|
|
let rss_url = vimwiki#vars#get_wikilocal('base_url') . vimwiki#vars#get_wikilocal('rss_name')
|
|
|
|
let link = vimwiki#vars#get_wikilocal('base_url')
|
|
|
|
\ . vimwiki#vars#get_wikilocal('diary_rel_path')
|
|
|
|
\ . vimwiki#vars#get_wikilocal('diary_index') . '.html'
|
|
|
|
let description = title
|
|
|
|
let pubdate = strftime('%a, %d %b %Y %T %z')
|
|
|
|
let header = [
|
|
|
|
\ '<?xml version="1.0" encoding="UTF-8" ?>',
|
|
|
|
\ '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">',
|
|
|
|
\ '<channel>',
|
|
|
|
\ ' <title>' . title . '</title>',
|
|
|
|
\ ' <link>' . link . '</link>',
|
|
|
|
\ ' <description>' . description . '</description>',
|
|
|
|
\ ' <pubDate>' . pubdate . '</pubDate>',
|
|
|
|
\ ' <atom:link href="' . rss_url . '" rel="self" type="application/rss+xml" />'
|
|
|
|
\ ]
|
|
|
|
return header
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:rss_footer() abort
|
|
|
|
let footer = ['</channel>', '</rss>']
|
|
|
|
return footer
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:rss_item(path, title) abort
|
|
|
|
let diary_rel_path = vimwiki#vars#get_wikilocal('diary_rel_path')
|
|
|
|
let full_path = vimwiki#vars#get_wikilocal('path')
|
|
|
|
\ . diary_rel_path . a:path . vimwiki#vars#get_wikilocal('ext')
|
|
|
|
let fname_base = fnamemodify(a:path, ':t:r')
|
|
|
|
let htmlfile = fname_base . '.html'
|
|
|
|
|
|
|
|
let converted = s:convert_file_to_lines(full_path, htmlfile)
|
|
|
|
if converted['nohtml'] == 1
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
|
|
|
|
let link = vimwiki#vars#get_wikilocal('base_url')
|
|
|
|
\ . diary_rel_path
|
|
|
|
\ . fname_base . '.html'
|
|
|
|
let pubdate = strftime('%a, %d %b %Y %T %z', getftime(full_path))
|
|
|
|
|
|
|
|
let item_pre = [' <item>',
|
|
|
|
\ ' <title>' . a:title . '</title>',
|
|
|
|
\ ' <link>' . link . '</link>',
|
|
|
|
\ ' <guid isPermaLink="false">' . fname_base . '</guid>',
|
|
|
|
\ ' <description><![CDATA[']
|
|
|
|
let item_post = [']]></description>',
|
|
|
|
\ ' <pubDate>' . pubdate . '</pubDate>',
|
|
|
|
\ ' </item>'
|
|
|
|
\]
|
|
|
|
return item_pre + converted['html'] + item_post
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:generate_rss(path) abort
|
|
|
|
let rss_path = a:path . vimwiki#vars#get_wikilocal('rss_name')
|
|
|
|
let max_items = vimwiki#vars#get_wikilocal('rss_max_items')
|
|
|
|
|
|
|
|
let rss_lines = []
|
|
|
|
call extend(rss_lines, s:rss_header())
|
|
|
|
|
|
|
|
let captions = vimwiki#diary#diary_file_captions()
|
|
|
|
let i = 0
|
|
|
|
for diary in vimwiki#diary#diary_sort(keys(captions))
|
|
|
|
if i >= max_items
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
let title = captions[diary]['top']
|
|
|
|
if title ==? ''
|
|
|
|
let title = diary
|
|
|
|
endif
|
|
|
|
call extend(rss_lines, s:rss_item(diary, title))
|
|
|
|
let i += 1
|
|
|
|
endfor
|
|
|
|
|
|
|
|
call extend(rss_lines, s:rss_footer())
|
|
|
|
call writefile(rss_lines, rss_path)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! vimwiki#html#diary_rss() abort
|
|
|
|
echomsg 'Vimwiki: Saving RSS feed ...'
|
|
|
|
let path_html = expand(vimwiki#vars#get_wikilocal('path_html'))
|
|
|
|
call vimwiki#path#mkdir(path_html)
|
|
|
|
call s:generate_rss(path_html)
|
|
|
|
endfunction
|