Skip to content

Instantly share code, notes, and snippets.

@blindFS
Last active August 29, 2015 14:08
Show Gist options
  • Save blindFS/a897fa23ce12b673b223 to your computer and use it in GitHub Desktop.
Save blindFS/a897fa23ce12b673b223 to your computer and use it in GitHub Desktop.
command! Wiki2Org :call Allwiki2Org()
function! Wiki2Org()
let b:enter_block = 0
let b:ordered_index = {}
let total_line = line("$")
for lino in range(1, total_line)
let line_content = getline(lino)
if line_content =~ '^[\t ]*{{{class=.\w*.'
let b:enter_block = 1
execute lino.'s/^[\t ]*{{{class=.\(\w*\)./#+begin_src \1'
elseif line_content =~ '^[\t ]*}}}[\t ]*$'
let b:enter_block = 0
execute lino.'s/^[\t ]*}}}[\t ]*$/#+end_src'
elseif !b:enter_block
if line_content =~ '^[\t ]*|[-|]\+|[\t ]*$'
silent! execute lino.'s/-|-/-+-/g'
endif
silent! execute lino.'s/\[\[\([^\[\]]*\)\]\]/\="\[\[file:".substitute(submatch(1), " ", "%20", "g").".org\]\[".submatch(1)."\]\]"/g'
silent! execute lino.'s/{{\([^{}]*\)}}/\[\[file:\1\]\]/g'
silent! execute lino.'s/^[\t ]*\zs\*/+/g'
silent! execute lino.'s/\$\([^`$]*\)\$/\\(\1\\)/g'
silent! execute lino.'s/`\([^`]*\)`/\~\1\~/g'
silent! execute lino.'s/^[\t ]*\(=\+\)\([^=]*\)=\+/\1\2'
if line_content =~ '^[\t ]*=\+'
execute lino.'s/=/*/g'
endif
if line_content =~ '^[\t ]*#\s*'
let level = len(matchstr(line_content, '^\s*\ze#'))/&shiftwidth+1
call filter(b:ordered_index, 'str2nr(v:key) <= level')
let right_index = get(b:ordered_index, level, 0)
if !right_index
let b:ordered_index[level] = 2
let right_index = 1
else
let b:ordered_index[level] += 1
endif
execute lino.'s/^[\t ]*\zs#/'.right_index."."
elseif line_content !~ '^[\t ]*[*-]'
let b:ordered_index = {}
endif
endif
endfor
%s/[\t ]*$//g
execute 'w! ~/Dropbox/org/notes/'.substitute(expand("%:t:r"), '\s', '\\ ', 'g').'.org'
edit!
endfunction
function! Allwiki2Org() abort
for file in systemlist('ls ~/Dropbox/vimwiki/*.wiki')
let target = substitute(substitute(file, 'wiki$', 'org', ''), 'Dropbox.vimwiki', 'Dropbox/org/notes', '')
if str2nr(system('date +%s -r ' . shellescape(file))[:-2]) <
\ str2nr(system('date +%s -r ' . shellescape(target))[:-2])
else
silent! execute 'e ' . fnameescape(file)
call Wiki2Org()
endif
endfor
echom 'finished'
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment