Use meta charset. This may occur some problem. For example charset=Windows-31J won't work correctly.

This commit is contained in:
mattn
2013-05-08 09:28:33 +09:00
parent 6a68c46d88
commit 4757aae967

View File

@@ -146,10 +146,17 @@ endfunction
"============================================================================== "==============================================================================
function! zencoding#util#getContentFromURL(url) function! zencoding#util#getContentFromURL(url)
let res = system(printf("%s %s", g:zencoding_curl_command, shellescape(substitute(a:url, '#.*', '', '')))) let res = system(printf("%s %s", g:zencoding_curl_command, shellescape(substitute(a:url, '#.*', '', ''))))
let s1 = len(split(res, '?')) let charset = matchstr(res, '<meta[^>]\+content=["''][^;"'']\+;\s\+charset=\zs[^;"'']\+\ze["'']>')
let utf8 = iconv(res, 'utf-8', &encoding) if len(charset) == 0
let s2 = len(split(utf8, '?')) let charset = matchstr(res, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]\+>')
return (s2 == s1 || s2 >= s1 * 2) ? utf8 : res endif
if len(charset) == 0
let s1 = len(split(res, '?'))
let utf8 = iconv(res, 'utf-8', &encoding)
let s2 = len(split(utf8, '?'))
return (s2 == s1 || s2 >= s1 * 2) ? utf8 : res
endif
return iconv(res, charset, &encoding)
endfunction endfunction
function! zencoding#util#getTextFromHTML(buf) function! zencoding#util#getTextFromHTML(buf)