Skip to content

Instantly share code, notes, and snippets.

@blindFS
Created August 29, 2013 10:41
Show Gist options
  • Save blindFS/6376599 to your computer and use it in GitHub Desktop.
Save blindFS/6376599 to your computer and use it in GitHub Desktop.
function! s:process_tag_pre_pygments(line, pre) "{{{
if !executable('pygmentize')
return s:process_tag_pre(a:line, a:pre)
endif
let lines = []
let pre = a:pre
let processed = 0
if !pre[0] && a:line =~ '^\s*{{{'
let s:syntax = matchstr(a:line, 'class=.\zs\w\+')
let s:syntax = s:syntax == "" ? "text" : s:syntax
if exists("g:vimwiki_code_syntax_map['".s:syntax."']")
let s:syntax = g:vimwiki_code_syntax_map[s:syntax]
endif
let s:lines_pre = ""
let pre = [1, len(matchstr(a:line, '^\s*\ze{{{'))]
let processed = 1
elseif pre[0] && a:line =~ '^\s*}}}\s*$'
let pre = [0, 0]
let processed = 1
redir! > ~/tmp/.pretemp
silent! echo s:lines_pre
redir END
silent! execute "!pygmentize -l ".s:syntax." -f html -o ~/tmp/.pretemp.html ~/tmp/.pretemp"
let lines = split(system("cat ~/tmp/.pretemp.html"),'\n')
silent !rm -f ~/tmp/.pretemp.html
elseif pre[0]
let processed = 1
let s:lines_pre .= a:line."\n"
endif
return [processed, lines, pre]
endfunction "}}}
@blindFS
Copy link
Author

blindFS commented Feb 19, 2014

直接读stdout的话unicode会莫名其妙的出错,只好存文件了,略丑...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment