check encoding more smart.

This commit is contained in:
mattn
2012-06-13 18:44:45 +09:00
parent 05688356b3
commit bddc3f9ff5
2 changed files with 7 additions and 14 deletions

View File

@@ -492,10 +492,7 @@ function! zencoding#anchorizeURL(flag)
endif endif
let mx = '.*<title[^>]*>\s*\zs\([^<]\+\)\ze\s*<\/title[^>]*>.*' let mx = '.*<title[^>]*>\s*\zs\([^<]\+\)\ze\s*<\/title[^>]*>.*'
let content = zencoding#util#getContentFromURL(url, 0) let content = zencoding#util#getContentFromURL(url)
if len(matchstr(content, mx)) == 0
let content = zencoding#util#getContentFromURL(url, 1)
endif
let content = substitute(content, '\r', '', 'g') let content = substitute(content, '\r', '', 'g')
let content = substitute(content, '[ \n]\+', ' ', 'g') let content = substitute(content, '[ \n]\+', ' ', 'g')
let content = substitute(content, '<!--.\{-}-->', '', 'g') let content = substitute(content, '<!--.\{-}-->', '', 'g')

View File

@@ -144,16 +144,12 @@ endfunction
"============================================================================== "==============================================================================
" html utils " html utils
"============================================================================== "==============================================================================
function! zencoding#util#getContentFromURL(url, utf8) function! zencoding#util#getContentFromURL(url)
silent! new let res = system(printf("%s %s", g:zencoding_curl_command, shellescape(substitute(a:url, '#.*', '', ''))))
if a:utf8 let s1 = len(split(res, '?'))
silent! exec '0r ++enc=utf8 !'.g:zencoding_curl_command.' "'.substitute(a:url, '#.*', '', '').'"' let utf8 = iconv(res, 'utf-8', &encoding)
else let s2 = len(split(utf8, '?'))
silent! exec '0r!'.g:zencoding_curl_command.' "'.substitute(a:url, '#.*', '', '').'"' return s2 > s1 * 2 ? utf8 : res
endif
let ret = join(getline(1, '$'), "\n")
silent! bw!
return ret
endfunction endfunction
function! zencoding#util#getTextFromHTML(buf) function! zencoding#util#getTextFromHTML(buf)