" Vimwiki autoload plugin file " Export to HTML " Author: Maxim Kim " Home: http://code.google.com/p/vimwiki/ " Load only once {{{ if exists("g:loaded_vimwiki_html_auto") || &cp finish endif let g:loaded_vimwiki_html_auto = 1 "}}} " SCRIPT VARS "{{{ " Warn if html header or html footer do not exist only once. let s:warn_html_header = 0 let s:warn_html_footer = 0 "}}} " UTILITY "{{{ function! s:root_path(subdir) "{{{ return repeat('../', len(split(a:subdir, '[/\\]'))) endfunction "}}} function! s:syntax_supported() " {{{ return VimwikiGet('syntax') == "default" endfunction " }}} function! s:remove_blank_lines(lines) " {{{ while a:lines[-1] =~ '^\s*$' call remove(a:lines, -1) endwhile endfunction "}}} function! s:is_web_link(lnk) "{{{ if a:lnk =~ '^\%(https://\|http://\|www.\|ftp://\)' return 1 endif return 0 endfunction "}}} function! s:is_img_link(lnk) "{{{ if a:lnk =~ '\.\%(png\|jpg\|gif\|jpeg\)$' return 1 endif return 0 endfunction "}}} function! s:is_non_wiki_link(lnk) "{{{ " TODO: Add more file extensions here if a:lnk =~ '.\+\.\%(pdf\|txt\|doc\|rtf\|xls\)$' return 1 endif return 0 endfunction "}}} function! s:has_abs_path(fname) "{{{ if a:fname =~ '\(^.:\)\|\(^/\)' return 1 endif return 0 endfunction "}}} function! s:create_default_CSS(path) " {{{ let path = expand(a:path) let css_full_name = path.VimwikiGet('css_name') if glob(css_full_name) == "" call vimwiki#mkdir(fnamemodify(css_full_name, ':p:h')) let lines = [] call add(lines, 'body {font-family: Arial, sans-serif; margin: 1em 2em 1em 2em; font-size: 100%; line-height: 130%;}') call add(lines, 'h1, h2, h3, h4, h5, h6 {font-family: Trebuchet MS, serif; margin-top: 1.5em; margin-bottom: 0.5em;}') call add(lines, 'h1 {font-size: 2.0em; color: #a77070;}') call add(lines, 'h2 {font-size: 1.6em; color: #779977;}') call add(lines, 'h3 {font-size: 1.3em; color: #555577;}') call add(lines, 'h4 {font-size: 1.2em; color: #222244;}') call add(lines, 'h5 {font-size: 1.1em; color: #222244;}') call add(lines, 'h6 {font-size: 1.0em; color: #222244;}') call add(lines, 'p, pre, blockquote, table, ul, ol, dl {margin-top: 1em; margin-bottom: 1em;}') call add(lines, 'ul ul, ul ol, ol ol, ol ul {margin-top: 0.5em; margin-bottom: 0.5em;}') call add(lines, 'li {margin: 0.3em auto;}') call add(lines, 'ul {margin-left: 2em; padding-left: 0.5em;}') call add(lines, 'dt {font-weight: bold;}') call add(lines, 'img {border: none;}') call add(lines, 'pre {border-left: 1px solid #ccc; margin-left: 2em; padding-left: 0.5em;}') call add(lines, 'blockquote {padding: 0.4em; background-color: #f6f5eb;}') call add(lines, 'td {border: 1px solid #ccc; padding: 0.3em;}') call add(lines, 'hr {border: none; border-top: 1px solid #ccc; width: 100%;}') call add(lines, 'del {text-decoration: line-through; color: #777777;}') call add(lines, '.toc li {list-style-type: none;}') call add(lines, '.todo {font-weight: bold; background-color: #f0ece8; color: #a03020;}') call add(lines, '.justleft {text-align: left;}') call add(lines, '.justright {text-align: right;}') call add(lines, '.justcenter {text-align: center;}') call writefile(lines, css_full_name) echomsg "Default style.css is created." endif endfunction "}}} function! s:get_html_header(wikifile, subdir, charset) "{{{ let lines=[] let title = fnamemodify(a:wikifile, ":t:r") if VimwikiGet('html_header') != "" && !s:warn_html_header try let lines = readfile(expand(VimwikiGet('html_header'))) call map(lines, 'substitute(v:val, "%title%", "'. title .'", "g")') call map(lines, 'substitute(v:val, "%root_path%", "'. \ s:root_path(a:subdir) .'", "g")') return lines catch /E484/ let s:warn_html_header = 1 echomsg 'vimwiki: Header template '.VimwikiGet('html_header'). \ ' does not exist!' endtry endif let css_name = expand(VimwikiGet('css_name')) let css_name = substitute(css_name, '\', '/', 'g') if !s:has_abs_path(css_name) " Relative css file for deep links: [[dir1/dir2/dir3/filename]] let css_name = s:root_path(a:subdir).css_name endif " if no VimwikiGet('html_header') set up or error while reading template " file -- use default header. call add(lines, '') call add(lines, '') call add(lines, '') call add(lines, ''.title.'') call add(lines, '') call add(lines, '') call add(lines, '') return lines endfunction "}}} function! s:get_html_footer() "{{{ let lines=[] if VimwikiGet('html_footer') != "" && !s:warn_html_footer try let lines = readfile(expand(VimwikiGet('html_footer'))) return lines catch /E484/ let s:warn_html_footer = 1 echomsg 'vimwiki: Footer template '.VimwikiGet('html_footer'). \ ' does not exist!' endtry endif " if no VimwikiGet('html_footer') set up or error while reading template " file -- use default footer. call add(lines, "") call add(lines, '') call add(lines, '') return lines endfunction "}}} function! s:safe_html(line) "{{{ "" change dangerous html symbols: < > & let line = substitute(a:line, '&', '\&', 'g') let line = substitute(line, '<', '\<', 'g') let line = substitute(line, '>', '\>', 'g') return line endfunction "}}} function! s:delete_html_files(path) "{{{ let htmlfiles = split(glob(a:path.'**/*.html'), '\n') for fname in htmlfiles try call delete(fname) catch echomsg 'vimwiki: Cannot delete '.fname endtry endfor endfunction "}}} function! s:remove_comments(lines) "{{{ let res = [] let multiline_comment = 0 let idx = 0 while idx < len(a:lines) let line = a:lines[idx] let idx += 1 if multiline_comment let col = matchend(line, '-->',) if col != -1 let multiline_comment = 0 let line = strpart(line, col) else continue endif endif if !multiline_comment && line =~ '' let line = substitute(line, '', '', 'g') if line =~ '^\s*$' continue endif endif if !multiline_comment let col = match(line, '