Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 1 | " Vim autoload file for the tohtml plugin. |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 2 | " Maintainer: Ben Fritz <fritzophrenic@gmail.com> |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 3 | " Last Change: 2010 Aug 06 |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 4 | " |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 5 | " Additional contributors: |
| 6 | " |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 7 | " Original by Bram Moolenaar <Bram@vim.org> |
| 8 | " Diff2HTML() added by Christian Brabandt <cb@256bit.org> |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 9 | " |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 10 | " See Mercurial change logs for more! |
| 11 | |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 12 | " this file uses line continuations |
| 13 | let s:cpo_sav = &cpo |
| 14 | set cpo-=C |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 15 | |
| 16 | func! tohtml#Convert2HTML(line1, line2) |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 17 | let s:settings = tohtml#GetUserSettings() |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 18 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 19 | if !&diff || s:settings.diff_one_file |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 20 | if a:line2 >= a:line1 |
| 21 | let g:html_start_line = a:line1 |
| 22 | let g:html_end_line = a:line2 |
| 23 | else |
| 24 | let g:html_start_line = a:line2 |
| 25 | let g:html_end_line = a:line1 |
| 26 | endif |
| 27 | runtime syntax/2html.vim |
| 28 | else |
| 29 | let win_list = [] |
| 30 | let buf_list = [] |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 31 | windo | if &diff | call add(win_list, winbufnr(0)) | endif |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 32 | let s:settings.whole_filler = 1 |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 33 | let g:html_diff_win_num = 0 |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 34 | for window in win_list |
| 35 | exe ":" . bufwinnr(window) . "wincmd w" |
| 36 | let g:html_start_line = 1 |
| 37 | let g:html_end_line = line('$') |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 38 | let g:html_diff_win_num += 1 |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 39 | runtime syntax/2html.vim |
| 40 | call add(buf_list, bufnr('%')) |
| 41 | endfor |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 42 | unlet g:html_diff_win_num |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 43 | call tohtml#Diff2HTML(win_list, buf_list) |
| 44 | endif |
| 45 | |
| 46 | unlet g:html_start_line |
| 47 | unlet g:html_end_line |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 48 | unlet s:settings |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 49 | endfunc |
| 50 | |
| 51 | func! tohtml#Diff2HTML(win_list, buf_list) |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 52 | let xml_line = "" |
| 53 | let tag_close = '>' |
| 54 | |
| 55 | if s:settings.use_xhtml |
| 56 | if s:settings.encoding != "" |
| 57 | let xml_line = "<?xml version=\"1.0\" encoding=\"" . s:settings.encoding . "\"?>" |
| 58 | else |
| 59 | let xml_line = "<?xml version=\"1.0\"?>" |
| 60 | endif |
| 61 | let tag_close = ' />' |
| 62 | endif |
| 63 | |
| 64 | let style = [s:settings.use_xhtml ? "" : '-->'] |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 65 | let body_line = '' |
| 66 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 67 | let html = [] |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 68 | if s:settings.use_xhtml |
| 69 | call add(html, xml_line) |
| 70 | endif |
| 71 | if s:settings.use_xhtml |
| 72 | call add(html, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">") |
| 73 | call add(html, '<html xmlns="http://www.w3.org/1999/xhtml">') |
| 74 | elseif s:settings.use_css && !s:settings.no_pre |
| 75 | call add(html, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">") |
| 76 | call add(html, '<html>') |
| 77 | else |
| 78 | call add(html, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"') |
| 79 | call add(html, ' "http://www.w3.org/TR/html4/loose.dtd">') |
| 80 | call add(html, '<html>') |
| 81 | endif |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 82 | call add(html, '<head>') |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 83 | |
| 84 | " include encoding as close to the top as possible, but only if not already |
| 85 | " contained in XML information (to avoid haggling over content type) |
| 86 | if s:settings.encoding != "" && !s:settings.use_xhtml |
| 87 | call add(html, "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:settings.encoding . '"' . tag_close) |
| 88 | endif |
| 89 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 90 | call add(html, '<title>diff</title>') |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 91 | call add(html, '<meta name="Generator" content="Vim/'.v:version/100.'.'.v:version%100.'"'.tag_close) |
| 92 | call add(html, '<meta name="plugin-version" content="'.g:loaded_2html_plugin.'"'.tag_close) |
| 93 | call add(html, '<meta name="settings" content="'. |
| 94 | \ join(filter(keys(s:settings),'s:settings[v:val]'),','). |
| 95 | \ '"'.tag_close) |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 96 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 97 | call add(html, '</head>') |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 98 | let body_line_num = len(html) |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 99 | call add(html, '<body>') |
| 100 | call add(html, '<table border="1" width="100%">') |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 101 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 102 | call add(html, '<tr>') |
| 103 | for buf in a:win_list |
| 104 | call add(html, '<th>'.bufname(buf).'</th>') |
| 105 | endfor |
| 106 | call add(html, '</tr><tr>') |
| 107 | |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 108 | let diff_style_start = 0 |
| 109 | let insert_index = 0 |
| 110 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 111 | for buf in a:buf_list |
| 112 | let temp = [] |
| 113 | exe bufwinnr(buf) . 'wincmd w' |
| 114 | |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 115 | " If text is folded because of user foldmethod settings, etc. we don't want |
| 116 | " to act on everything in a fold by mistake. |
| 117 | setlocal nofoldenable |
| 118 | |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 119 | " When not using CSS or when using xhtml, the <body> line can be important. |
| 120 | " Assume it will be the same for all buffers and grab it from the first |
| 121 | " buffer. Similarly, need to grab the body end line as well. |
| 122 | if body_line == '' |
| 123 | 1 |
| 124 | call search('<body') |
| 125 | let body_line = getline('.') |
| 126 | $ |
| 127 | call search('</body>', 'b') |
| 128 | let s:body_end_line = getline('.') |
| 129 | endif |
| 130 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 131 | " Grab the style information. Some of this will be duplicated... |
| 132 | 1 |
| 133 | let style_start = search('^<style type="text/css">') |
| 134 | 1 |
| 135 | let style_end = search('^</style>') |
| 136 | if style_start > 0 && style_end > 0 |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 137 | let buf_styles = getline(style_start + 1, style_end - 1) |
| 138 | for a_style in buf_styles |
| 139 | if index(style, a_style) == -1 |
| 140 | if diff_style_start == 0 |
| 141 | if a_style =~ '\<Diff\(Change\|Text\|Add\|Delete\)' |
| 142 | let diff_style_start = len(style)-1 |
| 143 | endif |
| 144 | endif |
| 145 | call insert(style, a_style, insert_index) |
| 146 | let insert_index += 1 |
| 147 | endif |
| 148 | endfor |
| 149 | endif |
| 150 | |
| 151 | if diff_style_start != 0 |
| 152 | let insert_index = diff_style_start |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 153 | endif |
| 154 | |
| 155 | " Delete those parts that are not needed so |
| 156 | " we can include the rest into the resulting table |
| 157 | 1,/^<body/d_ |
| 158 | $ |
| 159 | ?</body>?,$d_ |
| 160 | let temp = getline(1,'$') |
| 161 | " undo deletion of start and end part |
| 162 | " so we can later save the file as valid html |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 163 | " TODO: restore using grabbed lines if undolevel is 1? |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 164 | normal 2u |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 165 | if s:settings.use_css |
| 166 | call add(html, '<td valign="top"><div>') |
| 167 | elseif s:settings.use_xhtml |
| 168 | call add(html, '<td nowrap="nowrap" valign="top"><div>') |
| 169 | else |
| 170 | call add(html, '<td nowrap valign="top"><div>') |
| 171 | endif |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 172 | let html += temp |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 173 | call add(html, '</div></td>') |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 174 | |
| 175 | " Close this buffer |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 176 | " TODO: the comment above says we're going to allow saving the file |
| 177 | " later...but here we discard it? |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 178 | quit! |
| 179 | endfor |
| 180 | |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 181 | let html[body_line_num] = body_line |
| 182 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 183 | call add(html, '</tr>') |
| 184 | call add(html, '</table>') |
Bram Moolenaar | 8ada2cc | 2010-07-29 20:43:36 +0200 | [diff] [blame] | 185 | call add(html, s:body_end_line) |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 186 | call add(html, '</html>') |
| 187 | |
| 188 | let i = 1 |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 189 | let name = "Diff" . (s:settings.use_xhtml ? ".xhtml" : ".html") |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 190 | " Find an unused file name if current file name is already in use |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 191 | while filereadable(name) |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 192 | let name = substitute(name, '\d*\.x\?html$', '', '') . i . '.' . fnamemodify(copy(name), ":t:e") |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 193 | let i += 1 |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 194 | endwhile |
| 195 | exe "topleft new " . name |
| 196 | setlocal modifiable |
| 197 | |
| 198 | " just in case some user autocmd creates content in the new buffer, make sure |
| 199 | " it is empty before proceeding |
| 200 | %d |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 201 | call append(0, html) |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 202 | |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 203 | if len(style) > 0 |
| 204 | 1 |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 205 | let style_start = search('^</head>')-1 |
| 206 | |
| 207 | " Insert javascript to toggle matching folds open and closed in all windows, |
| 208 | " if dynamic folding is active. |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 209 | if s:settings.dynamic_folds |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 210 | call append(style_start, [ |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 211 | \ "<script type='text/javascript'>", |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 212 | \ s:settings.use_xhtml ? '//<![CDATA[' : " <!--", |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 213 | \ " function toggleFold(objID)", |
| 214 | \ " {", |
| 215 | \ " for (win_num = 1; win_num <= ".len(a:buf_list)."; win_num++)", |
| 216 | \ " {", |
| 217 | \ " var fold;", |
| 218 | \ ' fold = document.getElementById("win"+win_num+objID);', |
| 219 | \ " if(fold.className == 'closed-fold')", |
| 220 | \ " {", |
| 221 | \ " fold.className = 'open-fold';", |
| 222 | \ " }", |
| 223 | \ " else if (fold.className == 'open-fold')", |
| 224 | \ " {", |
| 225 | \ " fold.className = 'closed-fold';", |
| 226 | \ " }", |
| 227 | \ " }", |
| 228 | \ " }", |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 229 | \ s:settings.use_xhtml ? '//]]>' : " -->", |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 230 | \ "</script>" |
| 231 | \ ]) |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 232 | endif |
| 233 | |
| 234 | " Insert styles from all the generated html documents and additional styles |
| 235 | " for the table-based layout of the side-by-side diff. The diff should take |
| 236 | " up the full browser window (but not more), and be static in size, |
| 237 | " horizontally scrollable when the lines are too long. Otherwise, the diff |
| 238 | " is pretty useless for really long lines. |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 239 | if s:settings.use_css |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 240 | call append(style_start, |
| 241 | \ ['<style type="text/css">']+ |
| 242 | \ style+ |
| 243 | \ [ s:settings.use_xhtml ? '' : '<!--', |
| 244 | \ 'table { table-layout: fixed; }', |
| 245 | \ 'html, body, table, tbody { width: 100%; margin: 0; padding: 0; }', |
| 246 | \ 'th, td { width: '.printf("%.1f",100.0/len(a:win_list)).'%; }', |
| 247 | \ 'td div { overflow: auto; }', |
| 248 | \ s:settings.use_xhtml ? '' : '-->', |
| 249 | \ '</style>' |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 250 | \ ]) |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 251 | endif |
Bram Moolenaar | b02cbe3 | 2010-07-11 22:38:52 +0200 | [diff] [blame] | 252 | endif |
| 253 | endfunc |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 254 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 255 | " Gets a single user option and sets it in the passed-in Dict, or gives it the |
| 256 | " default value if the option doesn't actually exist. |
| 257 | func! tohtml#GetOption(settings, option, default) |
| 258 | if exists('g:html_'.a:option) |
| 259 | let a:settings[a:option] = g:html_{a:option} |
| 260 | else |
| 261 | let a:settings[a:option] = a:default |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 262 | endif |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 263 | endfunc |
| 264 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 265 | " returns a Dict containing the values of all user options for 2html, including |
| 266 | " default values for those not given an explicit value by the user. Discards the |
| 267 | " html_ prefix of the option for nicer looking code. |
| 268 | func! tohtml#GetUserSettings() |
| 269 | if exists('s:settings') |
| 270 | " just restore the known options if we've already retrieved them |
| 271 | return s:settings |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 272 | else |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 273 | " otherwise figure out which options are set |
| 274 | let user_settings = {} |
| 275 | |
| 276 | " Define the correct option if the old option name exists and we haven't |
| 277 | " already defined the correct one. Maybe I'll put out a warnig message about |
| 278 | " this sometime and remove the old option entirely at some even later time, |
| 279 | " but for now just silently accept the old option. |
| 280 | if exists('g:use_xhtml') && !exists("g:html_use_xhtml") |
| 281 | let g:html_use_xhtml = g:use_xhtml |
| 282 | endif |
| 283 | |
| 284 | " get current option settings with appropriate defaults |
| 285 | call tohtml#GetOption(user_settings, 'no_progress', !has("statusline") ) |
| 286 | call tohtml#GetOption(user_settings, 'diff_one_file', 0 ) |
| 287 | call tohtml#GetOption(user_settings, 'number_lines', &number ) |
| 288 | call tohtml#GetOption(user_settings, 'use_css', 1 ) |
| 289 | call tohtml#GetOption(user_settings, 'ignore_conceal', 0 ) |
| 290 | call tohtml#GetOption(user_settings, 'ignore_folding', 0 ) |
| 291 | call tohtml#GetOption(user_settings, 'dynamic_folds', 0 ) |
| 292 | call tohtml#GetOption(user_settings, 'no_foldcolumn', 0 ) |
| 293 | call tohtml#GetOption(user_settings, 'hover_unfold', 0 ) |
| 294 | call tohtml#GetOption(user_settings, 'no_pre', 0 ) |
| 295 | call tohtml#GetOption(user_settings, 'whole_filler', 0 ) |
| 296 | call tohtml#GetOption(user_settings, 'use_xhtml', 0 ) |
| 297 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 298 | " override those settings that need it |
| 299 | |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 300 | " hover opening implies dynamic folding |
| 301 | if user_settings.hover_unfold |
| 302 | let user_settings.dynamic_folds = 1 |
| 303 | endif |
| 304 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 305 | " ignore folding overrides dynamic folding |
| 306 | if user_settings.ignore_folding && user_settings.dynamic_folds |
| 307 | let user_settings.dynamic_folds = 0 |
| 308 | let user_settings.hover_unfold = 0 |
| 309 | endif |
| 310 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 311 | " dynamic folding with no foldcolumn implies hover opens |
| 312 | if user_settings.dynamic_folds && user_settings.no_foldcolumn |
| 313 | let user_settings.hover_unfold = 1 |
| 314 | endif |
| 315 | |
| 316 | " dynamic folding implies css |
| 317 | if user_settings.dynamic_folds |
| 318 | let user_settings.use_css = 1 |
| 319 | endif |
| 320 | |
| 321 | " if we're not using CSS we cannot use a pre section because <font> tags |
| 322 | " aren't allowed inside a <pre> block |
| 323 | if !user_settings.use_css |
| 324 | let user_settings.no_pre = 1 |
| 325 | endif |
| 326 | |
Bram Moolenaar | bebca9d | 2010-08-07 15:47:30 +0200 | [diff] [blame] | 327 | " Figure out proper MIME charset from the 'encoding' option. |
| 328 | if exists("g:html_use_encoding") |
| 329 | let user_settings.encoding = g:html_use_encoding |
| 330 | else |
| 331 | let vim_encoding = &encoding |
| 332 | if vim_encoding =~ '^8bit\|^2byte' |
| 333 | let vim_encoding = substitute(vim_encoding, '^8bit-\|^2byte-', '', '') |
| 334 | endif |
| 335 | if vim_encoding == 'latin1' |
| 336 | let user_settings.encoding = 'iso-8859-1' |
| 337 | elseif vim_encoding =~ "^cp12" |
| 338 | let user_settings.encoding = substitute(vim_encoding, 'cp', 'windows-', '') |
| 339 | elseif vim_encoding == 'sjis' || vim_encoding == 'cp932' |
| 340 | let user_settings.encoding = 'Shift_JIS' |
| 341 | elseif vim_encoding == 'big5' || vim_encoding == 'cp950' |
| 342 | let user_settings.encoding = "Big5" |
| 343 | elseif vim_encoding == 'euc-cn' |
| 344 | let user_settings.encoding = 'GB_2312-80' |
| 345 | elseif vim_encoding == 'euc-tw' |
| 346 | let user_settings.encoding = "" |
| 347 | elseif vim_encoding =~ '^euc\|^iso\|^koi' |
| 348 | let user_settings.encoding = substitute(vim_encoding, '.*', '\U\0', '') |
| 349 | elseif vim_encoding == 'cp949' |
| 350 | let user_settings.encoding = 'KS_C_5601-1987' |
| 351 | elseif vim_encoding == 'cp936' |
| 352 | let user_settings.encoding = 'GBK' |
| 353 | elseif vim_encoding =~ '^ucs\|^utf' |
| 354 | let user_settings.encoding = 'UTF-8' |
| 355 | else |
| 356 | let user_settings.encoding = "" |
| 357 | endif |
| 358 | endif |
| 359 | |
| 360 | " TODO: font |
| 361 | |
Bram Moolenaar | 076e8b2 | 2010-08-05 21:54:00 +0200 | [diff] [blame] | 362 | return user_settings |
Bram Moolenaar | 349b2fb | 2010-07-16 20:35:36 +0200 | [diff] [blame] | 363 | endif |
| 364 | endfunc |
| 365 | |
| 366 | let &cpo = s:cpo_sav |
| 367 | unlet s:cpo_sav |
| 368 | |
| 369 | " Make sure any patches will probably use consistent indent |
Bram Moolenaar | 7c86f4c | 2010-07-18 14:07:22 +0200 | [diff] [blame] | 370 | " vim: ts=8 sw=2 sts=2 noet |