Skip to content
Browse files

Version 0.9.8

* NEW: Rename g:vimwiki_fold_empty_lines to g:vimwiki_fold_trailing_empty_lines.
* NEW: One can use - along with * to start unordered list item.
* NEW: List items could be started from the first column.  As a result some
  limitations appeared:
    * a space after *, - or # for a list item is mandatory.
    * g:vimwiki_fold_trailing_empty_lines if set to 0 folds one trailing
      empty line.
* NEW: Folding is off by default. Use g:vimwiki_folding to enable it.
* NEW: Speed up vimwiki's folding a bit. Should lag a bit less in a long todo lists.
* NEW: Centered headers. Start header with at least one space to make it html centered.
* NEW: Change in default css: header's colors.
* NEW: Vimwiki is aware of GetLatestVimScripts now.
* FIX: Use <del> tag instead of custom <span class="strike"> in html.
* FIX: There are no text styling in htmlized quoted text.
* FIX: set default value of g:vimwiki_fold_lists to 0 as written in this help.
* FIX: Issue 33: Folded list items have wrong indentation when 'tabs' are used.
* FIX: Issue 34: vimwiki#subdir got wrong dir when VimwikiGet('path') is a
  symbolic link. Thanks lilydjwg for the patch.
* FIX: Issue 28: todo-list auto-indent enhancement. New item should always be unchecked.
* FIX: Issue 36: Change the name of the :Search command to :VimwikiSearch
  as it conflicts with MultipleSearch. Alias :VWS is also available.
* NEW: You can generate 'Table of contents' of your wiki page. See :h vimwiki-toc for details.
  • Loading branch information...
1 parent 66c3d9d commit 339377490424d21b20174f0b768e399b99308b25 @habamax habamax committed with Jan 20, 2010
Showing with 4,593 additions and 4,361 deletions.
  1. +676 −0 autoload/vimwiki.vim
  2. +1,099 −0 autoload/vimwiki_html.vim
  3. +361 −0 autoload/vimwiki_lst.vim
  4. +1,547 −0 doc/vimwiki.txt
  5. +299 −0 ftplugin/vimwiki.vim
  6. +336 −0 plugin/vimwiki.vim
  7. +141 −0 syntax/vimwiki.vim
  8. +76 −0 syntax/vimwiki_default.vim
  9. +58 −0 syntax/vimwiki_media.vim
  10. +0 −4,361 vimwiki_0_9_701.vba
