| '.bufname(buf).'') endfor call add(html, ' | ||
|---|---|---|
| ')
    elseif s:settings.use_xhtml
      call add(html, ' ')
    else
      call add(html, ' ')
    " Close this buffer
    " TODO: the comment above says we're going to allow saving the file
    " later...but here we discard it?
    quit!
  endfor
  let html[body_line_num] = body_line
  call add(html, ' | ')
    endif
    let html += temp
    call add(html, ' | 
 block
    if !user_settings.use_css
      let user_settings.no_pre = 1
    endif
    " pre_wrap doesn't do anything if not using pre or not using CSS
    if user_settings.no_pre || !user_settings.use_css
      let user_settings.pre_wrap=0
    endif
    "}}}
    " set up expand_tabs option after all the overrides so we know the
    " appropriate defaults {{{
    if user_settings.no_pre == 0
      call tohtml#GetOption(user_settings,
	    \ 'expand_tabs',
	    \ &expandtab || &ts != 8 || user_settings.number_lines ||
	    \   (user_settings.dynamic_folds && !user_settings.no_foldcolumn))
    else
      let user_settings.expand_tabs = 1
    endif
    " }}}
    if exists("g:html_use_encoding") "{{{
      " user specified the desired MIME charset, figure out proper
      " 'fileencoding' from it or warn the user if we cannot
      let user_settings.encoding = g:html_use_encoding
      let user_settings.vim_encoding = tohtml#EncodingFromCharset(g:html_use_encoding)
      if user_settings.vim_encoding == ''
	echohl WarningMsg
	echomsg "TOhtml: file encoding for"
	      \ g:html_use_encoding
	      \ "unknown, please set 'fileencoding'"
	echohl None
      endif
    else
      " Figure out proper MIME charset from 'fileencoding' if possible
      if &l:fileencoding != '' 
	" If the buffer is not a "normal" type, the 'fileencoding' value may not
	" be trusted; since the buffer should not be written the fileencoding is
	" not intended to be used.
	if &l:buftype=='' || &l:buftype==?'help'
	  let user_settings.vim_encoding = &l:fileencoding
	  call tohtml#CharsetFromEncoding(user_settings)
	else
	  let user_settings.encoding = '' " trigger detection using &encoding
	endif
      endif
      " else from 'encoding' if possible
      if &l:fileencoding == '' || user_settings.encoding == ''
	let user_settings.vim_encoding = &encoding
	call tohtml#CharsetFromEncoding(user_settings)
      endif
      " else default to UTF-8 and warn user
      if user_settings.encoding == ''
	let user_settings.vim_encoding = 'utf-8'
	let user_settings.encoding = 'UTF-8'
	echohl WarningMsg
	echomsg "TOhtml: couldn't determine MIME charset, using UTF-8"
	echohl None
      endif
    endif "}}}
    " TODO: font
    return user_settings
  endif
endfunc "}}}
" get the proper HTML charset name from a Vim encoding option.
function! tohtml#CharsetFromEncoding(settings) "{{{
  let l:vim_encoding = a:settings.vim_encoding
  if exists('g:html_charset_override') && has_key(g:html_charset_override, l:vim_encoding)
    let a:settings.encoding = g:html_charset_override[l:vim_encoding]
  else
    if l:vim_encoding =~ '^8bit\|^2byte'
      " 8bit- and 2byte- prefixes are to indicate encodings available on the
      " system that Vim will convert with iconv(), look up just the encoding name,
      " not Vim's prefix.
      let l:vim_encoding = substitute(l:vim_encoding, '^8bit-\|^2byte-', '', '')
    endif
    if has_key(g:tohtml#encoding_to_charset, l:vim_encoding)
      let a:settings.encoding = g:tohtml#encoding_to_charset[l:vim_encoding]
    else
      let a:settings.encoding = ""
    endif
  endif
  if a:settings.encoding != ""
    let l:vim_encoding = tohtml#EncodingFromCharset(a:settings.encoding)
    if l:vim_encoding != ""
      " if the Vim encoding to HTML encoding conversion is set up (by default or
      " by the user) to convert to a different encoding, we need to also change
      " the Vim encoding of the new buffer
      let a:settings.vim_encoding = l:vim_encoding
    endif
  endif
endfun "}}}
" Get the proper Vim encoding option setting from an HTML charset name.
function! tohtml#EncodingFromCharset(encoding) "{{{
  if exists('g:html_encoding_override') && has_key(g:html_encoding_override, a:encoding)
    return g:html_encoding_override[a:encoding]
  elseif has_key(g:tohtml#charset_to_encoding, tolower(a:encoding))
    return g:tohtml#charset_to_encoding[tolower(a:encoding)]
  else
    return ""
  endif
endfun "}}}
let &cpo = s:cpo_sav
unlet s:cpo_sav
" Make sure any patches will probably use consistent indent
"   vim: ts=8 sw=2 sts=2 noet fdm=marker