View
676 autoload/vimwiki.vim
@@ -0,0 +1,676 @@
+" Vimwiki autoload plugin file
+" Author: Maxim Kim <habamax@gmail.com>
+" Home: http://code.google.com/p/vimwiki/
+
+if exists("g:loaded_vimwiki_auto") || &cp
+ finish
+endif
+let g:loaded_vimwiki_auto = 1
+
+if has("win32")
+ let s:os_sep = '\'
+else
+ let s:os_sep = '/'
+endif
+
+let s:badsymbols = '['.g:vimwiki_badsyms.g:vimwiki_stripsym.'<>|?*:"]'
+
+" MISC helper functions {{{
+
+" This function is double defined.
+" TODO: refactor common functions into new module.
+function! s:chomp_slash(str) "{{{
+ return substitute(a:str, '[/\\]\+$', '', '')
+endfunction "}}}
+
+function! vimwiki#mkdir(path) "{{{
+ let path = expand(a:path)
+ if !isdirectory(path) && exists("*mkdir")
+ let path = s:chomp_slash(path)
+ call mkdir(path, "p")
+ endif
+endfunction
+" }}}
+
+function! vimwiki#safe_link(string) "{{{
+ return substitute(a:string, s:badsymbols, g:vimwiki_stripsym, 'g')
+endfunction
+"}}}
+
+function! vimwiki#unsafe_link(string) "{{{
+ return substitute(a:string, g:vimwiki_stripsym, s:badsymbols, 'g')
+endfunction
+"}}}
+
+function! vimwiki#subdir(path, filename)"{{{
+ let path = expand(a:path)
+ let filename = expand(a:filename)
+ let idx = 0
+ while path[idx] == filename[idx]
+ let idx = idx + 1
+ endwhile
+
+ let p = split(strpart(filename, idx), '[/\\]')
+ let res = join(p[:-2], s:os_sep)
+ if len(res) > 0
+ let res = res.s:os_sep
+ endif
+ return res
+endfunction"}}}
+
+function! vimwiki#current_subdir()"{{{
+ return vimwiki#subdir(VimwikiGet('path'), expand('%:p'))
+endfunction"}}}
+
+function! s:filename(link) "{{{
+ let result = vimwiki#safe_link(a:link)
+ if a:link =~ '|'
+ let result = vimwiki#safe_link(split(a:link, '|')[0])
+ elseif a:link =~ ']['
+ let result = vimwiki#safe_link(split(a:link, '][')[0])
+ endif
+ return result
+endfunction
+" }}}
+
+function! s:is_wiki_word(str) "{{{
+ if a:str =~ g:vimwiki_word1 && a:str !~ '[[:space:]\\/]'
+ return 1
+ endif
+ return 0
+endfunction
+" }}}
+
+function! s:edit_file(command, filename) "{{{
+ let fname = escape(a:filename, '% ')
+ call vimwiki#mkdir(fnamemodify(a:filename, ":p:h"))
+ execute a:command.' '.fname
+endfunction
+" }}}
+
+function! s:search_word(wikiRx, cmd) "{{{
+ let match_line = search(a:wikiRx, 's'.a:cmd)
+ if match_line == 0
+ echomsg "vimwiki: Wiki link not found."
+ endif
+endfunction
+" }}}
+
+function! s:get_word_at_cursor(wikiRX) "{{{
+ let col = col('.') - 1
+ let line = getline('.')
+ let ebeg = -1
+ let cont = match(line, a:wikiRX, 0)
+ while (ebeg >= 0 || (0 <= cont) && (cont <= col))
+ let contn = matchend(line, a:wikiRX, cont)
+ if (cont <= col) && (col < contn)
+ let ebeg = match(line, a:wikiRX, cont)
+ let elen = contn - ebeg
+ break
+ else
+ let cont = match(line, a:wikiRX, contn)
+ endif
+ endwh
+ if ebeg >= 0
+ return strpart(line, ebeg, elen)
+ else
+ return ""
+ endif
+endf "}}}
+
+function! s:strip_word(word) "{{{
+ let result = a:word
+ if strpart(a:word, 0, 2) == "[["
+ " get rid of [[ and ]]
+ let w = strpart(a:word, 2, strlen(a:word)-4)
+
+ if w =~ '|'
+ " we want "link" from [[link|link desc]]
+ let w = split(w, "|")[0]
+ elseif w =~ ']['
+ " we want "link" from [[link][link desc]]
+ let w = split(w, "][")[0]
+ endif
+
+ let result = vimwiki#safe_link(w)
+ endif
+ return result
+endfunction
+" }}}
+
+function! s:is_link_to_non_wiki_file(word) "{{{
+ " Check if word is link to a non-wiki file.
+ " The easiest way is to check if it has extension like .txt or .html
+ if a:word =~ '\.\w\{1,4}$'
+ return 1
+ endif
+ return 0
+endfunction
+" }}}
+
+function! s:print_wiki_list() "{{{
+ let idx = 0
+ while idx < len(g:vimwiki_list)
+ if idx == g:vimwiki_current_idx
+ let sep = ' * '
+ echohl PmenuSel
+ else
+ let sep = ' '
+ echohl None
+ endif
+ echo (idx + 1).sep.VimwikiGet('path', idx)
+ let idx += 1
+ endwhile
+ echohl None
+endfunction
+" }}}
+
+function! s:wiki_select(wnum)"{{{
+ if a:wnum < 1 || a:wnum > len(g:vimwiki_list)
+ return
+ endif
+ let b:vimwiki_idx = g:vimwiki_current_idx
+ let g:vimwiki_current_idx = a:wnum - 1
+endfunction
+" }}}
+
+function! s:update_wiki_link(fname, old, new) " {{{
+ echo "Updating links in ".a:fname
+ let has_updates = 0
+ let dest = []
+ for line in readfile(a:fname)
+ if !has_updates && match(line, a:old) != -1
+ let has_updates = 1
+ endif
+ call add(dest, substitute(line, a:old, escape(a:new, "&"), "g"))
+ endfor
+ " add exception handling...
+ if has_updates
+ call rename(a:fname, a:fname.'#vimwiki_upd#')
+ call writefile(dest, a:fname)
+ call delete(a:fname.'#vimwiki_upd#')
+ endif
+endfunction
+" }}}
+
+function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
+ let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g')
+ let new_fname = a:new_fname
+
+ if !s:is_wiki_word(new_fname)
+ let new_fname = '[['.new_fname.']]'
+ endif
+ if !s:is_wiki_word(old_fname)
+ let old_fname = '\[\['.vimwiki#unsafe_link(old_fname).
+ \ '\%(|.*\)\?\%(\]\[.*\)\?\]\]'
+ else
+ let old_fname = '\<'.old_fname.'\>'
+ endif
+ let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n')
+ for fname in files
+ call s:update_wiki_link(fname, old_fname, new_fname)
+ endfor
+endfunction
+" }}}
+
+function! s:tail_name(fname) "{{{
+ let result = substitute(a:fname, ":", "__colon__", "g")
+ let result = fnamemodify(result, ":t:r")
+ let result = substitute(result, "__colon__", ":", "g")
+ return result
+endfunction "}}}
+
+function! s:update_wiki_links(old_fname, new_fname) " {{{
+ let old_fname = s:tail_name(a:old_fname)
+ let new_fname = s:tail_name(a:new_fname)
+
+ let subdirs = split(a:old_fname, '[/\\]')[: -2]
+
+ " TODO: Use Dictionary here...
+ let dirs_keys = ['']
+ let dirs_vals = ['']
+ if len(subdirs) > 0
+ let dirs_keys = ['']
+ let dirs_vals = [join(subdirs, '/').'/']
+ let idx = 0
+ while idx < len(subdirs) - 1
+ call add(dirs_keys, join(subdirs[: idx], '/').'/')
+ call add(dirs_vals, join(subdirs[idx+1 :], '/').'/')
+ let idx = idx + 1
+ endwhile
+ call add(dirs_keys,join(subdirs, '/').'/')
+ call add(dirs_vals, '')
+ endif
+
+ let idx = 0
+ while idx < len(dirs_keys)
+ let dir = dirs_keys[idx]
+ let new_dir = dirs_vals[idx]
+ call s:update_wiki_links_dir(dir,
+ \ new_dir.old_fname, new_dir.new_fname)
+ let idx = idx + 1
+ endwhile
+endfunction
+" }}}
+
+function! s:get_wiki_buffers() "{{{
+ let blist = []
+ let bcount = 1
+ while bcount<=bufnr("$")
+ if bufexists(bcount)
+ let bname = fnamemodify(bufname(bcount), ":p")
+ if bname =~ VimwikiGet('ext')."$"
+ let bitem = [bname, getbufvar(bname, "vimwiki_prev_word")]
+ call add(blist, bitem)
+ endif
+ endif
+ let bcount = bcount + 1
+ endwhile
+ return blist
+endfunction
+" }}}
+
+function! s:open_wiki_buffer(item) "{{{
+ call s:edit_file('e', a:item[0])
+ if !empty(a:item[1])
+ call setbufvar(a:item[0], "vimwiki_prev_word", a:item[1])
+ endif
+endfunction
+" }}}
+
+" }}}
+
+" SYNTAX highlight {{{
+function! vimwiki#WikiHighlightWords() "{{{
+ " search all wiki files in 'path' and its subdirs.
+ let subdir = vimwiki#current_subdir()
+ let wikies = glob(VimwikiGet('path').subdir.'**/*'.VimwikiGet('ext'))
+
+ " remove .wiki extensions
+ let wikies = substitute(wikies, '\'.VimwikiGet('ext'), "", "g")
+ let g:vimwiki_wikiwords = split(wikies, '\n')
+
+ " remove backup files (.wiki~)
+ call filter(g:vimwiki_wikiwords, 'v:val !~ ''.*\~$''')
+
+ " remove paths
+ let rem_path = escape(expand(VimwikiGet('path')).subdir, '\')
+ call map(g:vimwiki_wikiwords, 'substitute(v:val, rem_path, "", "g")')
+
+ " Links with subdirs should be highlighted for linux and windows separators
+ " Change \ or / to [/\\]
+ let os_p = '[/\\]'
+ let os_p2 = escape(os_p, '\')
+ call map(g:vimwiki_wikiwords, 'substitute(v:val, os_p, os_p2, "g")')
+
+ for word in g:vimwiki_wikiwords
+ if g:vimwiki_camel_case &&
+ \ word =~ g:vimwiki_word1 && !s:is_link_to_non_wiki_file(word)
+ execute 'syntax match VimwikiWord /\%(^\|[^!]\)\@<=\<'.word.'\>/'
+ endif
+ execute 'syntax match VimwikiWord /\[\[\<'.
+ \ vimwiki#unsafe_link(word).
+ \ '\>\%(|\+.*\)*\]\]/'
+ execute 'syntax match VimwikiWord /\[\[\<'.
+ \ vimwiki#unsafe_link(word).
+ \ '\>\]\[.\+\]\]/'
+ endfor
+ execute 'syntax match VimwikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/'
+ execute 'syntax match VimwikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/'
+endfunction
+" }}}
+
+function! vimwiki#hl_exists(hl)"{{{
+ if !hlexists(a:hl)
+ return 0
+ endif
+ redir => hlstatus
+ exe "silent hi" a:hl
+ redir END
+ return (hlstatus !~ "cleared")
+endfunction
+"}}}
+
+function! vimwiki#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
+" From http://vim.wikia.com/wiki/VimTip857
+ let ft=toupper(a:filetype)
+ let group='textGroup'.ft
+ if exists('b:current_syntax')
+ let s:current_syntax=b:current_syntax
+ " Remove current syntax definition, as some syntax files (e.g. cpp.vim)
+ " do nothing if b:current_syntax is defined.
+ unlet b:current_syntax
+ endif
+
+ " Some syntax files set up iskeyword which might scratch vimwiki a bit.
+ " Let us save and restore it later.
+ " let b:skip_set_iskeyword = 1
+ let is_keyword = &iskeyword
+
+ execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
+ try
+ execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
+ catch
+ endtry
+
+ let &iskeyword = is_keyword
+
+ if exists('s:current_syntax')
+ let b:current_syntax=s:current_syntax
+ else
+ unlet b:current_syntax
+ endif
+ execute 'syntax region textSnip'.ft.'
+ \ matchgroup='.a:textSnipHl.'
+ \ start="'.a:start.'" end="'.a:end.'"
+ \ contains=@'.group
+endfunction "}}}
+
+"}}}
+
+" WIKI functions {{{
+function! vimwiki#WikiNextWord() "{{{
+ call s:search_word(g:vimwiki_rxWikiWord.'\|'.g:vimwiki_rxWeblink, '')
+endfunction
+" }}}
+
+function! vimwiki#WikiPrevWord() "{{{
+ call s:search_word(g:vimwiki_rxWikiWord.'\|'.g:vimwiki_rxWeblink, 'b')
+endfunction
+" }}}
+
+function! vimwiki#WikiFollowWord(split) "{{{
+ if a:split == "split"
+ let cmd = ":split "
+ elseif a:split == "vsplit"
+ let cmd = ":vsplit "
+ else
+ let cmd = ":e "
+ endif
+
+ let word = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWikiWord))
+ if word == ""
+ let weblink = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWeblink))
+ if weblink != ""
+ call VimwikiWeblinkHandler(weblink)
+ else
+ execute "normal! \n"
+ endif
+ return
+ endif
+
+ if s:is_link_to_non_wiki_file(word)
+ call s:edit_file(cmd, word)
+ else
+ let vimwiki_prev_word = [expand('%:p'), getpos('.')]
+ let subdir = vimwiki#current_subdir()
+ call s:edit_file(cmd, VimwikiGet('path').subdir.word.VimwikiGet('ext'))
+ let b:vimwiki_prev_word = vimwiki_prev_word
+ endif
+endfunction
+" }}}
+
+function! vimwiki#WikiGoBackWord() "{{{
+ if exists("b:vimwiki_prev_word")
+ " go back to saved WikiWord
+ let prev_word = b:vimwiki_prev_word
+ execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g')
+ call setpos('.', prev_word[1])
+ endif
+endfunction
+" }}}
+
+function! vimwiki#WikiGoHome(index) "{{{
+ call s:wiki_select(a:index)
+ call vimwiki#mkdir(VimwikiGet('path'))
+
+ try
+ execute ':e '.fnameescape(
+ \ VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext'))
+ catch /E37/ " catch 'No write since last change' error
+ " this is really unsecure!!!
+ execute ':'.VimwikiGet('gohome').' '.
+ \ VimwikiGet('path').
+ \ VimwikiGet('index').
+ \ VimwikiGet('ext')
+ catch /E325/ " catch 'ATTENTION' error (:h E325)
+ endtry
+endfunction
+"}}}
+
+function! vimwiki#WikiDeleteWord() "{{{
+ "" file system funcs
+ "" Delete WikiWord you are in from filesystem
+ let val = input('Delete ['.expand('%').'] (y/n)? ', "")
+ if val != 'y'
+ return
+ endif
+ let fname = expand('%:p')
+ try
+ call delete(fname)
+ catch /.*/
+ echomsg 'vimwiki: Cannot delete "'.expand('%:t:r').'"!'
+ return
+ endtry
+ execute "bdelete! ".escape(fname, " ")
+
+ " reread buffer => deleted WikiWord should appear as non-existent
+ if expand('%:p') != ""
+ execute "e"
+ endif
+endfunction
+"}}}
+
+function! vimwiki#WikiRenameWord() "{{{
+ "" Rename WikiWord, update all links to renamed WikiWord
+ let subdir = vimwiki#current_subdir()
+ let old_fname = subdir.expand('%:t')
+
+ " there is no file (new one maybe)
+ if glob(expand('%:p')) == ''
+ echomsg 'vimwiki: Cannot rename "'.expand('%:p').
+ \'". It does not exist! (New file? Save it before renaming.)'
+ return
+ endif
+
+ let val = input('Rename "'.expand('%:t:r').'" (y/n)? ', "")
+ if val!='y'
+ return
+ endif
+
+ let new_link = input('Enter new name: ', "")
+
+ if new_link =~ '[/\\]'
+ " It is actually doable but I do not have free time to do it.
+ echomsg 'vimwiki: Cannot rename to a filename with path!'
+ return
+ endif
+
+ let new_link = subdir.new_link
+
+ " check new_fname - it should be 'good', not empty
+ if substitute(new_link, '\s', '', 'g') == ''
+ echomsg 'vimwiki: Cannot rename to an empty filename!'
+ return
+ endif
+ if s:is_link_to_non_wiki_file(new_link)
+ echomsg 'vimwiki: Cannot rename to a filename with extension (ie .txt .html)!'
+ return
+ endif
+
+ let new_link = s:strip_word(new_link)
+ let new_fname = VimwikiGet('path').s:filename(new_link).VimwikiGet('ext')
+
+ " do not rename if word with such name exists
+ let fname = glob(new_fname)
+ if fname != ''
+ echomsg 'vimwiki: Cannot rename to "'.new_fname.
+ \ '". File with that name exist!'
+ return
+ endif
+ " rename WikiWord file
+ try
+ echomsg "Renaming ".VimwikiGet('path').old_fname." to ".new_fname
+ let res = rename(expand('%:p'), expand(new_fname))
+ if res != 0
+ throw "Cannot rename!"
+ end
+ catch /.*/
+ echomsg 'vimwiki: Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"'
+ return
+ endtry
+
+ let &buftype="nofile"
+
+ let cur_buffer = [expand('%:p'),
+ \getbufvar(expand('%:p'), "vimwiki_prev_word")]
+
+ let blist = s:get_wiki_buffers()
+
+ " save wiki buffers
+ for bitem in blist
+ execute ':b '.escape(bitem[0], ' ')
+ execute ':update'
+ endfor
+
+ execute ':b '.escape(cur_buffer[0], ' ')
+
+ " remove wiki buffers
+ for bitem in blist
+ execute 'bwipeout '.escape(bitem[0], ' ')
+ endfor
+
+ let setting_more = &more
+ setlocal nomore
+
+ " update links
+ call s:update_wiki_links(old_fname, new_link)
+
+ " restore wiki buffers
+ for bitem in blist
+ if bitem[0] != cur_buffer[0]
+ call s:open_wiki_buffer(bitem)
+ endif
+ endfor
+
+ call s:open_wiki_buffer([new_fname,
+ \ cur_buffer[1]])
+ " execute 'bwipeout '.escape(cur_buffer[0], ' ')
+
+ echomsg old_fname." is renamed to ".new_fname
+
+ let &more = setting_more
+endfunction
+" }}}
+
+function! vimwiki#WikiUISelect()"{{{
+ call s:print_wiki_list()
+ let idx = input("Select Wiki (specify number): ")
+ if idx == ""
+ return
+ endif
+ call vimwiki#WikiGoHome(idx)
+endfunction
+"}}}
+
+" }}}
+
+" TEXT OBJECTS functions {{{
+
+function! vimwiki#TO_header(inner, visual) "{{{
+ if !search('^\(=\+\)[^=]\+\1\s*$', 'bcW')
+ return
+ endif
+
+ let sel_start = line("'<")
+ let sel_end = line("'>")
+ let block_start = line(".")
+ let advance = 0
+
+ let level = vimwiki#count_first_sym(getline('.'))
+
+ let is_header_selected = sel_start == block_start
+ \ && sel_start != sel_end
+
+ if a:visual && is_header_selected
+ if level > 1
+ let level -= 1
+ call search('^\(=\{'.level.'\}\)[^=]\+\1\s*$', 'bcW')
+ else
+ let advance = 1
+ endif
+ endif
+
+ normal! V
+
+ if a:visual && is_header_selected
+ call cursor(sel_end + advance, 0)
+ endif
+
+ if search('^\(=\{1,'.level.'}\)[^=]\+\1\s*$', 'W')
+ call cursor(line('.') - 1, 0)
+ else
+ call cursor(line('$'), 0)
+ endif
+
+ if a:inner && getline(line('.')) =~ '^\s*$'
+ let lnum = prevnonblank(line('.') - 1)
+ call cursor(lnum, 0)
+ endif
+endfunction
+"}}}
+
+function! vimwiki#count_first_sym(line) "{{{
+ let first_sym = matchstr(a:line, '\S')
+ return len(matchstr(a:line, first_sym.'\+'))
+endfunction "}}}
+
+function! vimwiki#AddHeaderLevel() "{{{
+ let lnum = line('.')
+ let line = getline(lnum)
+
+ if line =~ '^\s*$'
+ return
+ endif
+
+ if line =~ '^\s*\(=\+\).\+\1\s*$'
+ let level = vimwiki#count_first_sym(line)
+ if level < 6
+ let line = substitute(line, '\(=\+\).\+\1', '=&=', '')
+ call setline(lnum, line)
+ endif
+ else
+ let line = substitute(line, '^\s*', '&= ', '')
+ let line = substitute(line, '\s*$', ' =&', '')
+ call setline(lnum, line)
+ endif
+endfunction
+"}}}
+
+function! vimwiki#RemoveHeaderLevel() "{{{
+ let lnum = line('.')
+ let line = getline(lnum)
+
+ if line =~ '^\s*$'
+ return
+ endif
+
+ if line =~ '^\s*\(=\+\).\+\1\s*$'
+ let level = vimwiki#count_first_sym(line)
+ let old = repeat('=', level)
+ let new = repeat('=', level - 1)
+
+ let chomp = line =~ '=\s'
+
+ let line = substitute(line, old, new, 'g')
+
+ if level == 1 && chomp
+ let line = substitute(line, '^\s', '', 'g')
+ let line = substitute(line, '\s$', '', 'g')
+ endif
+ call setline(lnum, line)
+ endif
+endfunction
+" }}}
+
+" }}}
View
1,099 autoload/vimwiki_html.vim
@@ -0,0 +1,1099 @@
+" Vimwiki autoload plugin file
+" Export to HTML
+" Author: Maxim Kim <habamax@gmail.com>
+" 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, '<html>')
+ call add(lines, '<head>')
+ call add(lines, '<link rel="Stylesheet" type="text/css" href="'.
+ \ css_name.'" />')
+ call add(lines, '<title>'.title.'</title>')
+ call add(lines, '<meta http-equiv="Content-Type" content="text/html;'.
+ \ ' charset='.a:charset.'" />')
+ call add(lines, '</head>')
+ call add(lines, '<body>')
+
+ 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, '</body>')
+ call add(lines, '</html>')
+
+ return lines
+endfunction "}}}
+
+function! s:safe_html(line) "{{{
+ "" change dangerous html symbols: < > &
+
+ let line = substitute(a:line, '&', '\&amp;', 'g')
+ let line = substitute(line, '<', '\&lt;', 'g')
+ let line = substitute(line, '>', '\&gt;', '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, '<!--',)
+ if col != -1
+ let multiline_comment = 1
+ let line = strpart(line, 1, col - 1)
+ endif
+ endif
+
+ call add(res, line)
+ endwhile
+ return res
+endfunction "}}}
+
+function! s:mid(value, cnt) "{{{
+ return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt)
+endfunction "}}}
+
+function! s:subst_func(line, regexp, func) " {{{
+ " Substitute text found by regexp with result of
+ " func(matched) function.
+
+ let pos = 0
+ let lines = split(a:line, a:regexp, 1)
+ let res_line = ""
+ for line in lines
+ let res_line = res_line.line
+ let matched = matchstr(a:line, a:regexp, pos)
+ if matched != ""
+ let res_line = res_line.{a:func}(matched)
+ endif
+ let pos = matchend(a:line, a:regexp, pos)
+ endfor
+ return res_line
+endfunction " }}}
+
+function! s:save_vimwiki_buffer() "{{{
+ if &filetype == 'vimwiki'
+ silent update
+ endif
+endfunction "}}}
+
+function! s:trim(string) "{{{
+ let res = substitute(a:string, '^\s\+', '', '')
+ let res = substitute(res, '\s\+$', '', '')
+ return res
+endfunction "}}}
+
+" toc_list is list of [level, header_text, header_id]
+" ex: [[1, "Header", "toc1"], [2, "Header2", "toc2"], ...]
+function! s:get_html_toc(toc_list) "{{{
+ if empty(a:toc_list)
+ return []
+ endif
+
+ let toc = ['<div class="toc">']
+ let level = 0
+ let plevel = 0
+ for [level, text, id] in a:toc_list
+ if level > plevel
+ call add(toc, '<ul>')
+ elseif level < plevel
+ call add(toc, '</ul>')
+ endif
+ call add(toc, '<li><a href="#'.id.'">'.text.'</a></li>')
+ let plevel = level
+ endfor
+ while level > 0
+ call add(toc, '</ul>')
+ let level -= 1
+ endwhile
+ call add(toc, '</div>')
+ return toc
+endfunction "}}}
+
+" insert placeholder's contents into dest.
+function! s:process_placeholders(dest, placeholders, type, ins_content) "{{{
+ if !empty(a:placeholders)
+ for [placeholder, row, idx] in a:placeholders
+ let [type, param] = placeholder
+ if type == a:type
+ let ins_content = a:ins_content[:]
+ if !empty(param)
+ call insert(ins_content, '<h1>'.param.'</h1>')
+ endif
+ let shift = idx * len(ins_content)
+ call extend(a:dest, ins_content, row + shift)
+ endif
+ endfor
+ endif
+endfunction "}}}
+
+"}}}
+
+" INLINE TAGS "{{{
+function! s:tag_em(value) "{{{
+ return '<em>'.s:mid(a:value, 1).'</em>'
+endfunction "}}}
+
+function! s:tag_strong(value) "{{{
+ return '<strong>'.s:mid(a:value, 1).'</strong>'
+endfunction "}}}
+
+function! s:tag_todo(value) "{{{
+ return '<span class="todo">'.a:value.'</span>'
+endfunction "}}}
+
+function! s:tag_strike(value) "{{{
+ return '<del>'.s:mid(a:value, 2).'</del>'
+endfunction "}}}
+
+function! s:tag_super(value) "{{{
+ return '<sup><small>'.s:mid(a:value, 1).'</small></sup>'
+endfunction "}}}
+
+function! s:tag_sub(value) "{{{
+ return '<sub><small>'.s:mid(a:value, 2).'</small></sub>'
+endfunction "}}}
+
+function! s:tag_code(value) "{{{
+ return '<code>'.s:mid(a:value, 1).'</code>'
+endfunction "}}}
+
+function! s:tag_pre(value) "{{{
+ return '<code>'.s:mid(a:value, 3).'</code>'
+endfunction "}}}
+
+function! s:tag_external_link(value) "{{{
+ "" Make <a href="link">link desc</a>
+ "" from [link link desc]
+
+ let value = s:mid(a:value, 1)
+
+ let line = ''
+ if s:is_web_link(value)
+ let lnkElements = split(value)
+ let head = lnkElements[0]
+ let rest = join(lnkElements[1:])
+ if rest==""
+ let rest=head
+ endif
+ if s:is_img_link(rest)
+ if rest!=head
+ let line = '<a href="'.head.'"><img src="'.rest.'" /></a>'
+ else
+ let line = '<img src="'.rest.'" />'
+ endif
+ else
+ let line = '<a href="'.head.'">'.rest.'</a>'
+ endif
+ elseif s:is_img_link(value)
+ let line = '<img src="'.value.'" />'
+ else
+ " [alskfj sfsf] shouldn't be a link. So return it as it was --
+ " enclosed in [...]
+ let line = '['.value.']'
+ endif
+ return line
+endfunction "}}}
+
+function! s:tag_internal_link(value) "{{{
+ " Make <a href="This is a link">This is a link</a>
+ " from [[This is a link]]
+ " Make <a href="link">This is a link</a>
+ " from [[link|This is a link]]
+ " Make <a href="link">This is a link</a>
+ " from [[link][This is a link]]
+ " TODO: rename function -- it makes not only internal links.
+ " TODO: refactor it.
+
+ let value = s:mid(a:value, 2)
+
+ let line = ''
+ if value =~ '|'
+ let link_parts = split(value, "|", 1)
+ else
+ let link_parts = split(value, "][", 1)
+ endif
+
+ if len(link_parts) > 1
+ if len(link_parts) < 3
+ let style = ""
+ else
+ let style = link_parts[2]
+ endif
+
+ if s:is_img_link(link_parts[1])
+ let line = '<a href="'.link_parts[0].'"><img src="'.link_parts[1].
+ \ '" style="'.style.'" /></a>'
+ elseif len(link_parts) < 3
+ if s:is_non_wiki_link(link_parts[0])
+ let line = '<a href="'.link_parts[0].'">'.link_parts[1].'</a>'
+ else
+ let line = '<a href="'.vimwiki#safe_link(link_parts[0]).
+ \ '.html">'.link_parts[1].'</a>'
+ endif
+ elseif s:is_img_link(link_parts[0])
+ let line = '<img src="'.link_parts[0].'" alt="'.
+ \ link_parts[1].'" style="'.style.'" />'
+ endif
+ else
+ if s:is_img_link(value)
+ let line = '<img src="'.value.'" />'
+ elseif s:is_non_wiki_link(link_parts[0])
+ let line = '<a href="'.value.'">'.value.'</a>'
+ else
+ let line = '<a href="'.vimwiki#safe_link(value).
+ \ '.html">'.value.'</a>'
+ endif
+ endif
+ return line
+endfunction "}}}
+
+function! s:tag_wikiword_link(value) "{{{
+ " Make <a href="WikiWord">WikiWord</a> from WikiWord
+ " if first symbol is ! then remove it and make no link.
+ if a:value[0] == '!'
+ return a:value[1:]
+ else
+ let line = '<a href="'.a:value.'.html">'.a:value.'</a>'
+ return line
+ endif
+endfunction "}}}
+
+function! s:tag_barebone_link(value) "{{{
+ "" Make <a href="http://habamax.ru">http://habamax.ru</a>
+ "" from http://habamax.ru
+
+ if s:is_img_link(a:value)
+ let line = '<img src="'.a:value.'" />'
+ else
+ let line = '<a href="'.a:value.'">'.a:value.'</a>'
+ endif
+ return line
+endfunction "}}}
+
+function! s:make_tag(line, regexp, func) "{{{
+ " Make tags for a given matched regexp.
+ " Exclude preformatted text and href links.
+
+ let patt_splitter = '\(`[^`]\+`\)\|\({{{.\+}}}\)\|'.
+ \ '\(<a href.\{-}</a>\)\|\(<img src.\{-}/>\)'
+ if '`[^`]\+`' == a:regexp || '{{{.\+}}}' == a:regexp
+ 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)
+ let res_line = ""
+ for line in lines
+ let res_line = res_line.s:subst_func(line, a:regexp, a:func)
+ let res_line = res_line.matchstr(a:line, patt_splitter, pos)
+ let pos = matchend(a:line, patt_splitter, pos)
+ endfor
+ endif
+ return res_line
+endfunction "}}}
+
+function! s:process_inline_tags(line) "{{{
+ let line = a:line
+ let line = s:make_tag(line, '\[\[.\{-}\]\]', 's:tag_internal_link')
+ let line = s:make_tag(line, '\[.\{-}\]', 's:tag_external_link')
+ let line = s:make_tag(line, g:vimwiki_rxWeblink, 's:tag_barebone_link')
+ let line = s:make_tag(line, '!\?'.g:vimwiki_rxWikiWord,
+ \ 's:tag_wikiword_link')
+ let line = s:make_tag(line, g:vimwiki_rxItalic, 's:tag_em')
+ let line = s:make_tag(line, g:vimwiki_rxBold, 's:tag_strong')
+ let line = s:make_tag(line, g:vimwiki_rxTodo, 's:tag_todo')
+ let line = s:make_tag(line, g:vimwiki_rxDelText, 's:tag_strike')
+ let line = s:make_tag(line, g:vimwiki_rxSuperScript, 's:tag_super')
+ let line = s:make_tag(line, g:vimwiki_rxSubScript, 's:tag_sub')
+ let line = s:make_tag(line, g:vimwiki_rxCode, 's:tag_code')
+ let line = s:make_tag(line, g:vimwiki_rxPreStart.'.\+'.g:vimwiki_rxPreEnd,
+ \ 's:tag_pre')
+ return line
+endfunction " }}}
+"}}}
+
+" BLOCK TAGS {{{
+function! s:close_tag_pre(pre, ldest) "{{{
+ if a:pre
+ call insert(a:ldest, "</pre></code>")
+ return 0
+ endif
+ return a:pre
+endfunction "}}}
+
+function! s:close_tag_quote(quote, ldest) "{{{
+ if a:quote
+ call insert(a:ldest, "</blockquote>")
+ return 0
+ endif
+ return a:quote
+endfunction "}}}
+
+function! s:close_tag_para(para, ldest) "{{{
+ if a:para
+ call insert(a:ldest, "</p>")
+ return 0
+ endif
+ return a:para
+endfunction "}}}
+
+function! s:close_tag_table(table, ldest) "{{{
+ if a:table
+ call insert(a:ldest, "</table>")
+ return 0
+ endif
+ return a:table
+endfunction "}}}
+
+function! s:close_tag_list(lists, ldest) "{{{
+ while len(a:lists)
+ let item = remove(a:lists, -1)
+ call insert(a:ldest, item[0])
+ endwhile
+endfunction! "}}}
+
+function! s:close_tag_def_list(deflist, ldest) "{{{
+ if a:deflist
+ call insert(a:ldest, "</dl>")
+ return 0
+ endif
+ return a:deflist
+endfunction! "}}}
+
+function! s:process_tag_pre(line, pre) "{{{
+ let lines = []
+ let pre = a:pre
+ let processed = 0
+ if !pre && a:line =~ '{{{[^\(}}}\)]*\s*$'
+ let class = matchstr(a:line, '{{{\zs.*$')
+ let class = substitute(class, '\s\+$', '', 'g')
+ if class != ""
+ call add(lines, "<pre ".class.">")
+ else
+ call add(lines, "<pre>")
+ endif
+ let pre = 1
+ let processed = 1
+ elseif pre && a:line =~ '^}}}\s*$'
+ let pre = 0
+ call add(lines, "</pre>")
+ let processed = 1
+ elseif pre
+ let processed = 1
+ call add(lines, a:line)
+ endif
+ return [processed, lines, pre]
+endfunction "}}}
+
+function! s:process_tag_quote(line, quote) "{{{
+ let lines = []
+ let quote = a:quote
+ let processed = 0
+ " if a:line =~ '^\s\{4,}[^[:blank:]*#]'
+ if a:line =~ '^\s\{4,}\S'
+ if !quote
+ call add(lines, "<blockquote>")
+ let quote = 1
+ endif
+ let processed = 1
+ call add(lines, substitute(a:line, '^\s*', '', ''))
+ elseif quote && a:line =~ '^\s*$'
+ let processed = 1
+ call add(lines, a:line)
+ elseif quote
+ call add(lines, "</blockquote>")
+ let quote = 0
+ endif
+ return [processed, lines, quote]
+endfunction "}}}
+
+function! s:process_tag_list(line, lists) "{{{
+
+ function! s:add_checkbox(line, rx_list, st_tag, en_tag) "{{{
+ let st_tag = a:st_tag
+ let en_tag = a:en_tag
+
+ let chk = matchlist(a:line, a:rx_list)
+ if len(chk) > 0
+ if chk[1] == g:vimwiki_listsyms[4]
+ let st_tag .= '<del><input type="checkbox" checked />'
+ let en_tag = '</del>'.a:en_tag
+ else
+ let st_tag .= '<input type="checkbox" />'
+ endif
+ endif
+ return [st_tag, en_tag]
+ endfunction "}}}
+
+ " Do not process line that starts from *bold* text as list item.
+ let pos = match(a:line, g:vimwiki_rxBold)
+ if pos != -1 && strpart(a:line, 0, pos) =~ '^\s*$'
+ return [0, []]
+ endif
+
+ let lines = []
+ let processed = 0
+
+ if a:line =~ g:vimwiki_rxListBullet
+ let lstSym = matchstr(a:line, '[*-]')
+ let lstTagOpen = '<ul>'
+ let lstTagClose = '</ul>'
+ let lstRegExp = g:vimwiki_rxListBullet
+ elseif a:line =~ g:vimwiki_rxListNumber
+ let lstSym = '#'
+ let lstTagOpen = '<ol>'
+ let lstTagClose = '</ol>'
+ let lstRegExp = g:vimwiki_rxListNumber
+ else
+ let lstSym = ''
+ let lstTagOpen = ''
+ let lstTagClose = ''
+ let lstRegExp = ''
+ endif
+
+ let in_list = (len(a:lists) > 0)
+ if lstSym != ''
+ " To get proper indent level 'retab' the line -- change all tabs
+ " to spaces*tabstop
+ let line = substitute(a:line, '\t', repeat(' ', &tabstop), 'g')
+ let indent = stridx(line, lstSym)
+
+ let checkbox = '\s*\[\(.\?\)\]\s*'
+ let [st_tag, en_tag] = s:add_checkbox(line,
+ \ lstRegExp.checkbox, '<li>', '</li>')
+
+ 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)
+ call add(lines,
+ \ substitute(a:line, lstRegExp.'\%('.checkbox.'\)\?', '', ''))
+ let processed = 1
+ elseif in_list > 0 && a:line =~ '^\s\+\S\+'
+ if g:vimwiki_list_ignore_newline
+ call add(lines, a:line)
+ else
+ call add(lines, '<br />'.a:line)
+ endif
+ let processed = 1
+ else
+ while len(a:lists)
+ let item = remove(a:lists, -1)
+ call add(lines, item[0])
+ endwhile
+ endif
+ return [processed, lines]
+endfunction "}}}
+
+function! s:process_tag_def_list(line, deflist) "{{{
+ let lines = []
+ let deflist = a:deflist
+ let processed = 0
+ let matches = matchlist(a:line, '\(^.*\)::\%(\s\|$\)\(.*\)')
+ if !deflist && len(matches) > 0
+ call add(lines, "<dl>")
+ let deflist = 1
+ endif
+ if deflist && len(matches) > 0
+ if matches[1] != ''
+ call add(lines, "<dt>".matches[1]."</dt>")
+ endif
+ if matches[2] != ''
+ call add(lines, "<dd>".matches[2]."</dd>")
+ endif
+ let processed = 1
+ elseif deflist
+ let deflist = 0
+ call add(lines, "</dl>")
+ endif
+ return [processed, lines, deflist]
+endfunction "}}}
+
+function! s:process_tag_para(line, para) "{{{
+ let lines = []
+ let para = a:para
+ let processed = 0
+ if a:line =~ '^\s\{,3}\S'
+ if !para
+ call add(lines, "<p>")
+ let para = 1
+ endif
+ let processed = 1
+ call add(lines, a:line)
+ elseif para && a:line =~ '^\s*$'
+ call add(lines, "</p>")
+ let para = 0
+ endif
+ return [processed, lines, para]
+endfunction "}}}
+
+function! s:process_tag_h(line, id) "{{{
+ let line = a:line
+ let processed = 0
+ let h_level = 0
+ let h_text = ''
+ let h_id = ''
+ if a:line =~ g:vimwiki_rxH6
+ let h_level = 6
+ elseif a:line =~ g:vimwiki_rxH5
+ let h_level = 5
+ elseif a:line =~ g:vimwiki_rxH4
+ let h_level = 4
+ elseif a:line =~ g:vimwiki_rxH3
+ let h_level = 3
+ elseif a:line =~ g:vimwiki_rxH2
+ let h_level = 2
+ elseif a:line =~ g:vimwiki_rxH1
+ let h_level = 1
+ endif
+ if h_level > 0
+ let centered = 0
+ if a:line =~ '^\s\+'
+ let centered = 1
+ endif
+
+ let line = s:trim(line)
+
+ let h_text = s:trim(strpart(line, h_level, len(line) - h_level * 2))
+ let h_id = 'toc'.a:id
+ let h_part = '<h'.h_level.' id="'.h_id.'"'
+
+ if centered
+ let h_part .= ' class="justcenter">'
+ else
+ let h_part .= '>'
+ endif
+ let line = h_part.h_text.'</h'.h_level.'>'
+ let processed = 1
+ endif
+ return [processed, line, h_level, h_text, h_id]
+endfunction "}}}
+
+function! s:process_tag_hr(line) "{{{
+ let line = a:line
+ let processed = 0
+ if a:line =~ '^-----*$'
+ let line = '<hr />'
+ let processed = 1
+ endif
+ return [processed, line]
+endfunction "}}}
+
+function! s:process_tag_table(line, table) "{{{
+ let table = a:table
+ let lines = []
+ let processed = 0
+ if a:line =~ '^||.\+||.*'
+ if !table
+ call add(lines, "<table>")
+ let table = 1
+ endif
+ let processed = 1
+
+ call add(lines, "<tr>")
+ let pos1 = 0
+ let pos2 = 0
+ let done = 0
+ while !done
+ let pos1 = stridx(a:line, '||', pos2)
+ let pos2 = stridx(a:line, '||', pos1+2)
+ if pos1==-1 || pos2==-1
+ let done = 1
+ let pos2 = len(a:line)
+ endif
+ let line = strpart(a:line, pos1+2, pos2-pos1-2)
+ if line == ''
+ continue
+ endif
+ if strpart(line, 0, 1) == ' ' &&
+ \ strpart(line, len(line) - 1, 1) == ' '
+ call add(lines, '<td class="justcenter">'.line.'</td>')
+ elseif strpart(line, 0, 1) == ' '
+ call add(lines, '<td class="justright">'.line.'</td>')
+ else
+ call add(lines, '<td class="justleft">'.line.'</td>')
+ endif
+ endwhile
+ call add(lines, "</tr>")
+
+ elseif table
+ call add(lines, "</table>")
+ let table = 0
+ endif
+ return [processed, lines, table]
+endfunction "}}}
+
+"}}}
+
+" WIKI2HTML "{{{
+function! s:wiki2html(line, state) " {{{
+ let state = {}
+ let state.para = a:state.para
+ let state.quote = a:state.quote
+ let state.pre = a:state.pre
+ let state.table = a:state.table
+ let state.lists = a:state.lists[:]
+ let state.deflist = a:state.deflist
+ let state.placeholder = a:state.placeholder
+ let state.toc = a:state.toc
+ let state.toc_id = a:state.toc_id
+
+ let res_lines = []
+
+ let line = s:safe_html(a:line)
+
+ let processed = 0
+
+ " toc -- placeholder
+ if !processed
+ if line =~ '^\s*%toc'
+ let processed = 1
+ let param = matchstr(line, '^\s*%toc\s\zs.*')
+ let state.placeholder = ['toc', param]
+ endif
+ endif
+
+ " pres
+ if !processed
+ let [processed, lines, state.pre] = s:process_tag_pre(line, state.pre)
+ if processed && len(state.lists)
+ call s:close_tag_list(state.lists, lines)
+ endif
+ if processed && state.table
+ let state.table = s:close_tag_table(state.table, lines)
+ 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
+ if processed && state.para
+ let state.para = s:close_tag_para(state.para, lines)
+ endif
+ call extend(res_lines, lines)
+ endif
+
+ " lists
+ 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
+ if processed && state.pre
+ let state.pre = s:close_tag_pre(state.pre, lines)
+ endif
+ if processed && state.table
+ let state.table = s:close_tag_table(state.table, lines)
+ 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
+
+ call map(lines, 's:process_inline_tags(v:val)')
+
+ call extend(res_lines, lines)
+ endif
+
+ " headers
+ if !processed
+ let [processed, line, h_level, h_text, h_id] = s:process_tag_h(line, state.toc_id)
+ if processed
+ call s:close_tag_list(state.lists, res_lines)
+ let state.table = s:close_tag_table(state.table, res_lines)
+ let state.pre = s:close_tag_pre(state.pre, res_lines)
+ let state.quote = s:close_tag_quote(state.quote, res_lines)
+ call add(res_lines, line)
+
+ " gather information for table of contents
+ call add(state.toc, [h_level, h_text, h_id])
+ let state.toc_id += 1
+ endif
+ endif
+
+ " quotes
+ 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
+ if processed && state.table
+ let state.table = s:close_tag_table(state.table, lines)
+ endif
+ if processed && state.pre
+ let state.pre = s:close_tag_pre(state.pre, 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)')
+
+ call extend(res_lines, lines)
+ endif
+
+ " definition lists
+ if !processed
+ let [processed, lines, state.deflist] = s:process_tag_def_list(line, state.deflist)
+
+ call map(lines, 's:process_inline_tags(v:val)')
+
+ call extend(res_lines, lines)
+ endif
+
+ " tables
+ if !processed
+ let [processed, lines, state.table] = s:process_tag_table(line, state.table)
+
+ call map(lines, 's:process_inline_tags(v:val)')
+
+ call extend(res_lines, lines)
+ endif
+
+ " horizontal lines
+ if !processed
+ let [processed, line] = s:process_tag_hr(line)
+ if processed
+ call s:close_tag_list(state.lists, res_lines)
+ let state.table = s:close_tag_table(state.table, res_lines)
+ let state.pre = s:close_tag_pre(state.pre, res_lines)
+ call add(res_lines, line)
+ endif
+ endif
+
+ "" P
+ 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
+ if processed && state.quote
+ let state.quote = s:close_tag_quote(state.quote, res_lines)
+ endif
+ if processed && state.pre
+ let state.pre = s:close_tag_pre(state.pre, res_lines)
+ endif
+ if processed && state.table
+ let state.table = s:close_tag_table(state.table, res_lines)
+ endif
+
+ call map(lines, 's:process_inline_tags(v:val)')
+
+ call extend(res_lines, lines)
+ endif
+
+ "" add the rest
+ if !processed
+ call add(res_lines, line)
+ endif
+
+ return [res_lines, state]
+
+endfunction " }}}
+
+function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{
+
+ if !s:syntax_supported()
+ echomsg 'vimwiki: Only vimwiki_default syntax supported!!!'
+ return
+ endif
+
+ let wikifile = fnamemodify(a:wikifile, ":p")
+ let subdir = vimwiki#subdir(VimwikiGet('path'), wikifile)
+
+ let path = expand(a:path).subdir
+ call vimwiki#mkdir(path)
+
+ let lsource = s:remove_comments(readfile(wikifile))
+ let ldest = s:get_html_header(wikifile, subdir, &fileencoding)
+
+ " for table of contents placeholders.
+ let placeholders = []
+
+ " current state of converter
+ let state = {}
+ let state.para = 0
+ let state.quote = 0
+ let state.pre = 0
+ let state.table = 0
+ let state.deflist = 0
+ let state.lists = []
+ let state.placeholder = []
+ let state.toc = []
+ let state.toc_id = 1
+
+ for line in lsource
+ let oldquote = state.quote
+ let [lines, state] = s:wiki2html(line, state)
+
+ " 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) && ldest[-1] =~ '^\s*$'
+ call s:remove_blank_lines(ldest)
+ endif
+
+ if !empty(state.placeholder)
+ call add(placeholders, [state.placeholder, len(ldest), len(placeholders)])
+ let state.placeholder = []
+ endif
+
+ call extend(ldest, lines)
+ endfor
+
+
+ let toc = s:get_html_toc(state.toc)
+ call s:process_placeholders(ldest, placeholders, 'toc', toc)
+
+ call s:remove_blank_lines(ldest)
+
+ "" process end of file
+ "" close opened tags if any
+ let lines = []
+ call s:close_tag_quote(state.quote, lines)
+ call s:close_tag_para(state.para, lines)
+ call s:close_tag_pre(state.pre, 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)
+ call extend(ldest, lines)
+
+ call extend(ldest, s:get_html_footer())
+
+ "" make html file.
+ let wwFileNameOnly = fnamemodify(wikifile, ":t:r")
+ call writefile(ldest, path.wwFileNameOnly.'.html')
+endfunction "}}}
+
+function! vimwiki_html#WikiAll2HTML(path) "{{{
+ if !s:syntax_supported()
+ echomsg 'vimwiki: Only vimwiki_default syntax supported!!!'
+ return
+ endif
+
+ echomsg 'Saving vimwiki files...'
+ let cur_buf = bufname('%')
+ bufdo call s:save_vimwiki_buffer()
+ exe 'buffer '.cur_buf
+
+ let path = expand(a:path)
+ call vimwiki#mkdir(path)
+
+ echomsg 'Deleting old html files...'
+ call s:delete_html_files(path)
+
+ echomsg 'Converting wiki to html files...'
+ let setting_more = &more
+ setlocal nomore
+
+ let wikifiles = split(glob(VimwikiGet('path').'**/*'.VimwikiGet('ext')), '\n')
+ for wikifile in wikifiles
+ echomsg 'Processing '.wikifile
+ call vimwiki_html#Wiki2HTML(path, wikifile)
+ endfor
+ call s:create_default_CSS(path)
+ echomsg 'Done!'
+
+ let &more = setting_more
+endfunction "}}}
+"}}}
View
361 autoload/vimwiki_lst.vim
@@ -0,0 +1,361 @@
+" Vimwiki autoload plugin file
+" Todo lists related stuff here.
+" Author: Maxim Kim <habamax@gmail.com>
+" Home: http://code.google.com/p/vimwiki/
+
+if exists("g:loaded_vimwiki_list_auto") || &cp
+ finish
+endif
+let g:loaded_vimwiki_lst_auto = 1
+
+" Script variables {{{
+let s:rx_li_box = '\[.\?\]'
+" }}}
+
+" Script functions {{{
+
+" Get checkbox regexp
+function! s:rx_li_symbol(rate) "{{{
+ let result = ''
+ if a:rate == 100
+ let result = g:vimwiki_listsyms[4]
+ elseif a:rate == 0
+ let result = g:vimwiki_listsyms[0]
+ elseif a:rate >= 67
+ let result = g:vimwiki_listsyms[3]
+ elseif a:rate >= 34
+ let result = g:vimwiki_listsyms[2]
+ else
+ let result = g:vimwiki_listsyms[1]
+ endif
+
+ return '\['.result.'\]'
+endfunction "}}}
+
+" Get regexp of the list item.
+function! s:rx_list_item() "{{{
+ return '\('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)'
+endfunction "}}}
+
+" Get regexp of the list item with checkbox.
+function! s:rx_cb_list_item() "{{{
+ " return s:rx_list_item().'\s*\zs\[.\?\]'
+ return s:rx_list_item().'\s*\zs\[.\?\]'
+endfunction "}}}
+
+" Get level of the list item.
+function! s:get_level(lnum) "{{{
+ if VimwikiGet('syntax') == 'media'
+ let level = vimwiki#count_first_sym(getline(a:lnum))
+ else
+ let level = indent(a:lnum)
+ endif
+ return level
+endfunction "}}}
+
+" Get previous list item.
+" Returns: line number or 0.
+function! s:prev_list_item(lnum) "{{{
+ let c_lnum = a:lnum - 1
+ while c_lnum >= 1
+ let line = getline(c_lnum)
+ if line =~ s:rx_list_item()
+ return c_lnum
+ endif
+ if line =~ '^\s*$'
+ return 0
+ endif
+ let c_lnum -= 1
+ endwhile
+ return 0
+endfunction "}}}
+
+" Get next list item in the list.
+" Returns: line number or 0.
+function! s:next_list_item(lnum) "{{{
+ let c_lnum = a:lnum + 1
+ while c_lnum <= line('$')
+ let line = getline(c_lnum)
+ if line =~ s:rx_list_item()
+ return c_lnum
+ endif
+ if line =~ '^\s*$'
+ return 0
+ endif
+ let c_lnum += 1
+ endwhile
+ return 0
+endfunction "}}}
+
+" Find next list item in the buffer.
+" Returns: line number or 0.
+function! s:find_next_list_item(lnum) "{{{
+ let c_lnum = a:lnum + 1
+ while c_lnum <= line('$')
+ let line = getline(c_lnum)
+ if line =~ s:rx_list_item()
+ return c_lnum
+ endif
+ let c_lnum += 1
+ endwhile
+ return 0
+endfunction "}}}
+
+" Set state of the list item on line number "lnum" to [ ] or [x]
+function! s:set_state(lnum, rate) "{{{
+ let line = getline(a:lnum)
+ let state = s:rx_li_symbol(a:rate)
+ let line = substitute(line, s:rx_li_box, state, '')
+ call setline(a:lnum, line)
+endfunction "}}}
+
+" Get state of the list item on line number "lnum"
+function! s:get_state(lnum) "{{{
+ let state = 0
+ let line = getline(a:lnum)
+ let opt = matchstr(line, s:rx_cb_list_item())
+ if opt =~ s:rx_li_symbol(100)
+ let state = 100
+ elseif opt =~ s:rx_li_symbol(0)
+ let state = 0
+ elseif opt =~ s:rx_li_symbol(25)
+ let state = 25
+ elseif opt =~ s:rx_li_symbol(50)
+ let state = 50
+ elseif opt =~ s:rx_li_symbol(75)
+ let state = 75
+ endif
+ return state
+endfunction "}}}
+
+" Returns 1 if there is checkbox on a list item, 0 otherwise.
+function! s:is_cb_list_item(lnum) "{{{
+ return getline(a:lnum) =~ s:rx_cb_list_item()
+endfunction "}}}
+
+" Returns start line number of list item, 0 if it is not a list.
+function! s:is_list_item(lnum) "{{{
+ let c_lnum = a:lnum
+ while c_lnum >= 1
+ let line = getline(c_lnum)
+ if line =~ s:rx_list_item()
+ return c_lnum
+ endif
+ if line =~ '^\s*$'
+ return 0
+ endif
+ if indent(c_lnum) > indent(a:lnum)
+ return 0
+ endif
+ let c_lnum -= 1
+ endwhile
+ return 0
+endfunction "}}}
+
+" Returns char column of checkbox. Used in parent/child checks.
+function! s:get_li_pos(lnum) "{{{
+ return stridx(getline(a:lnum), '[')
+endfunction "}}}
+
+" Returns list of line numbers of parent and all its child items.
+function! s:get_child_items(lnum) "{{{
+ let result = []
+ let lnum = a:lnum
+ let p_pos = s:get_level(lnum)
+
+ " add parent
+ call add(result, lnum)
+
+ let lnum = s:next_list_item(lnum)
+ while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) > p_pos
+ call add(result, lnum)
+ let lnum = s:next_list_item(lnum)
+ endwhile
+
+ return result
+endfunction "}}}
+
+" Returns list of line numbers of all items of the same level.
+function! s:get_sibling_items(lnum) "{{{
+ let result = []
+ let lnum = a:lnum
+ let ind = s:get_level(lnum)
+
+ while s:get_level(lnum) >= ind &&
+ \ lnum != 0
+
+ if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
+ call add(result, lnum)
+ endif
+ let lnum = s:next_list_item(lnum)
+ endwhile
+
+ let lnum = s:prev_list_item(a:lnum)
+ while s:get_level(lnum) >= ind &&
+ \ lnum != 0
+
+ if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
+ call add(result, lnum)
+ endif
+ let lnum = s:prev_list_item(lnum)
+ endwhile
+
+ return result
+endfunction "}}}
+
+" Returns line number of the parent of lnum item
+function! s:get_parent_item(lnum) "{{{
+ let lnum = a:lnum
+ let ind = s:get_level(lnum)
+
+ let lnum = s:prev_list_item(lnum)
+ while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) >= ind
+ let lnum = s:prev_list_item(lnum)
+ endwhile
+
+ if s:is_cb_list_item(lnum)
+ return lnum
+ else
+ return a:lnum
+ endif
+endfunction "}}}
+
+" Creates checkbox in a list item.
+function! s:create_cb_list_item(lnum) "{{{
+ let line = getline(a:lnum)
+ let m = matchstr(line, s:rx_list_item())
+ if m != ''
+ let li_content = substitute(strpart(line, len(m)), '^\s*', '', '')
+ let line = m.'[ ] '.li_content
+ call setline(a:lnum, line)
+ endif
+endfunction "}}}
+
+" Tells if all of the sibling list items are checked or not.
+function! s:all_siblings_checked(lnum) "{{{
+ let result = 0
+ let cnt = 0
+ let siblings = s:get_sibling_items(a:lnum)
+ for lnum in siblings
+ let cnt += s:get_state(lnum)/100.0
+ endfor
+ let result = (cnt*100.0)/len(siblings)
+ return result
+endfunction "}}}
+
+" Creates checkbox on a list item if there is no one.
+function! s:TLI_create_checkbox(lnum) "{{{
+ if a:lnum && !s:is_cb_list_item(a:lnum)
+ if g:vimwiki_auto_checkbox
+ call s:create_cb_list_item(a:lnum)
+ endif
+ return 1
+ endif
+ return 0
+endfunction "}}}
+
+" Switch state of the child list items.
+function! s:TLI_switch_child_state(lnum) "{{{
+ let current_state = s:get_state(a:lnum)
+ if current_state == 100
+ let new_state = 0
+ else
+ let new_state = 100
+ endif
+ for lnum in s:get_child_items(a:lnum)
+ call s:set_state(lnum, new_state)
+ endfor
+endfunction "}}}
+
+" Switch state of the parent list items.
+function! s:TLI_switch_parent_state(lnum) "{{{
+ let c_lnum = a:lnum
+ while s:is_cb_list_item(c_lnum)
+ let parent_lnum = s:get_parent_item(c_lnum)
+ if parent_lnum == c_lnum
+ break
+ endif
+ call s:set_state(parent_lnum, s:all_siblings_checked(c_lnum))
+
+ let c_lnum = parent_lnum
+ endwhile
+endfunction "}}}
+
+function! s:TLI_toggle(lnum) "{{{
+ if !s:TLI_create_checkbox(a:lnum)
+ call s:TLI_switch_child_state(a:lnum)
+ endif
+ call s:TLI_switch_parent_state(a:lnum)
+endfunction "}}}
+
+" Script functions }}}
+
+" Toggle list item between [ ] and [X]
+function! vimwiki_lst#ToggleListItem(line1, line2) "{{{
+ let line1 = a:line1
+ let line2 = a:line2
+
+ if line1 != line2 && !s:is_list_item(line1)
+ let line1 = s:find_next_list_item(line1)
+ endif
+
+ let c_lnum = line1
+ while c_lnum != 0 && c_lnum <= line2
+ let li_lnum = s:is_list_item(c_lnum)
+
+ if li_lnum
+ let li_level = s:get_level(li_lnum)
+ if c_lnum == line1
+ let start_li_level = li_level
+ endif
+
+ if li_level <= start_li_level
+ call s:TLI_toggle(li_lnum)
+ let start_li_level = li_level
+ endif
+ endif
+
+ let c_lnum = s:find_next_list_item(c_lnum)
+ endwhile
+
+endfunction "}}}
+
+function! vimwiki_lst#insertCR() "{{{
+ " This function is heavily relies on proper 'set comments' option.
+ let cr = "\<CR>"
+ if getline('.') =~ s:rx_cb_list_item()
+ let cr .= '[ ] '
+ endif
+ return cr
+endfunction "}}}
+
+function! vimwiki_lst#insertOo(cmd) "{{{
+ " cmd should be 'o' or 'O'
+
+ let beg_lnum = foldclosed('.')
+ let end_lnum = foldclosedend('.')
+ if end_lnum != -1 && a:cmd ==# 'o'
+ let lnum = end_lnum
+ let line = getline(beg_lnum)
+ else
+ let line = getline('.')
+ let lnum = line('.')
+ endif
+
+ let res = ''
+ if line =~ s:rx_cb_list_item()
+ let res = matchstr(line, s:rx_list_item()).'[ ] '
+ elseif line =~ s:rx_list_item()
+ let res = matchstr(line, s:rx_list_item())
+ elseif &autoindent || &smartindent
+ let res = matchstr(line, '^\s*')
+ endif
+ if a:cmd ==# 'o'
+ call append(lnum, res)
+ call cursor(lnum + 1, col('$'))
+ else
+ call append(lnum - 1, res)
+ call cursor(lnum, col('$'))
+ endif
+endfunction "}}}
+
View
1,547 doc/vimwiki.txt
@@ -0,0 +1,1547 @@
+*vimwiki.txt* A Personal Wiki for Vim
+
+ __ __ ______ __ __ ______ __ __ ______ ~
+ /\ \/\ \/\__ _\ /'\_/`\/\ \ __/\ \/\__ _\ /\ \/\ \ /\__ _\ ~
+ \ \ \ \ \/_/\ \/ /\ \ \ \/\ \ \ \/_/\ \/ \ \ \/'/'\/_/\ \/ ~
+ \ \ \ \ \ \ \ \ \ \ \__\ \ \ \ \ \ \ \ \ \ \ \ \ , < \ \ \ ~
+ \ \ \_/ \ \_\ \__\ \ \_/\ \ \ \_/ \_\ \ \_\ \__\ \ \\`\ \_\ \__ ~
+ \ `\___/ /\_____\\ \_\\ \_\ `\___x___/ /\_____\\ \_\ \_\ /\_____\~
+ `\/__/ \/_____/ \/_/ \/_/'\/__//__/ \/_____/ \/_/\/_/ \/_____/~
+
+ Version: 0.9.8 ~
+
+==============================================================================
+CONTENTS *vimwiki-contents*
+
+ 1. Intro ...................................|vimwiki|
+ 2. Prerequisites ...........................|vimwiki-prerequisites|
+ 3. Mappings ................................|vimwiki-mappings|
+ 3.1. Global mappings .....................|vimwiki-global-mappings|
+ 3.2. Local mappings ......................|vimwiki-local-mappings|
+ 3.3. Text objects ........................|vimwiki-text-objects|
+ 4. Commands ................................|vimwiki-commands|
+ 4.1. Global commands .....................|vimwiki-global-commands|
+ 4.2. Local commands ......................|vimwiki-local-commands|
+ 5. Wiki syntax .............................|vimwiki-syntax|
+ 5.1. Typefaces ...........................|vimwiki-syntax-typefaces|
+ 5.2. Links ...............................|vimwiki-syntax-links|
+ 5.3. Headers .............................|vimwiki-syntax-headers|
+ 5.4. Paragraphs...........................|vimwiki-syntax-paragraphs|
+ 5.5. Lists ...............................|vimwiki-syntax-lists|
+ 5.6. Tables ..............................|vimwiki-syntax-tables|
+ 5.7. Preformatted text ...................|vimwiki-syntax-preformatted|
+ 5.8. Blockquotes .........................|vimwiki-syntax-blockquotes|
+ 5.9. Comments ............................|vimwiki-syntax-comments|
+ 6. Folding/Outline .........................|vimwiki-folding|
+ 7. Placeholders ............................|vimwiki-placeholders|
+ 7.1 Table of Contents ....................|vimwiki-table-of-contents|
+ 8. Todo lists...............................|vimwiki-todo-lists|
+ 9. Options .................................|vimwiki-options|
+ 10. Help ...................................|vimwiki-help|
+ 11. Author .................................|vimwiki-author|
+ 12. Changelog ..............................|vimwiki-changelog|
+ 13. License ................................|vimwiki-license|
+
+
+==============================================================================
+1. Intro *vimwiki*
+
+Vimwiki is a personal wiki for Vim -- a number of linked text files that have
+it's own syntax highlighting.
+
+With vimwiki you can
+ - organize notes and ideas
+ - manage todo-lists
+ - write documentation
+
+To do a quick start press <Leader>ww (this is usually \ww) to go to your index
+wiki file. By default it is located in: >
+ ~/vimwiki/index.wiki
+
+Feed it with the following example:
+
+= My knowledge base =
+ * MyUrgentTasks -- things to be done _yesterday_!!!
+ * ProjectGutenberg -- good books are power.
+ * ScratchPad -- various temporary stuff.
+
+
+Notice that ProjectGutenberg, MyUrgentTasks and ScratchPad highlighted as
+errors. These are links in CamelCase form that do not exists yet. (CamelCase
+form -- capitalized word connected with other capitalized words)
+
+Place cursor on ProjectGutenberg and press <Enter>. Now you are in
+ProjectGutenberg. Edit and save it, then press Backspace to return to parent
+wiki page. You should see the difference now -- ProjectGutenberg is
+highlighted as a link.
+
+
+==============================================================================
+2. Prerequisites *vimwiki-prerequisites*
+
+Make sure you have these settings in your vimrc file: >
+ set nocompatible
+ filetype plugin on
+ syntax on
+
+Without them Vimwiki will not work properly.
+
+
+==============================================================================
+3. Mappings *vimwiki-mappings*
+
+There are global and local mappings in vimwiki.
+
+------------------------------------------------------------------------------
+3.1. Global mappings *vimwiki-global-mappings*
+
+<Leader>ww or <Plug>VimwikiGoHome
+ Open index file of the [count]'s wiki.
+ <Leader>ww opens first wiki from |g:vimwiki_list|.
+ 1<Leader>ww as above opens first wiki from |g:vimwiki_list|.
+ 2<Leader>ww opens second wiki from |g:vimwiki_list|.
+ 3<Leader>ww opens third wiki from |g:vimwiki_list|.
+ etc.
+ To remap: >
+ :map <Leader>w <Plug>VimwikiGoHome
+<
+See also|:VimwikiGoHome|
+
+<Leader>wt or <Plug>VimwikiTabGoHome
+ Open index file of the [count]'s wiki in a new tab.
+ <Leader>wt tabopens first wiki from |g:vimwiki_list|.
+ 1<Leader>wt as above tabopens first wiki from |g:vimwiki_list|.
+ 2<Leader>wt tabopens second wiki from |g:vimwiki_list|.
+ 3<Leader>wt tabopens third wiki from |g:vimwiki_list|.
+ etc.
+ To remap: >
+ :map <Leader>t <Plug>VimwikiTabGoHome
+<
+See also|:VimwikiTabGoHome|
+
+<Leader>ws or <Plug>VimwikiUISelect
+ List and select available wikies.
+ To remap: >
+ :map <Leader>wq <Plug>VimwikiUISelect
+<
+See also|:VimwikiUISelect|
+
+
+------------------------------------------------------------------------------
+3.2. Local mappings *vimwiki-local-mappings*
+
+Normal mode (Keyboard):~
+ *vimwiki_<CR>*
+<CR> Follow/Create WikiWord.
+ Maps to|:VimwikiFollowWord|.
+ To remap: >
+ :map <Leader>wf <Plug>VimwikiFollowWord
+<
+ *vimwiki_<S-CR>*
+<S-CR> Split and follow/create WikiWord
+ Maps to|:VimwikiSplitWord|.
+ To remap: >
+ :map <Leader>we <Plug>VimwikiSplitWord
+<
+ *vimwiki_<C-CR>*
+<C-CR> Vertical split and follow/create WikiWord
+ Maps to|:VimwikiVSplitWord|.
+ To remap: >
+ :map <Leader>wq <Plug>VimwikiVSplitWord
+<
+ *vimwiki_<Backspace>*
+<Backspace> Go back to previous WikiWord
+ Maps to|:VimwikiGoBackWord|.
+ To remap: >
+ :map <Leader>wb <Plug>VimwikiGoBackWord
+<
+ *vimwiki_<Tab>*
+<Tab> Find next WikiWord
+ Maps to|:VimwikiNextWord|.
+ To remap: >
+ :map <Leader>wn <Plug>VimwikiNextWord
+<
+ *vimwiki_<S-Tab>*
+<S-Tab> Find previous WikiWord
+ Maps to|:VimwikiPrevWord|.
+ To remap: >
+ :map <Leader>wp <Plug>VimwikiPrevWord
+<
+ *vimwiki_<Leader>wd*
+<Leader>wd Delete WikiWord you are in.
+ Maps to|:VimwikiDeleteWord|.
+ To remap: >
+ :map <Leader>dd <Plug>VimwikiDeleteWord
+<
+ *vimwiki_<Leader>wr*
+<Leader>wr Rename WikiWord you are in.
+ Maps to|:VimwikiRenameWord|.
+ To remap: >
+ :map <Leader>rr <Plug>VimwikiRenameWord
+<
+ *vimwiki_<C-Space>*
+<C-Space> Toggle list item on/off (checked/unchecked)
+ Maps to|:VimwikiToggleListItem|.
+ To remap: >
+ :map <leader>tt <Plug>VimwikiToggleListItem
+< See |vimwiki-todo-lists|.
+
+ *vimwiki_=*
+= Add header level. Create if needed.
+ There is nothing to indent with '==' command in
+ vimwiki, so it should be ok to use '=' here.
+
+ *vimwiki_-*
+- Remove header level.
+
+Normal mode (Mouse): ~
+Works only if |g:vimwiki_use_mouse| is set to 1.
+<2-LeftMouse> Follow/Create WikiWord
+<S-2-LeftMouse> Split and follow/create WikiWord
+<C-2-LeftMouse> Vertical split and follow/create WikiWord
+<RightMouse><LeftMouse> Go back to previous WikiWord
+
+Note: <2-LeftMouse> is just left double click.
+
+------------------------------------------------------------------------------
+3.3. Text objects *vimwiki-text-objects*
+
+ah A Header with leading empty lines.
+ih Inner Header without leading empty lines.
+
+You can 'vah' to select a header with its contents or 'dah' to delete it or
+'yah' to yank it or 'cah' to change it. ;)
+
+
+==============================================================================
+4. Commands *vimwiki-commands*
+
+------------------------------------------------------------------------------
+4.1. Global Commands *vimwiki-global-commands*
+
+*:VimwikiGoHome*
+ Open index file of the current wiki.
+
+*:VimwikiTabGoHome*
+ Open index file of the current wiki in a new tab.
+
+*:VimwikiUISelect*
+ Open index file of the selected wiki.
+
+------------------------------------------------------------------------------
+4.2. Local commands *vimwiki-local-commands*
+
+*:VimwikiFollowWord*
+ Follow/create WikiWord.
+
+*:VimwikiGoBackWord*
+ Go back to previous WikiWord you come from.
+
+*:VimwikiSplitWord*
+ Split and follow/create WikiWord.
+
+*:VimwikiVSplitWord*
+ Vertical split and follow/create WikiWord.
+
+*:VimwikiNextWord*
+ Find next WikiWord.
+
+*:VimwikiPrevWord*
+ Find previous WikiWord.
+
+*:VimwikiDeleteWord*
+ Delete WikiWord you are in.
+
+*:VimwikiRenameWord*
+ Rename WikiWord you are in.
+
+*:Vimwiki2HTML*
+ Convert current WikiPage to HTML.
+
+*:VimwikiAll2HTML*
+ Convert all WikiPages to HTML.
+
+*:VimwikiToggleListItem*
+ Toggle list item on/off (checked/unchecked)
+ See |vimwiki-todo-lists|.
+
+*:VimwikiSearch* /pattern/
+*:VWS* /pattern/
+ Search for /pattern/ in current wiki.
+
+
+==============================================================================
+5. Wiki syntax *vimwiki-syntax*
+
+There are a lot of different wikies out there. Most of them have their own
+syntax and vimwiki is not an exception here. Default vimwiki's syntax is a
+subset of google's wiki syntax markup.
+
+As for MediaWiki's syntax -- it is not that convenient for non English
+(Russian in my case :)) keyboard layouts to emphasize text as it uses a lot
+of '''''' to do it. You have to switch layouts every time you want some bold
+non English text. This is the answer to "Why not MediaWiki?"
+
+Nevertheless, there is MediaWiki syntax file included in the distribution (it
+doesn't have all the fancy stuff original MediaWiki syntax has though).
+See |vimwiki-option-syntax|.
+
+
+------------------------------------------------------------------------------
+5.1. Typefaces *vimwiki-syntax-typefaces*
+
+There are a few typefaces that gives you a bit of control on how your
+text should be decorated: >
+ *bold text*
+ _italic text_
+ ~~strikeout text~~
+ `code (no syntax) text`
+ super^script^
+ sub,,script,,
+
+------------------------------------------------------------------------------
+5.2. Links *vimwiki-syntax-links*
+
+Internal links~
+WikiWords: >
+ CapitalizedWordsConnected
+
+You can limit linking of WikiWords by adding an exclamation mark in front of
+it: >
+ !CapitalizedWordsConnected
+
+Or disable it completely with |g:vimwiki_camel_case|.
+
+Link with spaces in it: >
+ [[This is a link]]
+or: >
+ [[This is a link source|Description of the link]]
+or: >
+ [[This is a link source][Description of the link]]
+
+
+External links~
+Plain link: >
+ http://code.google.com/p/vimwiki
+
+Link with description: >
+ [http://habamax.ru/blog habamax home page]
+
+
+Images and image links~
+Image link is the link with one of jpg, png or gif endings.
+Plain image link: >
+ http://someaddr.com/picture.jpg
+in html: >
+ <img src="http://someaddr.com/picture.jpg" />
+
+Link to a local image: >
+ [[images/pabloymoira.jpg]]
+in html: >
+ <img src="images/pabloymoira.jpg" />
+Path to image (ie. images/pabloymoira.jpg) is relative to
+|vimwiki-option-path_html|.
+
+Double bracketed link to an image: >
+ [[http://habamax.ru/blog/wp-content/uploads/2009/01/2740254sm.jpg]]
+in html: >
+ <img src="http://habamax.ru/ ... /.jpg" />
+
+Double bracketed link to an image with description text: >
+ [[http://habamax.ru/blog/wp-content/uploads/2009/01/2740254sm.jpg|dance]]
+in html: >
+ <a href="http://habamax.ru/ ... /.jpg">dance</a>
+
+Double bracketed link to an image with alternate text: >
+ [[http://habamax.ru/blog/wp-content/uploads/2009/01/2740254sm.jpg|dance|]]
+in html: >
+ <img src="http://habamax.ru/ ... /.jpg" alt="dance"/>
+