- Timestamp:
- 04/06/10 20:38:14 (2 years ago)
- Children:
- 01dd7f5b7e1d40674466cfe13e7bbb72263baa65
- Parents:
- 3ee93061c45cb514c7833f79937feb7478a2629d
- git-committer:
- Luper Rouch <luper.rouch@…> (04/06/10 20:38:14)
- File:
-
- 1 edited
-
various/config/dot-vim/autoload/vst/vst.vim (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
various/config/dot-vim/autoload/vst/vst.vim
r5a60096 reec4080 25 25 " Preamble {{{ 26 26 " 27 " Note: This script relies on indentation of elements. You28 " should set it to at least 4.27 " Note: This script relies on indentation of elements. You 28 " should set it to at least 4. 29 29 " 30 30 " 31 31 if &compatible == 1 32 set nocompatible32 set nocompatible 33 33 endif 34 34 … … 41 41 " Write export immediately 42 42 if !exists("g:vst_write_export") 43 let g:vst_write_export = 043 let g:vst_write_export = 0 44 44 endif 45 45 if !exists("g:vst_included") 46 let g:vst_included = split(&rtp, ',')[0].'/autoload/vst/include/'46 let g:vst_included = split(&rtp, ',')[0].'/autoload/vst/include/' 47 47 endif 48 48 if !exists("g:vst_css_user") 49 let g:vst_css_user = ''49 let g:vst_css_user = '' 50 50 endif 51 51 if !exists("g:vst_css_default") 52 let g:vst_css_default = ''52 let g:vst_css_default = '' 53 53 endif 54 54 if !exists("g:vst_tex_preamble") 55 let g:vst_tex_preamble = ''55 let g:vst_tex_preamble = '' 56 56 endif 57 57 if !exists("g:vst_pdf_view") 58 let g:vst_user_css = 058 let g:vst_user_css = 0 59 59 endif 60 60 if !exists("g:vst_pdf_clean") 61 let g:vst_pdf_clean = 061 let g:vst_pdf_clean = 0 62 62 endif 63 63 if !exists("g:vst_tex_post") 64 let g:vst_tex_post = ''64 let g:vst_tex_post = '' 65 65 endif 66 66 if !exists("g:vst_html_post") 67 let g:vst_html_post = ''67 let g:vst_html_post = '' 68 68 endif 69 69 if !exists("g:vst_containers") 70 let g:vst_containers = []70 let g:vst_containers = [] 71 71 endif 72 72 73 73 " Placeholders: 74 " LISTDEF: list definitions75 " HEADDEF: sections detection76 " This is ideal:77 " ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~78 " And is implemented! Also for transitions.74 " LISTDEF: list definitions 75 " HEADDEF: sections detection 76 " This is ideal: 77 " ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~ 78 " And is implemented! Also for transitions. 79 79 " 80 80 " HEADDEF: … … 95 95 " format - format of export 96 96 function! vst#vst#VST_InstantWrapper(line1, line2, format) 97 let temp_write_export = g:vst_write_export98 let g:vst_write_export = 199 call vst#vst#VST_Export(a:line1, a:line2, a:format)100 let g:vst_write_export = temp_write_export101 return97 let temp_write_export = g:vst_write_export 98 let g:vst_write_export = 1 99 call vst#vst#VST_Export(a:line1, a:line2, a:format) 100 let g:vst_write_export = temp_write_export 101 return 102 102 endfunction 103 103 " }}} 104 " VST_Headers: Filter out only section titles from other elements {{{104 " VST_Headers: Filter out only section titles from other elements {{{ 105 105 " Description: get only real info about headers/section titles, these are 106 106 " bastardized versions of routines from VST_Structure but full scan was too 107 107 " slow, had to cut everything what was not necessary. 108 " text: text of whole file in List form108 " text: text of whole file in List form 109 109 function! VST_Headers(text) 110 110 111 let doc = a:text112 113 " Initiate arrays and variables {{{114 let ltype = []115 let lindent = []116 117 let g:paras = []118 let g:ptype = []119 let g:pindent = []120 let g:plinen = []121 122 " }}}123 " Detect and create line types {{{124 let lendoc = len(doc)125 for i in range(lendoc)126 if i == lendoc - 1127 let nextline = i - 1128 else129 let nextline = i + 1130 endif131 if doc[i] =~ '^\s*$'132 let ltype += ['blank']133 elseif doc[i] =~ '^\s*\.\. 2html::'134 let ltype += ['2html']135 elseif doc[i] =~ '^\s*\.\. |'136 let ltype += ['replacement']137 elseif doc[i] =~ '^\s*\.\. [[|]\?\w\+:'138 " Names of most directives aren't important for header detection139 " Comment is potential error.140 let ltype += ['nonimp']141 elseif doc[i] =~ '^\s*:.\{-1,}:\s\+'142 let ltype += ['field']143 elseif doc[i] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icvlxmICVLXM]\+\|#\))\s'144 " LISTDEF: enum embraced in parenthesis145 let cind = len(matchstr(doc[i], '^\s*'))146 let nind = len(matchstr(doc[nextline], '^\s*'))147 if nind > cind148 let ltype += ['oli']149 elseif nind == cind && doc[nextline] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s'150 let ltype += ['oli']151 elseif doc[nextline] =~ '^\s*$'152 let ltype += ['oli']153 else154 let ltype += ['p']155 endif156 elseif doc[i] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icvlxmICVLXM]\+\|#\)[\]:.)}]\s'157 " LISTDEF:158 let cind = len(matchstr(doc[i], '^\s*'))159 let nind = len(matchstr(doc[nextline], '^\s*'))160 if nind > cind161 let ltype += ['oli']162 elseif nind == cind && doc[nextline] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s'163 let ltype += ['oli']164 elseif doc[nextline] =~ '^\s*$'165 let ltype += ['oli']166 else167 let ltype += ['p']168 endif169 elseif doc[i] =~ '^\s*'.s:vst_bulletdef.'\s'170 " LISTDEF:171 let cind = len(matchstr(doc[i], '^\s*'))172 let nind = len(matchstr(doc[nextline], '^\s*'))173 if nind > cind174 let ltype += ['uli']175 elseif nind == cind && doc[nextline] =~ '^\s*'.s:vst_bulletdef.'\s'176 let ltype += ['uli']177 elseif doc[nextline] =~ '^\s*$'178 let ltype += ['uli']179 else180 let ltype += ['p']181 endif182 elseif doc[i] =~ '^\s*\(--\|-\|/\|:\|+\)\S.\{-}\( \|$\)' && doc[i] !~ '^\s*\(--\s\|:\S\+:`\)'183 if lendoc == 1184 let ltype += ['p']185 else186 let ltype += ['optlist']187 endif188 elseif doc[i] =~ '^\s*::\s*$'189 let ltype += ['emptypre']190 elseif doc[i] =~ '^\s*+[=-]\{3,}'191 let ltype += ['table']192 else193 let ltype += ['p']194 endif195 " Check indentation of each line196 let lindent += [strlen(matchstr(doc[i], '^\s*'))]197 endfor198 " }}}199 " Create false 'blank' line number 0 to make looping easier. {{{200 call insert(ltype, 'blank')201 call insert(lindent, 0)202 call insert(doc, '')203 " Create false 'blank' line to the end204 call add(ltype, 'blank')205 call add(lindent, 0)206 call add(doc, '')207 " }}}208 " Create paragraphs from line types {{{209 "210 let i = 0211 let parcounter = -1212 for line in doc213 if ltype[i] == 'blank'214 let i += 1215 continue216 else217 if ltype[i-1] == 'blank'218 let parcounter += 1219 let g:paras += [doc[i]]220 let g:ptype += [ltype[i]]221 let g:pindent += [lindent[i]]222 let g:plinen += [g:vst_reallines[i]]223 else224 let g:paras[parcounter] .= "\n".doc[i]225 endif226 endif227 228 let i += 1229 endfor230 " }}}231 " Create false 'blank' para number 0 to make looping easier. {{{232 call insert(g:ptype, 'blank')233 call insert(g:pindent, 0)234 call insert(g:paras, '')235 call insert(g:plinen, 0)236 " Create false 'blank' para on the end237 call add(g:ptype, 'blank')238 call add(g:pindent, 0)239 call add(g:paras, '')240 call add(g:plinen, 0)241 " }}}242 " Check and embrace paragraphs in pre tags <pre> (::) {{{243 let i = 0244 while i < len(g:paras)245 " Remove trailing spaces from the end of paragraph. They are meaningless246 " and can cause problems.247 let g:paras[i] = substitute(g:paras[i], '\s\+$', '', '')248 if strpart(g:paras[i], strlen(g:paras[i])-2) == '::' && g:paras[i] !~ '^\s*\.\. [a-zA-Z0-9_-]\+::\s*$' || g:ptype[i] == '2html'249 " For proper embedding of pre into lists I have to set indentation250 " level not to indentation of paragraph (including251 " enumeration/leading character) but indentation of last line.252 let plines = split(g:paras[i], '\n')253 if g:ptype[i] == 'oli'254 if plines[-1] =~ '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*\ze'255 " LISTDEF:256 let initind = strlen(matchstr(plines[-1], '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*\ze'))257 else258 let initind = strlen(matchstr(plines[-1], '^\s*'))259 endif260 elseif g:ptype[i] == 'uli'261 " LISTDEF:262 if plines[-1] =~ '^\s*\zs'.s:vst_bulletdef.'\s*\ze'263 let initind = strlen(matchstr(plines[-1], '^\s*\zs'.s:vst_bulletdef.'\s*\ze'))264 else265 let initind = strlen(matchstr(plines[-1], '^\s*'))266 endif267 elseif g:ptype[i] == 'optlist' || g:ptype[i] == 'dl'268 let initind = strlen(matchstr(plines[-1], '^\s*'))269 elseif g:ptype[i] =~ '^MED'270 if plines[-1] =~ '^\s*\.\. '271 let initind = strlen(matchstr(plines[-1], '^\s*\.\. \ze'))272 else273 let initind = strlen(matchstr(plines[-1], '^\s*'))274 endif275 else276 let initind = g:pindent[i]277 endif278 let j = i + 1279 while j < len(g:paras)280 if initind >= g:pindent[j] || g:ptype[j] == 'notend' || g:ptype[j] == 'blank'281 call insert(g:paras, '', j)282 call insert(g:pindent, g:pindent[j-1], j)283 call insert(g:ptype, 'prend', j)284 call insert(g:plinen, 0, j)285 286 if g:ptype[i] == '2html'287 let g:paras[i] = ''288 call insert(g:paras, '', i+1)289 else290 call insert(g:paras, '', i+1)291 endif292 call insert(g:pindent, g:pindent[i+1], i+1)293 call insert(g:ptype, 'prebegin', i+1)294 call insert(g:plinen, 0, i+1)295 296 " Don't allow for checking inside embraced fragment for297 " pre start conditions298 let i = j299 300 break301 else302 if g:ptype[j] == 'anonlink'303 let parlines = split(g:paras[j], '\n')304 for line in parlines305 call filter(g:vst_anonhlinkdb, 'v:val !~ "'.line.'"')306 endfor307 endif308 let g:ptype[j] = 'pre'309 let g:paras[j] = substitute(g:paras[j], '`', '\`', 'g')310 let g:paras[j] = substitute(g:paras[j], '_', '\_', 'g')311 let g:paras[j] = substitute(g:paras[j], '\[', '\[', 'g')312 let g:paras[j] = substitute(g:paras[j], '\.', '\.', 'g')313 let g:paras[j] = substitute(g:paras[j], '|', '\|', 'g')314 315 endif316 let j += 1317 endwhile318 endif319 let i += 1320 endwhile321 " }}}322 " Build databases NOW. {{{323 " For this we have to glue together g:paras,324 " split it along \n and perform other footnote detection actions.325 " But we want to make it only once on first parsing, not inside of tables326 if !exists('b:vst_first_parsing')327 328 " Some actions should be taken only first time when parsing whole file (not in329 " tables cells). Set this variable and unlet it when returning from export330 "let b:vst_first_parsing = 1331 332 " Build here also other databases?333 let fntext = split(join(g:paras, "\n\n"), "\n")334 335 call VST_CreateDBs(fntext)336 337 "let g:vst_anonhlinkdb = filter(copy(fntext), 'v:val =~ "^\\s*\\(\\.\\. __:\\|__ \\)"')338 339 endif340 " }}}341 " Build replacement database. {{{342 let i = 0343 while i < len(g:paras)344 if g:ptype[i] == 'replacement'345 let from = matchstr(g:paras[i], '^\s*\.\. |\zs.\{-}\ze|')346 let into = matchstr(g:paras[i], '^\s*\.\. |.\{-}|\s\+\zs.*')347 let g:vst_replacedb[from] = into348 349 endif350 let i += 1351 endwhile352 " }}} 353 " Detect if par is a header (<hx>) {{{354 let i = 0355 let h1 = ''356 let h2 = ''357 let h3 = ''358 let h4 = ''359 let h5 = ''360 while i < len(g:paras)361 if g:ptype[i] !~ '^pre'362 if g:paras[i] =~ '\n\s*'.s:vst_headdef.'\s*\(\n\|$\)' && g:ptype[i] !~ 'table'363 let parlines = split(g:paras[i], '\n')364 if parlines[1] =~ '^\s*'.s:vst_headdef.'\s*$'365 let double = ' '366 elseif parlines[0] == parlines[2] && parlines[0] =~ '^\s*'.s:vst_headdef.'\s*$'367 let double = 'd'368 call remove(parlines, 0)369 endif370 let lchar = matchstr(parlines[1], '.\ze\s*$').double371 if lchar =~ s:vst_headchars372 if h1 == '' || lchar == h1373 let h1 = lchar374 let g:ptype[i] = 'h1'375 elseif h2 == '' || lchar == h2376 let h2 = lchar377 let g:ptype[i] = 'h2'378 elseif h3 == '' || lchar == h3379 let h3 = lchar380 let g:ptype[i] = 'h3'381 elseif h4 == '' || lchar == h4382 let h4 = lchar383 let g:ptype[i] = 'h4'384 elseif h5 == '' || lchar == h5385 let h5 = lchar386 let g:ptype[i] = 'h5'387 else388 let g:ptype[i] = 'h6'389 endif390 let modlchar = substitute(lchar, '[d ]', '', 'g')391 let g:vst_headers[g:ptype[i]] = repeat(modlchar, 9).double392 " Everything after ornament put into next paragraph393 " p type. Ugly but prevents worse things.394 "395 if len(parlines) > 2396 let g:paras[i] = join(parlines[0:1], "\n")397 call insert(g:paras, join(parlines[2:], "\n"), i+1)398 call insert(g:pindent, g:pindent[i], i+1)399 call insert(g:plinen, 0, i+1)400 401 if parlines[2] =~ '^\s*:.\{-1,}:\s\+'402 call insert(g:ptype, 'field', i+1)403 else404 call insert(g:ptype, 'sub'.g:ptype[i], i+1)405 endif406 else407 let g:paras[i] = join(parlines, "\n")408 endif409 endif410 endif411 endif412 let i += 1413 endwhile414 " }}}111 let doc = a:text 112 113 " Initiate arrays and variables {{{ 114 let ltype = [] 115 let lindent = [] 116 117 let g:paras = [] 118 let g:ptype = [] 119 let g:pindent = [] 120 let g:plinen = [] 121 122 " }}} 123 " Detect and create line types {{{ 124 let lendoc = len(doc) 125 for i in range(lendoc) 126 if i == lendoc - 1 127 let nextline = i - 1 128 else 129 let nextline = i + 1 130 endif 131 if doc[i] =~ '^\s*$' 132 let ltype += ['blank'] 133 elseif doc[i] =~ '^\s*\.\. 2html::' 134 let ltype += ['2html'] 135 elseif doc[i] =~ '^\s*\.\. |' 136 let ltype += ['replacement'] 137 elseif doc[i] =~ '^\s*\.\. [[|]\?\w\+:' 138 " Names of most directives aren't important for header detection 139 " Comment is potential error. 140 let ltype += ['nonimp'] 141 elseif doc[i] =~ '^\s*:.\{-1,}:\s\+' 142 let ltype += ['field'] 143 elseif doc[i] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icvlxmICVLXM]\+\|#\))\s' 144 " LISTDEF: enum embraced in parenthesis 145 let cind = len(matchstr(doc[i], '^\s*')) 146 let nind = len(matchstr(doc[nextline], '^\s*')) 147 if nind > cind 148 let ltype += ['oli'] 149 elseif nind == cind && doc[nextline] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s' 150 let ltype += ['oli'] 151 elseif doc[nextline] =~ '^\s*$' 152 let ltype += ['oli'] 153 else 154 let ltype += ['p'] 155 endif 156 elseif doc[i] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icvlxmICVLXM]\+\|#\)[\]:.)}]\s' 157 " LISTDEF: 158 let cind = len(matchstr(doc[i], '^\s*')) 159 let nind = len(matchstr(doc[nextline], '^\s*')) 160 if nind > cind 161 let ltype += ['oli'] 162 elseif nind == cind && doc[nextline] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s' 163 let ltype += ['oli'] 164 elseif doc[nextline] =~ '^\s*$' 165 let ltype += ['oli'] 166 else 167 let ltype += ['p'] 168 endif 169 elseif doc[i] =~ '^\s*'.s:vst_bulletdef.'\s' 170 " LISTDEF: 171 let cind = len(matchstr(doc[i], '^\s*')) 172 let nind = len(matchstr(doc[nextline], '^\s*')) 173 if nind > cind 174 let ltype += ['uli'] 175 elseif nind == cind && doc[nextline] =~ '^\s*'.s:vst_bulletdef.'\s' 176 let ltype += ['uli'] 177 elseif doc[nextline] =~ '^\s*$' 178 let ltype += ['uli'] 179 else 180 let ltype += ['p'] 181 endif 182 elseif doc[i] =~ '^\s*\(--\|-\|/\|:\|+\)\S.\{-}\( \|$\)' && doc[i] !~ '^\s*\(--\s\|:\S\+:`\)' 183 if lendoc == 1 184 let ltype += ['p'] 185 else 186 let ltype += ['optlist'] 187 endif 188 elseif doc[i] =~ '^\s*::\s*$' 189 let ltype += ['emptypre'] 190 elseif doc[i] =~ '^\s*+[=-]\{3,}' 191 let ltype += ['table'] 192 else 193 let ltype += ['p'] 194 endif 195 " Check indentation of each line 196 let lindent += [strlen(matchstr(doc[i], '^\s*'))] 197 endfor 198 " }}} 199 " Create false 'blank' line number 0 to make looping easier. {{{ 200 call insert(ltype, 'blank') 201 call insert(lindent, 0) 202 call insert(doc, '') 203 " Create false 'blank' line to the end 204 call add(ltype, 'blank') 205 call add(lindent, 0) 206 call add(doc, '') 207 " }}} 208 " Create paragraphs from line types {{{ 209 " 210 let i = 0 211 let parcounter = -1 212 for line in doc 213 if ltype[i] == 'blank' 214 let i += 1 215 continue 216 else 217 if ltype[i-1] == 'blank' 218 let parcounter += 1 219 let g:paras += [doc[i]] 220 let g:ptype += [ltype[i]] 221 let g:pindent += [lindent[i]] 222 let g:plinen += [g:vst_reallines[i]] 223 else 224 let g:paras[parcounter] .= "\n".doc[i] 225 endif 226 endif 227 228 let i += 1 229 endfor 230 " }}} 231 " Create false 'blank' para number 0 to make looping easier. {{{ 232 call insert(g:ptype, 'blank') 233 call insert(g:pindent, 0) 234 call insert(g:paras, '') 235 call insert(g:plinen, 0) 236 " Create false 'blank' para on the end 237 call add(g:ptype, 'blank') 238 call add(g:pindent, 0) 239 call add(g:paras, '') 240 call add(g:plinen, 0) 241 " }}} 242 " Check and embrace paragraphs in pre tags <pre> (::) {{{ 243 let i = 0 244 while i < len(g:paras) 245 " Remove trailing spaces from the end of paragraph. They are meaningless 246 " and can cause problems. 247 let g:paras[i] = substitute(g:paras[i], '\s\+$', '', '') 248 if strpart(g:paras[i], strlen(g:paras[i])-2) == '::' && g:paras[i] !~ '^\s*\.\. [a-zA-Z0-9_-]\+::\s*$' || g:ptype[i] == '2html' 249 " For proper embedding of pre into lists I have to set indentation 250 " level not to indentation of paragraph (including 251 " enumeration/leading character) but indentation of last line. 252 let plines = split(g:paras[i], '\n') 253 if g:ptype[i] == 'oli' 254 if plines[-1] =~ '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*\ze' 255 " LISTDEF: 256 let initind = strlen(matchstr(plines[-1], '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*\ze')) 257 else 258 let initind = strlen(matchstr(plines[-1], '^\s*')) 259 endif 260 elseif g:ptype[i] == 'uli' 261 " LISTDEF: 262 if plines[-1] =~ '^\s*\zs'.s:vst_bulletdef.'\s*\ze' 263 let initind = strlen(matchstr(plines[-1], '^\s*\zs'.s:vst_bulletdef.'\s*\ze')) 264 else 265 let initind = strlen(matchstr(plines[-1], '^\s*')) 266 endif 267 elseif g:ptype[i] == 'optlist' || g:ptype[i] == 'dl' 268 let initind = strlen(matchstr(plines[-1], '^\s*')) 269 elseif g:ptype[i] =~ '^MED' 270 if plines[-1] =~ '^\s*\.\. ' 271 let initind = strlen(matchstr(plines[-1], '^\s*\.\. \ze')) 272 else 273 let initind = strlen(matchstr(plines[-1], '^\s*')) 274 endif 275 else 276 let initind = g:pindent[i] 277 endif 278 let j = i + 1 279 while j < len(g:paras) 280 if initind >= g:pindent[j] || g:ptype[j] == 'notend' || g:ptype[j] == 'blank' 281 call insert(g:paras, '', j) 282 call insert(g:pindent, g:pindent[j-1], j) 283 call insert(g:ptype, 'prend', j) 284 call insert(g:plinen, 0, j) 285 286 if g:ptype[i] == '2html' 287 let g:paras[i] = '' 288 call insert(g:paras, '', i+1) 289 else 290 call insert(g:paras, '', i+1) 291 endif 292 call insert(g:pindent, g:pindent[i+1], i+1) 293 call insert(g:ptype, 'prebegin', i+1) 294 call insert(g:plinen, 0, i+1) 295 296 " Don't allow for checking inside embraced fragment for 297 " pre start conditions 298 let i = j 299 300 break 301 else 302 if g:ptype[j] == 'anonlink' 303 let parlines = split(g:paras[j], '\n') 304 for line in parlines 305 call filter(g:vst_anonhlinkdb, 'v:val !~ "'.line.'"') 306 endfor 307 endif 308 let g:ptype[j] = 'pre' 309 let g:paras[j] = substitute(g:paras[j], '`', '\`', 'g') 310 let g:paras[j] = substitute(g:paras[j], '_', '\_', 'g') 311 let g:paras[j] = substitute(g:paras[j], '\[', '\[', 'g') 312 let g:paras[j] = substitute(g:paras[j], '\.', '\.', 'g') 313 let g:paras[j] = substitute(g:paras[j], '|', '\|', 'g') 314 315 endif 316 let j += 1 317 endwhile 318 endif 319 let i += 1 320 endwhile 321 " }}} 322 " Build databases NOW. {{{ 323 " For this we have to glue together g:paras, 324 " split it along \n and perform other footnote detection actions. 325 " But we want to make it only once on first parsing, not inside of tables 326 if !exists('b:vst_first_parsing') 327 328 " Some actions should be taken only first time when parsing whole file (not in 329 " tables cells). Set this variable and unlet it when returning from export 330 "let b:vst_first_parsing = 1 331 332 " Build here also other databases? 333 let fntext = split(join(g:paras, "\n\n"), "\n") 334 335 call VST_CreateDBs(fntext) 336 337 "let g:vst_anonhlinkdb = filter(copy(fntext), 'v:val =~ "^\\s*\\(\\.\\. __:\\|__ \\)"') 338 339 endif 340 " }}} 341 " Build replacement database. {{{ 342 let i = 0 343 while i < len(g:paras) 344 if g:ptype[i] == 'replacement' 345 let from = matchstr(g:paras[i], '^\s*\.\. |\zs.\{-}\ze|') 346 let into = matchstr(g:paras[i], '^\s*\.\. |.\{-}|\s\+\zs.*') 347 let g:vst_replacedb[from] = into 348 349 endif 350 let i += 1 351 endwhile 352 " }}} 353 " Detect if par is a header (<hx>) {{{ 354 let i = 0 355 let h1 = '' 356 let h2 = '' 357 let h3 = '' 358 let h4 = '' 359 let h5 = '' 360 while i < len(g:paras) 361 if g:ptype[i] !~ '^pre' 362 if g:paras[i] =~ '\n\s*'.s:vst_headdef.'\s*\(\n\|$\)' && g:ptype[i] !~ 'table' 363 let parlines = split(g:paras[i], '\n') 364 if parlines[1] =~ '^\s*'.s:vst_headdef.'\s*$' 365 let double = ' ' 366 elseif parlines[0] == parlines[2] && parlines[0] =~ '^\s*'.s:vst_headdef.'\s*$' 367 let double = 'd' 368 call remove(parlines, 0) 369 endif 370 let lchar = matchstr(parlines[1], '.\ze\s*$').double 371 if lchar =~ s:vst_headchars 372 if h1 == '' || lchar == h1 373 let h1 = lchar 374 let g:ptype[i] = 'h1' 375 elseif h2 == '' || lchar == h2 376 let h2 = lchar 377 let g:ptype[i] = 'h2' 378 elseif h3 == '' || lchar == h3 379 let h3 = lchar 380 let g:ptype[i] = 'h3' 381 elseif h4 == '' || lchar == h4 382 let h4 = lchar 383 let g:ptype[i] = 'h4' 384 elseif h5 == '' || lchar == h5 385 let h5 = lchar 386 let g:ptype[i] = 'h5' 387 else 388 let g:ptype[i] = 'h6' 389 endif 390 let modlchar = substitute(lchar, '[d ]', '', 'g') 391 let g:vst_headers[g:ptype[i]] = repeat(modlchar, 9).double 392 " Everything after ornament put into next paragraph 393 " p type. Ugly but prevents worse things. 394 " 395 if len(parlines) > 2 396 let g:paras[i] = join(parlines[0:1], "\n") 397 call insert(g:paras, join(parlines[2:], "\n"), i+1) 398 call insert(g:pindent, g:pindent[i], i+1) 399 call insert(g:plinen, 0, i+1) 400 401 if parlines[2] =~ '^\s*:.\{-1,}:\s\+' 402 call insert(g:ptype, 'field', i+1) 403 else 404 call insert(g:ptype, 'sub'.g:ptype[i], i+1) 405 endif 406 else 407 let g:paras[i] = join(parlines, "\n") 408 endif 409 endif 410 endif 411 endif 412 let i += 1 413 endwhile 414 " }}} 415 415 416 416 endfunction … … 419 419 " VST_Structure: Analyze of text structure 420 420 " Description: Take given table and analyze it 421 " - text: text in form of List421 " - text: text in form of List 422 422 function! VST_Structure(text) 423 423 424 424 let doc = a:text 425 425 426 " Initiate arrays and variables {{{427 let ltype = []428 let lindent = []429 430 if !exists("g:vst_recursion")431 let g:vst_recursion = 0432 else433 let g:vst_recursion += 1434 endif435 436 if exists("g:paras")437 let g:paras_rez += [g:paras]438 let g:paras = []439 else440 let g:paras_rez = []441 let g:paras = []442 endif443 if exists("g:ptype")444 let g:ptype_rez += [g:ptype]445 let g:ptype = []446 else447 let g:ptype_rez = []448 let g:ptype = []449 endif450 if exists("g:pindent")451 let g:pindent_rez += [g:pindent]452 let g:pindent = []453 else454 let g:pindent_rez = []455 let g:pindent = []456 endif457 if exists("g:plinen")458 let g:plinen_rez += [g:plinen]459 let g:plinen = []460 else461 let g:plinen_rez = []462 let g:plinen = []463 endif464 465 let toc = ''466 " }}}467 " Detect and create line types {{{468 let lendoc = len(doc)469 for line in range(lendoc)470 if line == lendoc - 1471 let nextline = line - 1472 else473 let nextline = line + 1474 endif475 if doc[line] =~ '^\s*$'476 let ltype += ['blank']477 elseif doc[line] =~ '^\s*\.\. _.*:\s*$'478 let ltype += ['intlink']479 elseif doc[line] =~ '^\s*\.\. __:'480 let ltype += ['anonlink']481 elseif doc[line] =~ '^\s*__'482 let ltype += ['anonlink']483 elseif doc[line] =~ '^\s*\.\. _'484 let ltype += ['link']485 elseif doc[line] =~ '^\s*\.\. image::'486 let ltype += ['img']487 elseif doc[line] =~? '^\s*\.\. \(note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)::'488 let ltype += ['MED']489 elseif doc[line] =~? '^\s*\.\. figure::'490 let ltype += ['MED-figure']491 elseif doc[line] =~ '^\s*\.\. \[\d\+\]'492 let ltype += ['MED-footnote']493 elseif doc[line] =~ '^\s*\.\. \[#\]'494 let ltype += ['MED-autofootnote']495 elseif doc[line] =~ '^\s*\.\. \[#\k\+\]'496 let ltype += ['MED-labelfootnote']497 elseif doc[line] =~ '^\s*\.\. \[\k\+\]'498 let ltype += ['MED-citation']499 elseif doc[line] =~ '^\s*\.\. pull-quote::'500 let ltype += ['MED-pullquote']501 elseif doc[line] =~ '^\s*\.\. block::'502 let ltype += ['MED-block']503 elseif doc[line] =~ '^\s*\.\. container::'504 let ltype += ['MED-container']505 elseif doc[line] =~ '^\s*\.\. topic::'506 let ltype += ['MED-topic']507 elseif doc[line] =~ '^\s*\.\. sidebar::'508 let ltype += ['MED-sidebar']509 elseif doc[line] =~ '^\s*\.\. compound::'510 let ltype += ['MED-compound']511 elseif doc[line] =~ '^\s*\.\. class::'512 let ltype += ['MED-class']513 elseif doc[line] =~ '^\s*\.\. raw::\s*\(la\)\?tex\s\+html'514 let ltype += ['rawboth']515 elseif doc[line] =~ '^\s*\.\. raw::\s*html\s\+\(la\)\?tex'516 let ltype += ['rawboth']517 elseif doc[line] =~ '^\s*\.\. raw::\s*\(la\)\?tex'518 let ltype += ['rawlatex']519 elseif doc[line] =~ '^\s*\.\. raw::\s*html'520 let ltype += ['rawhtml']521 elseif doc[line] =~ '^\s*\.\. role::'522 let ltype += ['role']523 elseif doc[line] =~ '^\s*\.\. default-role::'524 let ltype += ['defaultr']525 elseif doc[line] =~ '^\s*\.\. latexonly::'526 let ltype += ['latexonly']527 elseif doc[line] =~ '^\s*\.\. htmlonly::'528 let ltype += ['htmlonly']529 elseif doc[line] =~ '^\s*\.\. contents::\s*:local'530 let ltype += ['empty']531 elseif doc[line] =~ '^\s*\.\. contents::'532 let ltype += ['toc']533 elseif doc[line] =~ '^\s*\.\. comment::'534 let ltype += ['comment']535 elseif doc[line] =~ '^\s*\.\. title::'536 let ltype += ['title']537 elseif doc[line] =~ '^\s*\.\. rubric::'538 let ltype += ['rubric']539 elseif doc[line] =~ '^\s*\.\. 2html::'540 let ltype += ['2html']541 elseif doc[line] =~ '^\s*\.\. meta::'542 let ltype += ['meta']543 elseif doc[line] =~ '^\s*\.\. |'544 let ltype += ['replacement']545 elseif doc[line] =~ '^\s*\.\. [a-zA-Z-]\+::' && doc[line] !~ 'header\|footer'546 " Unknown directives treated as pre547 " it doesn't cover contents of these paragraphs, they are548 " processed normally.549 let ltype += ['MED-unknown']550 elseif doc[line] =~ '^\s*\.\.\(\s\|$\)'551 " Everything else beginning with double dot will be treated as552 " comment and completely removed from output. If you want to only553 " hid this use one doc[line] comments554 let ltype += ['MED-comment']555 elseif doc[line] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s'556 " LISTDEF: enum embraced in parenthesis557 let cind = len(matchstr(doc[line], '^\s*'))558 let nind = len(matchstr(doc[nextline], '^\s*'))559 if nind > cind560 let ltype += ['oli']561 elseif nind == cind && doc[nextline] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s'562 let ltype += ['oli']563 elseif doc[nextline] =~ '^\s*$'564 let ltype += ['oli']565 else566 let ltype += ['p']567 endif568 elseif doc[line] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s'569 " LISTDEF:570 let cind = len(matchstr(doc[line], '^\s*'))571 let nind = len(matchstr(doc[nextline], '^\s*'))572 if nind > cind573 let ltype += ['oli']574 elseif nind == cind && doc[nextline] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s'575 let ltype += ['oli']576 elseif doc[nextline] =~ '^\s*$'577 let ltype += ['oli']578 else579 let ltype += ['p']580 endif581 elseif doc[line] =~ '^\s*'.s:vst_bulletdef.'\s'582 " LISTDEF:583 let cind = len(matchstr(doc[line], '^\s*'))584 let nind = len(matchstr(doc[nextline], '^\s*'))585 if nind > cind586 let ltype += ['uli']587 elseif nind == cind && doc[nextline] =~ '^\s*'.s:vst_bulletdef.'\s'588 let ltype += ['uli']589 elseif doc[nextline] =~ '^\s*$'590 let ltype += ['uli']591 else592 let ltype += ['p']593 endif594 elseif doc[line] =~ '^\s*:.\{-1,}:\(\s\+\|$\)'595 let ltype += ['field']596 elseif doc[line] =~ '^\s*::\s*$'597 let ltype += ['emptypre']598 elseif doc[line] =~ '^\s*| '599 let ltype += ['verse']600 elseif doc[line] =~ '^\s*+-\{3,}'601 let ltype += ['table']602 elseif doc[line] =~ '^\s*+=\{3,}'603 let ltype += ['bltable']604 elseif doc[line] =~ '^\s*\(--\|-\|/\|:\|+\)\S.\{-}\( \|$\)' && doc[line] !~ '^\s*\(--\s\|:\S\+:`\)'605 if lendoc == 1606 let ltype += ['p']607 else608 let ltype += ['optlist']609 endif610 elseif doc[line] =~ '^\s*>>>'611 let ltype += ['doctest']612 elseif doc[line] =~ '^\s*=\{2,}\s\+=\{2,}'613 let ltype += ['simpletbl']614 else615 let ltype += ['p']616 " Remove backslash escaping special meaning for verse paragraphs617 let doc[line] = substitute(doc[line], '^\(\s*\)\\|', '\1|', '')618 endif619 " Check indentation of each doc[line]620 let lindent += [strlen(matchstr(doc[line], '^\s*'))]621 endfor622 " }}}623 " Create false 'blank' line number 0 to make looping easier. {{{624 call insert(ltype, 'blank')625 call insert(lindent, 0)626 call insert(doc, '')627 " Create false 'blank' line to the end628 call add(ltype, 'blank')629 call add(lindent, 0)630 call add(doc, '')631 " }}}632 " Create paragraphs from line types {{{633 "634 let i = 0635 let parcounter = -1636 for line in doc637 if ltype[i] == 'blank'638 let i += 1639 continue640 else641 if ltype[i-1] == 'blank'642 let parcounter += 1643 let g:paras += [doc[i]]644 let g:ptype += [ltype[i]]645 let g:pindent += [lindent[i]]646 let g:plinen += [g:vst_reallines[i]]647 else648 let g:paras[parcounter] .= "\n".doc[i]649 endif650 endif651 652 let i += 1653 endfor654 " }}}655 " Create false 'blank' para number 0 to make looping easier. {{{656 call insert(g:ptype, 'blank')657 call insert(g:pindent, 0)658 call insert(g:paras, '')659 call insert(g:plinen, 0)660 " Create false 'blank' para on the end661 call add(g:ptype, 'blank')662 call add(g:pindent, 0)663 call add(g:paras, '')664 call add(g:plinen, 0)665 " }}}666 " Loop through paragraphs to concatenate simple tables. {{{667 if string(g:ptype) =~ "'simpletbl'"668 let i = 0669 while i < len(g:paras)670 if g:ptype[i] == 'simpletbl'671 " Check if last line matches simple table syntax672 if g:paras[i] !~ '\n\s*=\{2,}\(\s\+=\{2,}\)\+\s*$' && i < len(g:paras)-1673 let g:paras[i] = g:paras[i]."\n\n".g:paras[i+1]674 " Remove elements from appropriate tables675 call remove(g:paras, i+1)676 call remove(g:pindent, i+1)677 call remove(g:ptype, i+1)678 call remove(g:plinen, i+1)679 let i -= 1680 endif681 endif682 let i += 1683 endwhile684 endif685 " }}}686 " Loop through empty paragraphs to make them really empty. {{{687 if string(g:ptype) =~ "'empty'"688 let i = 0689 while i < len(g:paras)690 if g:ptype[i] == 'empty'691 let g:paras[i] = ''692 endif693 let i += 1694 endwhile695 endif696 " }}}697 " Loop through rawlatex paragraphs correct next paragraphs. {{{698 if string(g:ptype) =~ "'rawlatex'"699 let i = 0700 while i < len(g:paras)701 if g:ptype[i] == 'rawlatex'702 if g:pindent[i+1] > g:pindent[i]703 let g:ptype[i+1] = 'rawlatexcontent'704 endif705 endif706 let i += 1707 endwhile708 endif709 " }}}710 " Loop through rawboth paragraphs correct next paragraphs. {{{711 if string(g:ptype) =~ "'rawboth'"712 let i = 0713 while i < len(g:paras)714 if g:ptype[i] == 'rawboth'715 if g:pindent[i+1] > g:pindent[i]716 let g:ptype[i+1] = 'rawbothcontent'717 endif718 endif719 let i += 1720 endwhile721 endif722 " }}}723 " Loop through rawhtml paragraphs correct next paragraphs. {{{724 if string(g:ptype) =~ "'rawhtml'"725 let i = 0726 while i < len(g:paras)727 if g:ptype[i] == 'rawhtml'728 if g:pindent[i+1] > g:pindent[i]729 let g:ptype[i+1] = 'rawhtmlcontent'730 endif731 endif732 let i += 1733 endwhile734 endif735 " }}}736 " Loop through p paragraphs to sort out additional types (dl). {{{737 let i = 0738 while i < len(g:paras)739 if g:ptype[i] == 'p'740 let parlines = split(g:paras[i], '\n')741 if len(parlines) > 1 && g:paras[i] !~ '^\s*--\?'742 let dlpindent1 = strlen(matchstr(parlines[0], '^\s*'))743 let dlpindent2 = strlen(matchstr(parlines[1], '^\s*'))744 if dlpindent2 > dlpindent1745 let g:ptype[i] = 'dl'746 endif747 endif748 endif749 let i += 1750 endwhile751 " }}}752 " Loop through paragraphs to sort out prequoted type. {{{753 " This par type could be catched only in second par, so we don't have to754 " start from 0755 let i = 1756 while i < len(g:paras)757 if g:ptype[i] == 'p' || g:ptype[i] == 'verse' || g:ptype[i] =~ 'li'758 if g:paras[i] =~ "^\\s*[][<>!:;=|()\"#%'*+$\&,./\?@^_`{}\~-]"759 if g:paras[i-1] =~ '::\s*$' && g:paras[i-1] !~ '^\s*\.\. \w\+::\s*$' && g:pindent[i] == g:pindent[i-1]760 if g:ptype[i] == 'anonlink'761 let parlines = split(g:paras[i], '\n')762 for line in parlines763 call filter(g:vst_anonhlinkdb, 'v:val !~ "'.line.'"')764 endfor765 endif766 let g:ptype[i] = 'prequoted'767 let g:paras[i] = substitute(g:paras[i], '\[', '\[', 'g')768 let g:paras[i] = substitute(g:paras[i], '_', '\_', 'g')769 "let g:paras[i-1] = substitute(g:paras[i-1], '::\s*$', ':', '')770 endif771 endif772 endif773 let i += 1774 endwhile775 " }}}776 " Create auto numbered footnotes database {{{777 let g:autofootnotes = []778 if string(g:ptype) =~ "'autofootnote'"779 let i = 0780 while i < len(g:paras)781 if g:ptype[i] == 'autofootnote'782 let g:autofootnotes += [g:paras[i]]783 endif784 let i += 1785 endwhile786 endif787 " }}}788 " Check and embrace paragraphs in pre tags <pre> (::) {{{789 let i = 0790 while i < len(g:paras)791 " Remove trailing spaces from the end of paragraph. They are meaningless792 " and can cause problems.793 let g:paras[i] = substitute(g:paras[i], '\s\+$', '', '')794 if strpart(g:paras[i], strlen(g:paras[i])-2) == '::' && g:paras[i] !~ '^\s*\.\. [a-zA-Z0-9_-]\+::\s*$' || g:ptype[i] == '2html'795 " For proper embedding of pre into lists I have to set indentation796 " level not to indentation of paragraph (including797 " enumeration/leading character) but indentation of last line.798 let plines = split(g:paras[i], '\n')799 if g:ptype[i] == 'oli'800 " LISTDEF:801 if plines[-1] =~ '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*'802 let initind = strlen(matchstr(plines[-1], '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*\ze'))803 else804 let initind = strlen(matchstr(plines[-1], '^\s*'))805 endif806 elseif g:ptype[i] == 'uli'807 " LISTDEF:808 if plines[-1] =~ '^\s*\zs'.s:vst_bulletdef.'\s*'809 let initind = strlen(matchstr(plines[-1], '^\s*\zs'.s:vst_bulletdef.'\s\+\ze'))810 else811 let initind = strlen(matchstr(plines[-1], '^\s*'))812 endif813 elseif g:ptype[i] == 'dl'814 let initind = strlen(matchstr(plines[-1], '^\s*'))815 elseif g:ptype[i] == 'optlist'816 let initind = strlen(matchstr(plines[-1], '^\s*'))817 elseif g:ptype[i] =~ '^MED'818 if plines[-1] =~ '^\s*\.\. '819 let initind = strlen(matchstr(plines[-1], '^\s*\.\. \ze'))820 else821 let initind = strlen(matchstr(plines[-1], '^\s*'))822 endif823 else824 let initind = g:pindent[i]825 endif826 let j = i + 1827 while j < len(g:paras)828 if initind >= g:pindent[j] || g:ptype[j] == 'notend' || g:ptype[j] == 'blank'829 call insert(g:paras, '</vim:pre>', j)830 call insert(g:pindent, g:pindent[j-1], j)831 call insert(g:ptype, 'prend', j)832 call insert(g:plinen, 0, j)833 834 if g:ptype[i] == '2html'835 let g:paras[i] = VST_FirstLine(g:paras[i])836 let g:paras[i] = substitute(g:paras[i], '\s\+', ' ', 'g')837 let darray = split(g:paras[i], ' ')838 let data = ''839 if len(darray) > 2840 let data .= darray[2]841 if len(darray) > 3842 " Looks strange but need something not likely843 " to occur in colorscheme name and acceptable844 " as class name845 let data .= '----'.darray[3]846 endif847 endif848 let g:paras[i] = ''849 call insert(g:paras, '<vim:pre class="tohtml-'.data.'">', i+1)850 else851 if g:paras[i] =~ '^\s*::\s*$'852 call insert(g:paras, '<vim:pre'.VST_AddClass(i, 1, ' ', '').'>', i+1)853 else854 call insert(g:paras, '<vim:pre>', i+1)855 endif856 endif857 call insert(g:pindent, g:pindent[i+1], i+1)858 call insert(g:ptype, 'prebegin', i+1)859 call insert(g:plinen, 0, i+1)860 861 " Don't allow for checking inside embraced fragment for862 " pre start conditions863 let i = j864 865 break866 else867 if g:ptype[j] == 'anonlink'868 let parlines = split(g:paras[j], '\n')869 for line in parlines870 call filter(g:vst_anonhlinkdb, 'v:val !~ "'.line.'"')871 endfor872 endif873 let g:ptype[j] = 'pre'874 let g:paras[j] = substitute(g:paras[j], '$', '\n', '')875 " In pre paragraphs special characters also have to be876 " escaped.877 let g:paras[j] = VST_SpecCharacter(g:paras[j])878 " Prevent splitting for auto footnotes and hyperlinks or879 " special treatment of backslashes880 let g:paras[j] = substitute(g:paras[j], '`', '\`', 'g')881 let g:paras[j] = substitute(g:paras[j], '\.', '\.', 'g')882 let g:paras[j] = substitute(g:paras[j], '\[', '\[', 'g')883 let g:paras[j] = substitute(g:paras[j], '\\', '\\', 'g')884 let g:paras[j] = substitute(g:paras[j], '_', '\_', 'g')885 let g:paras[j] = substitute(g:paras[j], '|', '\|', 'g')886 887 endif888 let j += 1889 endwhile890 endif891 let i += 1892 endwhile893 " }}}894 " Build databases NOW. {{{895 " For this we have to glue together g:paras,896 " split it along \n and perform other footnote detection actions.897 " But we want to make it only once on first parsing, not inside of tables898 if !exists('b:vst_first_parsing')899 900 " Some actions should be taken only first time when parsing whole file (not in901 " tables cells). Set this variable and unlet it when returning from export902 let b:vst_first_parsing = 1903 904 let fntext = split(join(g:paras, "\n\n"), "\n")905 906 " Create hyperlink and other databases907 call VST_CreateDBs(fntext)908 909 " Check how many numbered footnotes are in file910 let numberedfnotes = filter(copy(fntext), 'v:val =~ "^\\s*\\.\\. \\[\\d\\+\\]"')911 let fnotesnumbers = []912 for line in numberedfnotes913 let fnotesnumbers += [matchstr(line, '^\s*\.\. \[\zs\d\+\ze]')]914 endfor915 let s:maxfnumber = max(fnotesnumbers)916 917 " Check how many labeled footnotes is in file and build labels db918 " Dictionary with key -> text label, value -> number of footnote919 let g:labeledfnotes = filter(copy(fntext), 'v:val =~ "\\[#\\k\\+\\]_"')920 let g:lfnotes = {}921 let k = s:maxfnumber + 1922 let i = 0923 while i < len(g:labeledfnotes)924 let label = matchstr(g:labeledfnotes[i], '\[#\zs\k\+\ze]_')925 let g:lfnotes[label] = k926 let i += 1927 let k += 1928 endwhile929 let s:maxlnumber = len(g:labeledfnotes)930 931 " Build citation database, only list of citation labels:932 let citlabels = filter(copy(fntext), 'v:val =~ "\\[\\k\\+\\]_"')933 let g:clabels = []934 let i = 0935 while i < len(citlabels)936 let g:clabels += [matchstr(citlabels[i], '\[\zs\k\+\ze]_')]937 let i += 1938 endwhile939 940 endif941 " }}}942 " Build replacement database. {{{943 if string(g:ptype) =~ "'replacement'"944 let i = 0945 while i < len(g:paras)946 if g:ptype[i] == 'replacement'947 let from = matchstr(g:paras[i], '^\s*\.\. |\zs.\{-}\ze|')948 let into = matchstr(g:paras[i], '^\s*\.\. |.\{-}|\s\+\zs.*')949 let g:vst_replacedb[from] = into950 endif951 let i += 1952 endwhile953 endif954 " }}} 955 " Detect and create multi element directives (MED) {{{956 let i = 0957 while i < len(g:paras)958 if g:ptype[i] =~ '^MED'959 let firstpar = matchstr(g:paras[i], '^\s*\.\. \w\+::\s*\zs.*')960 " Header of MED {{{961 if g:ptype[i] == 'MED'962 let medtype = matchstr(g:paras[i], '^\s*\.\. \zs\w\+\ze::')963 elseif g:ptype[i] =~ '-footnote$'964 let medtype = 'footnote'965 elseif g:ptype[i] =~ '-figure$'966 let medtype = 'figure'967 elseif g:ptype[i] =~ '-autofootnote$'968 let medtype = 'autofootnote'969 elseif g:ptype[i] =~ '-citation$'970 let medtype = 'citation'971 elseif g:ptype[i] =~ '-class$'972 let medtype = 'class'973 elseif g:ptype[i] =~ '-compound$'974 let medtype = 'compound'975 elseif g:ptype[i] =~ '-comment$'976 let medtype = 'comment'977 elseif g:ptype[i] =~ '-container$'978 let medtype = 'container'979 elseif g:ptype[i] =~ '-labelfootnote$'980 let medtype = 'labelfootnote'981 elseif g:ptype[i] =~ '-pullquote$'982 let medtype = 'pullquote'983 elseif g:ptype[i] =~ '-block$'984 let medtype = 'block'985 elseif g:ptype[i] =~ '-topic$'986 let medtype = 'topic'987 elseif g:ptype[i] =~ '-sidebar$'988 let medtype = 'sidebar'989 elseif g:ptype[i] =~ '-unknown$'990 let medtype = 'unknown'991 endif992 993 let divindent = repeat(' ', g:pindent[i])994 if medtype =~? '\(\<note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)'995 if medtype == 'admonition'996 if firstpar =~ '\n\s*:class:'997 let class = VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*'))998 let name = matchstr(firstpar, '^.*\ze\s*\n')999 else1000 let name = matchstr(firstpar, '^.*\ze\s*$')1001 let class = 'note'1002 endif1003 let g:paras[i] = divindent.'<vim:div class="'.tolower(class).VST_AddClass(i,0,' ','').'">'1004 let title = name1005 let firstpar = ''1006 else1007 let g:paras[i] = divindent.'<vim:div class="'.tolower(medtype).VST_AddClass(i,0,' ','').'">'1008 let title = substitute(tolower(medtype), '^.', '\U\0', '')1009 endif1010 1011 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>'1012 1013 if firstpar != ''1014 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g')1015 let g:paras[i] = g:paras[i]."\n".title.VST_Structure(split(firstpar, "\n"))1016 else1017 let g:paras[i] = g:paras[i]."\n".title."\n"1018 endif1019 1020 let medtype = 'div'1021 1022 elseif medtype == 'figure'1023 " figure MED {{{1024 " supported sub-directives: alt, height, width, scale, align,1025 " target, class, identify, figwidth, figclass1026 let src = ''1027 let width = ''1028 let height = ''1029 let alt = ''1030 let title = ''1031 let identify = ''1032 let scale = ''1033 let target = ''1034 let class = ''1035 let align = ''1036 let figalign = ''1037 let figwidth = ''1038 let figclass = ''1039 let parlines = split(g:paras[i], '\n')1040 for parline in parlines1041 let parline = substitute(parline, '^\s*', '', '')1042 if src == ''1043 let src = matchstr(parline, '\.\. figure::\s*\zs.\{-}\ze\s*$')1044 if !filereadable(escape(src, ' \%#'))1045 let noimage = 11046 let g:vst_error .= "No image: ".src."\n"1047 else1048 let noimage = 01049 endif1050 endif1051 if width == ''1052 let width = matchstr(parline, ':width:\s*\zs.\{-}\ze\s*$')1053 endif1054 if height == ''1055 let height = matchstr(parline, ':height:\s*\zs.\{-}\ze\s*$')1056 endif1057 if alt == ''1058 let alt = matchstr(parline, ':alt:\s*\zs.\{-}\ze\s*$')1059 endif1060 if title == ''1061 let title = matchstr(parline, ':title:\s*\zs.\{-}\ze\s*$')1062 endif1063 if align == ''1064 let align = matchstr(parline, ':align:\s*\zs.\{-}\ze\s*$')1065 endif1066 if figwidth == ''1067 let figwidth = matchstr(parline, ':figwidth:\s*\zs.\{-}\ze\s*$')1068 endif1069 if figclass == ''1070 let figclass = matchstr(parline, ':figclass:\s*\zs.\{-}\ze\s*$')1071 endif1072 if figalign == ''1073 let figalign = matchstr(parline, ':figalign:\s*\zs.\{-}\ze\s*$')1074 endif1075 if scale == ''1076 let scale = matchstr(parline, ':scale:\s*\zs.\{-}\ze\s*$')1077 if scale =~ '\D'1078 let scale = ''1079 endif1080 endif1081 if target == ''1082 let target = matchstr(parline, ':target:\s*\zs.\{-}\ze\s*$')1083 if target == 'self' && src != ''1084 let target = src1085 endif1086 while target =~ '_\s*$'1087 let title = matchstr(target, '^\s*\(`\?\)\zs.*\ze\1_\s*$')1088 " If ends in _ it is probably indirect link, process it1089 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != ''1090 let target = escape(g:vst_hlinkdb[title], '&\~')1091 else1092 let target = '#l'.tolower(VST_IdMaker(title))1093 endif1094 endwhile1095 endif1096 if class == ''1097 let class = matchstr(parline, ':class:\s*\zs.\{-}\ze\s*$')1098 endif1099 if identify == ''1100 let identify = matchstr(parline, ':identify:')1101 if identify != ''1102 if executable('identify') && noimage == 01103 let [width, height] = VST_IdentifyImage(src, parline)1104 else1105 let [width, height] = ['', '']1106 endif1107 endif1108 endif1109 endfor1110 1111 if src != ''1112 let src = 'src="'.VST_ProtectLiteral(src).'"'1113 endif1114 if scale != ''1115 if width != ''1116 let width = width*scale/1001117 endif1118 if height != ''1119 let height = height*scale/1001120 endif1121 endif1122 if width != ''1123 let width = 'width="'.width.'"'1124 endif1125 if height != ''1126 let height = 'height="'.height.'"'1127 endif1128 if alt != ''1129 let alt = 'alt="'.alt.'"'1130 endif1131 if title != ''1132 let title = 'title="'.title.'"'1133 endif1134 " reST compatibility, if there is no figalign option but align1135 " is defined it is probably reST document not supporting1136 " figalign.1137 if figalign == '' && align != ''1138 let figalign = align1139 let align = ''1140 endif1141 if class != ''1142 if align == ''1143 let class = 'class="'.class.'"'1144 else1145 let class = 'class="'.class.' vst'.align.'"'1146 endif1147 else1148 if align == ''1149 let class = ''1150 else1151 let class = 'class="vst'.align.'"'1152 endif1153 endif1154 if target != ''1155 if target =~ '_\s*$'1156 let address = matchstr(VST_Hyperlink(target), '^.\{-}>\ze')1157 else1158 let address = '<vim:a href="'.VST_ProtectLiteral(target).'">'1159 endif1160 let imagepart = address."\n<vim:img ".src.' '.width.' '.height.' '.class.' '.alt.' '.title." />\n</vim:a>"1161 else1162 let imagepart = "\n<vim:img ".src.' '.width.' '.height.' '.class.' '.alt.' '.title." />\n"1163 endif1164 1165 if figclass != ''1166 if figalign == ''1167 let figclass = 'class="'.figclass.'"'1168 else1169 let figclass = 'class="'.figclass.' vst'.figalign.'"'1170 endif1171 else1172 if figalign == ''1173 let figclass = 'class="figure"'1174 else1175 let figclass = 'class="figure vst'.figalign.'"'1176 endif1177 endif1178 1179 if figwidth != ''1180 if figwidth == 'image'1181 if exists('width')1182 let figw = matchstr(width, '\d\+')1183 let figwidth = 'style="width:'.figw.'px"'1184 endif1185 else1186 let figwidth = 'style="width:'.figwidth.'px"'1187 endif1188 endif1189 let g:paras[i] = divindent.'<vim:figure '.figclass.' '.figwidth.">\n".divindent.imagepart1190 " }}}1191 elseif medtype == 'footnote'1192 " Footnote \[\d\+\] {{{1193 let g:paras[i] = VST_SpecCharacter(g:paras[i])1194 let indent = repeat(' ', g:pindent[i])1195 let g:paras[i] =1196 \ substitute(g:paras[i], '^\s*\.\. \[\(\d\+\)\]', indent.'<vim:footnote>\n'.indent.'<vim:div class="fnumber"><vim:a href="#target-\1" name="footnote-\1">[\1]</vim:a></vim:div>\n'.indent.'<vim:div class="ftext">', '')1197 let firstpar = matchstr(g:paras[i], '<vim:div class="ftext">\zs.*')1198 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g')1199 let firstpar = VST_Structure(split(firstpar, "\n"))1200 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ftext">\zs.*', '', '')1201 let g:paras[i] .= firstpar1202 " }}}1203 elseif medtype == 'autofootnote'1204 " Footnote \[#\] {{{1205 let g:paras[i] = VST_SpecCharacter(g:paras[i])1206 let indent = repeat(' ', g:pindent[i])1207 if !exists('b:vst_afs')1208 let g:autofnote = s:maxfnumber + s:maxlnumber + 11209 let b:vst_afs = 11210 endif1211 let k = g:autofnote1212 let g:paras[i] =1213 \ substitute(g:paras[i], '^\s*\.\. \[#\]', indent.'<vim:footnote>\n'.indent.'<vim:div class="fnumber"><vim:a href="#target-'.k.'" name="footnote-'.k.'">['.k.']</vim:a></vim:div>\n'.indent.'<vim:div class="ftext">', '')1214 let firstpar = matchstr(g:paras[i], '<vim:div class="ftext">\zs.*')1215 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g')1216 let firstpar = VST_Structure(split(firstpar, "\n"))1217 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ftext">\zs.*', '', '')1218 let g:paras[i] .= firstpar1219 let g:autofnote += 11220 let medtype = 'footnote'1221 " }}}1222 elseif medtype == 'labelfootnote'1223 " Footnote \[#\k\+\] {{{1224 let g:paras[i] = VST_SpecCharacter(g:paras[i])1225 let indent = repeat(' ', g:pindent[i])1226 let label = matchstr(g:paras[i], '^\s*\.\. \[#\zs\k\+\ze\]')1227 let k = g:lfnotes[label]1228 let g:paras[i] =1229 \ substitute(g:paras[i], '^\s*\.\. \[#\k\+\]', indent.'<vim:footnote>\n'.indent.'<vim:div class="fnumber"><vim:a href="#target-'.k.'" name="footnote-'.k.'">['.k.']</vim:a></vim:div>\n'.indent.'<vim:div class="ftext">', '')1230 let firstpar = matchstr(g:paras[i], '<vim:div class="ftext">\zs.*')1231 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g')1232 let firstpar = VST_Structure(split(firstpar, "\n"))1233 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ftext">\zs.*', '', '')1234 let g:paras[i] .= firstpar1235 let medtype = 'footnote'1236 " }}}1237 elseif medtype == 'citation'1238 " Citation \[\k\+\] {{{1239 let g:paras[i] = VST_SpecCharacter(g:paras[i])1240 let indent = repeat(' ', g:pindent[i])1241 let label = matchstr(g:paras[i], '^\s*\.\. \[\zs\k\+\ze\]')1242 let g:paras[i] =1243 \ substitute(g:paras[i], '^\s*\.\. \[\k\+\]', indent.'<vim:citation>\n'.indent.'<vim:div class="cnumber"><vim:a href="#ctarget-'.label.'" name="citation-'.label.'">['.label.']</vim:a></vim:div>\n'.indent.'<vim:div class="ctext">', '')1244 let firstpar = matchstr(g:paras[i], '<vim:div class="ctext">\zs.*')1245 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g')1246 let firstpar = VST_Structure(split(firstpar, "\n"))1247 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ctext">\zs.*', '', '')1248 let g:paras[i] .= firstpar1249 " }}}1250 elseif medtype == 'class'1251 " Multi element class {{{1252 " We don't need to change content of par, it is purely virtual MED1253 let classname = matchstr(g:paras[i], '^\s*\.\. class::\s*\zs.*\ze\s*$')1254 let g:paras[i] = VST_IdMaker(classname)1255 let indent = repeat(' ', g:pindent[i])1256 " }}}1257 elseif medtype == 'comment'1258 " Multi element comment {{{1259 let indent = repeat(' ', g:pindent[i])1260 let g:paras[i] = '<vim:comment>'.g:paras[i]1261 " }}}1262 elseif medtype == 'compound'1263 " Multi element compound {{{1264 let indent = repeat(' ', g:pindent[i])1265 if firstpar =~ '\n\s*:class:'1266 let class = 'vstcompound '.VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*\(\n\|$\)'))1267 else1268 let class = 'vstcompound'1269 endif1270 let g:paras[i] = indent.'<vim:block id="id-'.i.'" class="'.tolower(class).'">'1271 let g:vst_containers += [tolower(class)]1272 1273 let medtype = 'block'1274 1275 " }}}1276 elseif medtype == 'container'1277 " Multi line div {{{1278 let indent = repeat(' ', g:pindent[i])1279 let class = matchstr(g:paras[i], '^\s*\.\. container::\s*\zs.*\ze\s*')1280 let class = VST_IdMaker(class)1281 let g:paras[i] = indent.'<vim:container id="id-'.i.'" class="'.tolower(class).'">'1282 let g:vst_containers += [tolower(class)]1283 " }}}1284 elseif medtype == 'topic'1285 " Multi element topic {{{1286 let indent = repeat(' ', g:pindent[i])1287 if firstpar =~ '\n\s*:class:'1288 let class = 'topic '.VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*'))1289 let name = matchstr(firstpar, '^.*\ze\s*\n')1290 else1291 let name = matchstr(firstpar, '^.*\ze\s*$')1292 let class = 'topic'1293 endif1294 let g:paras[i] = divindent.'<vim:topic class="'.tolower(class).'">'1295 let title = name1296 if title != ''1297 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>'1298 else1299 let title = ''1300 endif1301 let firstpar = ''1302 1303 let g:paras[i] .= "\n".title1304 " }}}1305 elseif medtype == 'sidebar'1306 " Multi element sidebar {{{1307 let indent = repeat(' ', g:pindent[i])1308 if firstpar =~ '\n\s*:class:'1309 let class = 'vstsidebar '.VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*\(\n\|$\)'))1310 else1311 let class = 'vstsidebar'1312 endif1313 let name = matchstr(firstpar, '^.*\ze\s*\n')1314 if firstpar =~ ':subtitle:'1315 let subtitle = matchstr(firstpar, ':subtitle:\s*\zs.\{-}\ze\s*\(\n\|$\)')1316 else1317 let subtitle = ''1318 endif1319 let g:paras[i] = divindent.'<vim:sidebar class="'.tolower(class).'">'1320 let title = name1321 if title != ''1322 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>'1323 else1324 let title = ''1325 endif1326 1327 if subtitle != ''1328 let title .= "\n".'<vim:p class="notesubtitle">'.subtitle.'</vim:p>'1329 endif1330 let firstpar = ''1331 1332 let g:paras[i] .= "\n".title1333 " }}}1334 elseif medtype == 'block'1335 " Multi line div {{{1336 let indent = repeat(' ', g:pindent[i])1337 let class = matchstr(g:paras[i], '^\s*\.\. block::\s*\zs.*\ze\s*')1338 let class = VST_IdMaker(class)1339 let g:paras[i] = indent.'<vim:block id="id-'.i.'" class="'.tolower(class).'">'1340 let g:vst_containers += [tolower(class)]1341 " }}}1342 elseif medtype == 'pullquote'1343 " Bigger blockquote {{{1344 let g:paras[i] = VST_SpecCharacter(g:paras[i])1345 let indent = repeat(' ', g:pindent[i])1346 let g:paras[i] =1347 \ substitute(g:paras[i], '^\s*\.\. pull-quote::', indent.'<vim:pullquote'.VST_AddClass(i,1,' ','').'>', '')1348 " }}}1349 elseif medtype == 'unknown'1350 " Unknown multi element div {{{1351 let indent = repeat(' ', g:pindent[i])1352 let g:paras[i] = indent.'<vim:unknown>'.g:paras[i]1353 " }}}1354 else1355 let g:paras[i] = divindent.'<vim:div class="note">'1356 let title = 'Unknown'1357 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>'1358 if firstpar != ''1359 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '', 'g')1360 let g:paras[i] = g:paras[i]."\n".title.VST_Structure(split(firstpar, "\n"))1361 else1362 let g:paras[i] = g:paras[i]."\n".title."\n"1363 endif1364 endif1365 1366 " }}}1367 let j = i + 11368 while j < len(g:paras)1369 let noteindent = g:pindent[j] - g:pindent[i]1370 if g:pindent[i] >= g:pindent[j] || g:ptype[j] == 'notend' || g:ptype[j] == 'blank'1371 if medtype =~ 'footnote\|citation'1372 call insert(g:paras, repeat(' ', g:pindent[j]).'</vim:div></vim:'.medtype.'>', j)1373 elseif medtype == 'class'1374 if j - i == 11375 call insert(g:paras, repeat(' ', g:pindent[j]).'', j)1376 else1377 call insert(g:paras, repeat(' ', g:pindent[j]).'<vim:class'.classname.' />', j)1378 endif1379 else1380 call insert(g:paras, repeat(' ', g:pindent[j]).'</vim:'.medtype.'>', j)1381 endif1382 call insert(g:pindent, g:pindent[i], j)1383 "call insert(g:pindent, g:pindent[j-1], j)1384 call insert(g:ptype, 'notend', j)1385 call insert(g:plinen, 0, j)1386 break1387 else1388 "if g:pindent[j] == noteindent1389 if g:ptype[j] == 'blockquote' && g:pindent[j] == noteindent1390 let g:ptype[j] = 'p'1391 endif1392 endif1393 let j += 11394 endwhile1395 1396 endif1397 let i += 11398 endwhile1399 " }}}1400 " Detect and create transitions (<hr>) {{{1401 let i = 01402 for par in g:paras1403 if i < len(g:paras)1404 if g:paras[i] !~ '\n' && g:paras[i] =~ '^\s*'.s:vst_headdef.'\s*$'1405 if g:ptype[i] !~ '^pre'1406 let g:ptype[i] = 'hr'1407 let class = VST_AddClass(i, 1, '', '')1408 let g:paras[i] = substitute(g:paras[i], '.*', '\n<vim:hr '.class.'/>\n', '')1409 endif1410 endif1411 endif1412 let i += 11413 endfor1414 " }}}1415 " Detect blockquote paragraphs {{{1416 let i = 01417 while i < len(g:paras)1418 if g:ptype[i] == 'p' && g:pindent[i] > g:pindent[i-1]1419 if g:ptype[i] !~ '^pre' && g:ptype[i-1] !~ '^MED' && g:ptype[i-1] !~ 'optlist'1420 let g:ptype[i] = 'blockquote'1421 endif1422 if g:ptype[i-1] =~ '^MED' && g:pindent[i] > g:pindent[i-1] + 31423 let g:ptype[i] = 'blockquote'1424 endif1425 endif1426 let i += 11427 endwhile1428 " }}}1429 " Detect if par is a header (<hx>) {{{1430 let i = 01431 let h1 = ''1432 let h2 = ''1433 let h3 = ''1434 let h4 = ''1435 let h5 = ''1436 while i < len(g:paras)1437 if g:ptype[i] !~ '^pre'1438 if g:paras[i] =~ '\n\s*'.s:vst_headdef.'\s*\(\n\|$\)' && g:ptype[i] !~ 'table' && g:paras[i] !~ 'vim:comment'1439 let parlines = split(g:paras[i], '\n')1440 if parlines[1] =~ '^\s*'.s:vst_headdef.'\s*$'1441 let double = ' '1442 elseif parlines[0] == parlines[2] && parlines[0] =~ '^\s*'.s:vst_headdef.'\s*$'1443 let double = 'd'1444 call remove(parlines, 0)1445 endif1446 let lchar = matchstr(parlines[1], '.\ze\s*$').double1447 if lchar =~ s:vst_headchars1448 if h1 == '' || lchar == h11449 let h1 = lchar1450 let g:ptype[i] = 'h1'1451 elseif h2 == '' || lchar == h21452 let h2 = lchar1453 let g:ptype[i] = 'h2'1454 elseif h3 == '' || lchar == h31455 let h3 = lchar1456 let g:ptype[i] = 'h3'1457 elseif h4 == '' || lchar == h41458 let h4 = lchar1459 let g:ptype[i] = 'h4'1460 elseif h5 == '' || lchar == h51461 let h5 = lchar1462 let g:ptype[i] = 'h5'1463 else1464 let g:ptype[i] = 'h6'1465 endif1466 let modlchar = substitute(lchar, '[d ]', '', 'g')1467 let g:vst_headers[g:ptype[i]] = repeat(modlchar, 9).double1468 1469 if len(parlines) > 21470 let g:paras[i] = join(parlines[0:1], "\n")1471 call insert(g:paras, join(parlines[2:], "\n"), i+1)1472 call insert(g:pindent, g:pindent[i], i+1)1473 call insert(g:plinen, 0, i+1)1474 1475 if parlines[2] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s'1476 " LISTDEF:1477 call insert(g:ptype, 'oli', i+1)1478 elseif parlines[2] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s'1479 " LISTDEF:1480 call insert(g:ptype, 'oli', i+1)1481 elseif parlines[2] =~ '^\s*'.s:vst_bulletdef.'\s'1482 call insert(g:ptype, 'uli', i+1)1483 elseif parlines[2] =~ '^\s*:.\{-1,}:\(\s\+\|$\)'1484 call insert(g:ptype, 'field', i+1)1485 elseif parlines[2] =~ '^\s*::\s*$'1486 call insert(g:ptype, 'emptypre', i+1)1487 elseif parlines[2] =~ '^\s*| '1488 call insert(g:ptype, 'verse', i+1)1489 elseif parlines[2] =~ '^\s*+-\{3,}'1490 call insert(g:ptype, 'table', i+1)1491 elseif parlines[2] =~ '^\s*+=\{3,}'1492 call insert(g:ptype, 'bltable', i+1)1493 elseif parlines[2] =~ '^\s*\(--\|-\|/\|:\|+\)\S.\{-}\( \|$\)' && doc[line] !~ '^\s*\(--\s\|:\S\+:`\)'1494 call insert(g:ptype, 'optlist', i+1)1495 elseif parlines[2] =~ '^\s*>>>'1496 call insert(g:ptype, 'doctest', i+1)1497 elseif parlines[2] =~ '^\s*=\{2,}\s\+=\{2,}'1498 call insert(g:ptype, 'simpletbl', i+1)1499 else1500 " Everything after ornament put into next1501 " paragraph sub type. Ugly but prevents worse1502 " things.1503 call insert(g:ptype, 'sub'.g:ptype[i], i+1)1504 endif1505 else1506 let g:paras[i] = join(parlines, "\n")1507 endif1508 endif1509 endif1510 endif1511 let i += 11512 endwhile1513 " }}}426 " Initiate arrays and variables {{{ 427 let ltype = [] 428 let lindent = [] 429 430 if !exists("g:vst_recursion") 431 let g:vst_recursion = 0 432 else 433 let g:vst_recursion += 1 434 endif 435 436 if exists("g:paras") 437 let g:paras_rez += [g:paras] 438 let g:paras = [] 439 else 440 let g:paras_rez = [] 441 let g:paras = [] 442 endif 443 if exists("g:ptype") 444 let g:ptype_rez += [g:ptype] 445 let g:ptype = [] 446 else 447 let g:ptype_rez = [] 448 let g:ptype = [] 449 endif 450 if exists("g:pindent") 451 let g:pindent_rez += [g:pindent] 452 let g:pindent = [] 453 else 454 let g:pindent_rez = [] 455 let g:pindent = [] 456 endif 457 if exists("g:plinen") 458 let g:plinen_rez += [g:plinen] 459 let g:plinen = [] 460 else 461 let g:plinen_rez = [] 462 let g:plinen = [] 463 endif 464 465 let toc = '' 466 " }}} 467 " Detect and create line types {{{ 468 let lendoc = len(doc) 469 for line in range(lendoc) 470 if line == lendoc - 1 471 let nextline = line - 1 472 else 473 let nextline = line + 1 474 endif 475 if doc[line] =~ '^\s*$' 476 let ltype += ['blank'] 477 elseif doc[line] =~ '^\s*\.\. _.*:\s*$' 478 let ltype += ['intlink'] 479 elseif doc[line] =~ '^\s*\.\. __:' 480 let ltype += ['anonlink'] 481 elseif doc[line] =~ '^\s*__' 482 let ltype += ['anonlink'] 483 elseif doc[line] =~ '^\s*\.\. _' 484 let ltype += ['link'] 485 elseif doc[line] =~ '^\s*\.\. image::' 486 let ltype += ['img'] 487 elseif doc[line] =~? '^\s*\.\. \(note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)::' 488 let ltype += ['MED'] 489 elseif doc[line] =~? '^\s*\.\. figure::' 490 let ltype += ['MED-figure'] 491 elseif doc[line] =~ '^\s*\.\. \[\d\+\]' 492 let ltype += ['MED-footnote'] 493 elseif doc[line] =~ '^\s*\.\. \[#\]' 494 let ltype += ['MED-autofootnote'] 495 elseif doc[line] =~ '^\s*\.\. \[#\k\+\]' 496 let ltype += ['MED-labelfootnote'] 497 elseif doc[line] =~ '^\s*\.\. \[\k\+\]' 498 let ltype += ['MED-citation'] 499 elseif doc[line] =~ '^\s*\.\. pull-quote::' 500 let ltype += ['MED-pullquote'] 501 elseif doc[line] =~ '^\s*\.\. block::' 502 let ltype += ['MED-block'] 503 elseif doc[line] =~ '^\s*\.\. container::' 504 let ltype += ['MED-container'] 505 elseif doc[line] =~ '^\s*\.\. topic::' 506 let ltype += ['MED-topic'] 507 elseif doc[line] =~ '^\s*\.\. sidebar::' 508 let ltype += ['MED-sidebar'] 509 elseif doc[line] =~ '^\s*\.\. compound::' 510 let ltype += ['MED-compound'] 511 elseif doc[line] =~ '^\s*\.\. class::' 512 let ltype += ['MED-class'] 513 elseif doc[line] =~ '^\s*\.\. raw::\s*\(la\)\?tex\s\+html' 514 let ltype += ['rawboth'] 515 elseif doc[line] =~ '^\s*\.\. raw::\s*html\s\+\(la\)\?tex' 516 let ltype += ['rawboth'] 517 elseif doc[line] =~ '^\s*\.\. raw::\s*\(la\)\?tex' 518 let ltype += ['rawlatex'] 519 elseif doc[line] =~ '^\s*\.\. raw::\s*html' 520 let ltype += ['rawhtml'] 521 elseif doc[line] =~ '^\s*\.\. role::' 522 let ltype += ['role'] 523 elseif doc[line] =~ '^\s*\.\. default-role::' 524 let ltype += ['defaultr'] 525 elseif doc[line] =~ '^\s*\.\. latexonly::' 526 let ltype += ['latexonly'] 527 elseif doc[line] =~ '^\s*\.\. htmlonly::' 528 let ltype += ['htmlonly'] 529 elseif doc[line] =~ '^\s*\.\. contents::\s*:local' 530 let ltype += ['empty'] 531 elseif doc[line] =~ '^\s*\.\. contents::' 532 let ltype += ['toc'] 533 elseif doc[line] =~ '^\s*\.\. comment::' 534 let ltype += ['comment'] 535 elseif doc[line] =~ '^\s*\.\. title::' 536 let ltype += ['title'] 537 elseif doc[line] =~ '^\s*\.\. rubric::' 538 let ltype += ['rubric'] 539 elseif doc[line] =~ '^\s*\.\. 2html::' 540 let ltype += ['2html'] 541 elseif doc[line] =~ '^\s*\.\. meta::' 542 let ltype += ['meta'] 543 elseif doc[line] =~ '^\s*\.\. |' 544 let ltype += ['replacement'] 545 elseif doc[line] =~ '^\s*\.\. [a-zA-Z-]\+::' && doc[line] !~ 'header\|footer' 546 " Unknown directives treated as pre 547 " it doesn't cover contents of these paragraphs, they are 548 " processed normally. 549 let ltype += ['MED-unknown'] 550 elseif doc[line] =~ '^\s*\.\.\(\s\|$\)' 551 " Everything else beginning with double dot will be treated as 552 " comment and completely removed from output. If you want to only 553 " hid this use one doc[line] comments 554 let ltype += ['MED-comment'] 555 elseif doc[line] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s' 556 " LISTDEF: enum embraced in parenthesis 557 let cind = len(matchstr(doc[line], '^\s*')) 558 let nind = len(matchstr(doc[nextline], '^\s*')) 559 if nind > cind 560 let ltype += ['oli'] 561 elseif nind == cind && doc[nextline] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s' 562 let ltype += ['oli'] 563 elseif doc[nextline] =~ '^\s*$' 564 let ltype += ['oli'] 565 else 566 let ltype += ['p'] 567 endif 568 elseif doc[line] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s' 569 " LISTDEF: 570 let cind = len(matchstr(doc[line], '^\s*')) 571 let nind = len(matchstr(doc[nextline], '^\s*')) 572 if nind > cind 573 let ltype += ['oli'] 574 elseif nind == cind && doc[nextline] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s' 575 let ltype += ['oli'] 576 elseif doc[nextline] =~ '^\s*$' 577 let ltype += ['oli'] 578 else 579 let ltype += ['p'] 580 endif 581 elseif doc[line] =~ '^\s*'.s:vst_bulletdef.'\s' 582 " LISTDEF: 583 let cind = len(matchstr(doc[line], '^\s*')) 584 let nind = len(matchstr(doc[nextline], '^\s*')) 585 if nind > cind 586 let ltype += ['uli'] 587 elseif nind == cind && doc[nextline] =~ '^\s*'.s:vst_bulletdef.'\s' 588 let ltype += ['uli'] 589 elseif doc[nextline] =~ '^\s*$' 590 let ltype += ['uli'] 591 else 592 let ltype += ['p'] 593 endif 594 elseif doc[line] =~ '^\s*:.\{-1,}:\(\s\+\|$\)' 595 let ltype += ['field'] 596 elseif doc[line] =~ '^\s*::\s*$' 597 let ltype += ['emptypre'] 598 elseif doc[line] =~ '^\s*| ' 599 let ltype += ['verse'] 600 elseif doc[line] =~ '^\s*+-\{3,}' 601 let ltype += ['table'] 602 elseif doc[line] =~ '^\s*+=\{3,}' 603 let ltype += ['bltable'] 604 elseif doc[line] =~ '^\s*\(--\|-\|/\|:\|+\)\S.\{-}\( \|$\)' && doc[line] !~ '^\s*\(--\s\|:\S\+:`\)' 605 if lendoc == 1 606 let ltype += ['p'] 607 else 608 let ltype += ['optlist'] 609 endif 610 elseif doc[line] =~ '^\s*>>>' 611 let ltype += ['doctest'] 612 elseif doc[line] =~ '^\s*=\{2,}\s\+=\{2,}' 613 let ltype += ['simpletbl'] 614 else 615 let ltype += ['p'] 616 " Remove backslash escaping special meaning for verse paragraphs 617 let doc[line] = substitute(doc[line], '^\(\s*\)\\|', '\1|', '') 618 endif 619 " Check indentation of each doc[line] 620 let lindent += [strlen(matchstr(doc[line], '^\s*'))] 621 endfor 622 " }}} 623 " Create false 'blank' line number 0 to make looping easier. {{{ 624 call insert(ltype, 'blank') 625 call insert(lindent, 0) 626 call insert(doc, '') 627 " Create false 'blank' line to the end 628 call add(ltype, 'blank') 629 call add(lindent, 0) 630 call add(doc, '') 631 " }}} 632 " Create paragraphs from line types {{{ 633 " 634 let i = 0 635 let parcounter = -1 636 for line in doc 637 if ltype[i] == 'blank' 638 let i += 1 639 continue 640 else 641 if ltype[i-1] == 'blank' 642 let parcounter += 1 643 let g:paras += [doc[i]] 644 let g:ptype += [ltype[i]] 645 let g:pindent += [lindent[i]] 646 let g:plinen += [g:vst_reallines[i]] 647 else 648 let g:paras[parcounter] .= "\n".doc[i] 649 endif 650 endif 651 652 let i += 1 653 endfor 654 " }}} 655 " Create false 'blank' para number 0 to make looping easier. {{{ 656 call insert(g:ptype, 'blank') 657 call insert(g:pindent, 0) 658 call insert(g:paras, '') 659 call insert(g:plinen, 0) 660 " Create false 'blank' para on the end 661 call add(g:ptype, 'blank') 662 call add(g:pindent, 0) 663 call add(g:paras, '') 664 call add(g:plinen, 0) 665 " }}} 666 " Loop through paragraphs to concatenate simple tables. {{{ 667 if string(g:ptype) =~ "'simpletbl'" 668 let i = 0 669 while i < len(g:paras) 670 if g:ptype[i] == 'simpletbl' 671 " Check if last line matches simple table syntax 672 if g:paras[i] !~ '\n\s*=\{2,}\(\s\+=\{2,}\)\+\s*$' && i < len(g:paras)-1 673 let g:paras[i] = g:paras[i]."\n\n".g:paras[i+1] 674 " Remove elements from appropriate tables 675 call remove(g:paras, i+1) 676 call remove(g:pindent, i+1) 677 call remove(g:ptype, i+1) 678 call remove(g:plinen, i+1) 679 let i -= 1 680 endif 681 endif 682 let i += 1 683 endwhile 684 endif 685 " }}} 686 " Loop through empty paragraphs to make them really empty. {{{ 687 if string(g:ptype) =~ "'empty'" 688 let i = 0 689 while i < len(g:paras) 690 if g:ptype[i] == 'empty' 691 let g:paras[i] = '' 692 endif 693 let i += 1 694 endwhile 695 endif 696 " }}} 697 " Loop through rawlatex paragraphs correct next paragraphs. {{{ 698 if string(g:ptype) =~ "'rawlatex'" 699 let i = 0 700 while i < len(g:paras) 701 if g:ptype[i] == 'rawlatex' 702 if g:pindent[i+1] > g:pindent[i] 703 let g:ptype[i+1] = 'rawlatexcontent' 704 endif 705 endif 706 let i += 1 707 endwhile 708 endif 709 " }}} 710 " Loop through rawboth paragraphs correct next paragraphs. {{{ 711 if string(g:ptype) =~ "'rawboth'" 712 let i = 0 713 while i < len(g:paras) 714 if g:ptype[i] == 'rawboth' 715 if g:pindent[i+1] > g:pindent[i] 716 let g:ptype[i+1] = 'rawbothcontent' 717 endif 718 endif 719 let i += 1 720 endwhile 721 endif 722 " }}} 723 " Loop through rawhtml paragraphs correct next paragraphs. {{{ 724 if string(g:ptype) =~ "'rawhtml'" 725 let i = 0 726 while i < len(g:paras) 727 if g:ptype[i] == 'rawhtml' 728 if g:pindent[i+1] > g:pindent[i] 729 let g:ptype[i+1] = 'rawhtmlcontent' 730 endif 731 endif 732 let i += 1 733 endwhile 734 endif 735 " }}} 736 " Loop through p paragraphs to sort out additional types (dl). {{{ 737 let i = 0 738 while i < len(g:paras) 739 if g:ptype[i] == 'p' 740 let parlines = split(g:paras[i], '\n') 741 if len(parlines) > 1 && g:paras[i] !~ '^\s*--\?' 742 let dlpindent1 = strlen(matchstr(parlines[0], '^\s*')) 743 let dlpindent2 = strlen(matchstr(parlines[1], '^\s*')) 744 if dlpindent2 > dlpindent1 745 let g:ptype[i] = 'dl' 746 endif 747 endif 748 endif 749 let i += 1 750 endwhile 751 " }}} 752 " Loop through paragraphs to sort out prequoted type. {{{ 753 " This par type could be catched only in second par, so we don't have to 754 " start from 0 755 let i = 1 756 while i < len(g:paras) 757 if g:ptype[i] == 'p' || g:ptype[i] == 'verse' || g:ptype[i] =~ 'li' 758 if g:paras[i] =~ "^\\s*[][<>!:;=|()\"#%'*+$\&,./\?@^_`{}\~-]" 759 if g:paras[i-1] =~ '::\s*$' && g:paras[i-1] !~ '^\s*\.\. \w\+::\s*$' && g:pindent[i] == g:pindent[i-1] 760 if g:ptype[i] == 'anonlink' 761 let parlines = split(g:paras[i], '\n') 762 for line in parlines 763 call filter(g:vst_anonhlinkdb, 'v:val !~ "'.line.'"') 764 endfor 765 endif 766 let g:ptype[i] = 'prequoted' 767 let g:paras[i] = substitute(g:paras[i], '\[', '\[', 'g') 768 let g:paras[i] = substitute(g:paras[i], '_', '\_', 'g') 769 "let g:paras[i-1] = substitute(g:paras[i-1], '::\s*$', ':', '') 770 endif 771 endif 772 endif 773 let i += 1 774 endwhile 775 " }}} 776 " Create auto numbered footnotes database {{{ 777 let g:autofootnotes = [] 778 if string(g:ptype) =~ "'autofootnote'" 779 let i = 0 780 while i < len(g:paras) 781 if g:ptype[i] == 'autofootnote' 782 let g:autofootnotes += [g:paras[i]] 783 endif 784 let i += 1 785 endwhile 786 endif 787 " }}} 788 " Check and embrace paragraphs in pre tags <pre> (::) {{{ 789 let i = 0 790 while i < len(g:paras) 791 " Remove trailing spaces from the end of paragraph. They are meaningless 792 " and can cause problems. 793 let g:paras[i] = substitute(g:paras[i], '\s\+$', '', '') 794 if strpart(g:paras[i], strlen(g:paras[i])-2) == '::' && g:paras[i] !~ '^\s*\.\. [a-zA-Z0-9_-]\+::\s*$' || g:ptype[i] == '2html' 795 " For proper embedding of pre into lists I have to set indentation 796 " level not to indentation of paragraph (including 797 " enumeration/leading character) but indentation of last line. 798 let plines = split(g:paras[i], '\n') 799 if g:ptype[i] == 'oli' 800 " LISTDEF: 801 if plines[-1] =~ '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*' 802 let initind = strlen(matchstr(plines[-1], '^\s*(\?\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*\ze')) 803 else 804 let initind = strlen(matchstr(plines[-1], '^\s*')) 805 endif 806 elseif g:ptype[i] == 'uli' 807 " LISTDEF: 808 if plines[-1] =~ '^\s*\zs'.s:vst_bulletdef.'\s*' 809 let initind = strlen(matchstr(plines[-1], '^\s*\zs'.s:vst_bulletdef.'\s\+\ze')) 810 else 811 let initind = strlen(matchstr(plines[-1], '^\s*')) 812 endif 813 elseif g:ptype[i] == 'dl' 814 let initind = strlen(matchstr(plines[-1], '^\s*')) 815 elseif g:ptype[i] == 'optlist' 816 let initind = strlen(matchstr(plines[-1], '^\s*')) 817 elseif g:ptype[i] =~ '^MED' 818 if plines[-1] =~ '^\s*\.\. ' 819 let initind = strlen(matchstr(plines[-1], '^\s*\.\. \ze')) 820 else 821 let initind = strlen(matchstr(plines[-1], '^\s*')) 822 endif 823 else 824 let initind = g:pindent[i] 825 endif 826 let j = i + 1 827 while j < len(g:paras) 828 if initind >= g:pindent[j] || g:ptype[j] == 'notend' || g:ptype[j] == 'blank' 829 call insert(g:paras, '</vim:pre>', j) 830 call insert(g:pindent, g:pindent[j-1], j) 831 call insert(g:ptype, 'prend', j) 832 call insert(g:plinen, 0, j) 833 834 if g:ptype[i] == '2html' 835 let g:paras[i] = VST_FirstLine(g:paras[i]) 836 let g:paras[i] = substitute(g:paras[i], '\s\+', ' ', 'g') 837 let darray = split(g:paras[i], ' ') 838 let data = '' 839 if len(darray) > 2 840 let data .= darray[2] 841 if len(darray) > 3 842 " Looks strange but need something not likely 843 " to occur in colorscheme name and acceptable 844 " as class name 845 let data .= '----'.darray[3] 846 endif 847 endif 848 let g:paras[i] = '' 849 call insert(g:paras, '<vim:pre class="tohtml-'.data.'">', i+1) 850 else 851 if g:paras[i] =~ '^\s*::\s*$' 852 call insert(g:paras, '<vim:pre'.VST_AddClass(i, 1, ' ', '').'>', i+1) 853 else 854 call insert(g:paras, '<vim:pre>', i+1) 855 endif 856 endif 857 call insert(g:pindent, g:pindent[i+1], i+1) 858 call insert(g:ptype, 'prebegin', i+1) 859 call insert(g:plinen, 0, i+1) 860 861 " Don't allow for checking inside embraced fragment for 862 " pre start conditions 863 let i = j 864 865 break 866 else 867 if g:ptype[j] == 'anonlink' 868 let parlines = split(g:paras[j], '\n') 869 for line in parlines 870 call filter(g:vst_anonhlinkdb, 'v:val !~ "'.line.'"') 871 endfor 872 endif 873 let g:ptype[j] = 'pre' 874 let g:paras[j] = substitute(g:paras[j], '$', '\n', '') 875 " In pre paragraphs special characters also have to be 876 " escaped. 877 let g:paras[j] = VST_SpecCharacter(g:paras[j]) 878 " Prevent splitting for auto footnotes and hyperlinks or 879 " special treatment of backslashes 880 let g:paras[j] = substitute(g:paras[j], '`', '\`', 'g') 881 let g:paras[j] = substitute(g:paras[j], '\.', '\.', 'g') 882 let g:paras[j] = substitute(g:paras[j], '\[', '\[', 'g') 883 let g:paras[j] = substitute(g:paras[j], '\\', '\\', 'g') 884 let g:paras[j] = substitute(g:paras[j], '_', '\_', 'g') 885 let g:paras[j] = substitute(g:paras[j], '|', '\|', 'g') 886 887 endif 888 let j += 1 889 endwhile 890 endif 891 let i += 1 892 endwhile 893 " }}} 894 " Build databases NOW. {{{ 895 " For this we have to glue together g:paras, 896 " split it along \n and perform other footnote detection actions. 897 " But we want to make it only once on first parsing, not inside of tables 898 if !exists('b:vst_first_parsing') 899 900 " Some actions should be taken only first time when parsing whole file (not in 901 " tables cells). Set this variable and unlet it when returning from export 902 let b:vst_first_parsing = 1 903 904 let fntext = split(join(g:paras, "\n\n"), "\n") 905 906 " Create hyperlink and other databases 907 call VST_CreateDBs(fntext) 908 909 " Check how many numbered footnotes are in file 910 let numberedfnotes = filter(copy(fntext), 'v:val =~ "^\\s*\\.\\. \\[\\d\\+\\]"') 911 let fnotesnumbers = [] 912 for line in numberedfnotes 913 let fnotesnumbers += [matchstr(line, '^\s*\.\. \[\zs\d\+\ze]')] 914 endfor 915 let s:maxfnumber = max(fnotesnumbers) 916 917 " Check how many labeled footnotes is in file and build labels db 918 " Dictionary with key -> text label, value -> number of footnote 919 let g:labeledfnotes = filter(copy(fntext), 'v:val =~ "\\[#\\k\\+\\]_"') 920 let g:lfnotes = {} 921 let k = s:maxfnumber + 1 922 let i = 0 923 while i < len(g:labeledfnotes) 924 let label = matchstr(g:labeledfnotes[i], '\[#\zs\k\+\ze]_') 925 let g:lfnotes[label] = k 926 let i += 1 927 let k += 1 928 endwhile 929 let s:maxlnumber = len(g:labeledfnotes) 930 931 " Build citation database, only list of citation labels: 932 let citlabels = filter(copy(fntext), 'v:val =~ "\\[\\k\\+\\]_"') 933 let g:clabels = [] 934 let i = 0 935 while i < len(citlabels) 936 let g:clabels += [matchstr(citlabels[i], '\[\zs\k\+\ze]_')] 937 let i += 1 938 endwhile 939 940 endif 941 " }}} 942 " Build replacement database. {{{ 943 if string(g:ptype) =~ "'replacement'" 944 let i = 0 945 while i < len(g:paras) 946 if g:ptype[i] == 'replacement' 947 let from = matchstr(g:paras[i], '^\s*\.\. |\zs.\{-}\ze|') 948 let into = matchstr(g:paras[i], '^\s*\.\. |.\{-}|\s\+\zs.*') 949 let g:vst_replacedb[from] = into 950 endif 951 let i += 1 952 endwhile 953 endif 954 " }}} 955 " Detect and create multi element directives (MED) {{{ 956 let i = 0 957 while i < len(g:paras) 958 if g:ptype[i] =~ '^MED' 959 let firstpar = matchstr(g:paras[i], '^\s*\.\. \w\+::\s*\zs.*') 960 " Header of MED {{{ 961 if g:ptype[i] == 'MED' 962 let medtype = matchstr(g:paras[i], '^\s*\.\. \zs\w\+\ze::') 963 elseif g:ptype[i] =~ '-footnote$' 964 let medtype = 'footnote' 965 elseif g:ptype[i] =~ '-figure$' 966 let medtype = 'figure' 967 elseif g:ptype[i] =~ '-autofootnote$' 968 let medtype = 'autofootnote' 969 elseif g:ptype[i] =~ '-citation$' 970 let medtype = 'citation' 971 elseif g:ptype[i] =~ '-class$' 972 let medtype = 'class' 973 elseif g:ptype[i] =~ '-compound$' 974 let medtype = 'compound' 975 elseif g:ptype[i] =~ '-comment$' 976 let medtype = 'comment' 977 elseif g:ptype[i] =~ '-container$' 978 let medtype = 'container' 979 elseif g:ptype[i] =~ '-labelfootnote$' 980 let medtype = 'labelfootnote' 981 elseif g:ptype[i] =~ '-pullquote$' 982 let medtype = 'pullquote' 983 elseif g:ptype[i] =~ '-block$' 984 let medtype = 'block' 985 elseif g:ptype[i] =~ '-topic$' 986 let medtype = 'topic' 987 elseif g:ptype[i] =~ '-sidebar$' 988 let medtype = 'sidebar' 989 elseif g:ptype[i] =~ '-unknown$' 990 let medtype = 'unknown' 991 endif 992 993 let divindent = repeat(' ', g:pindent[i]) 994 if medtype =~? '\(\<note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)' 995 if medtype == 'admonition' 996 if firstpar =~ '\n\s*:class:' 997 let class = VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*')) 998 let name = matchstr(firstpar, '^.*\ze\s*\n') 999 else 1000 let name = matchstr(firstpar, '^.*\ze\s*$') 1001 let class = 'note' 1002 endif 1003 let g:paras[i] = divindent.'<vim:div class="'.tolower(class).VST_AddClass(i,0,' ','').'">' 1004 let title = name 1005 let firstpar = '' 1006 else 1007 let g:paras[i] = divindent.'<vim:div class="'.tolower(medtype).VST_AddClass(i,0,' ','').'">' 1008 let title = substitute(tolower(medtype), '^.', '\U\0', '') 1009 endif 1010 1011 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>' 1012 1013 if firstpar != '' 1014 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g') 1015 let g:paras[i] = g:paras[i]."\n".title.VST_Structure(split(firstpar, "\n")) 1016 else 1017 let g:paras[i] = g:paras[i]."\n".title."\n" 1018 endif 1019 1020 let medtype = 'div' 1021 1022 elseif medtype == 'figure' 1023 " figure MED {{{ 1024 " supported sub-directives: alt, height, width, scale, align, 1025 " target, class, identify, figwidth, figclass 1026 let src = '' 1027 let width = '' 1028 let height = '' 1029 let alt = '' 1030 let title = '' 1031 let identify = '' 1032 let scale = '' 1033 let target = '' 1034 let class = '' 1035 let align = '' 1036 let figalign = '' 1037 let figwidth = '' 1038 let figclass = '' 1039 let parlines = split(g:paras[i], '\n') 1040 for parline in parlines 1041 let parline = substitute(parline, '^\s*', '', '') 1042 if src == '' 1043 let src = matchstr(parline, '\.\. figure::\s*\zs.\{-}\ze\s*$') 1044 if !filereadable(escape(src, ' \%#')) 1045 let noimage = 1 1046 let g:vst_error .= "No image: ".src."\n" 1047 else 1048 let noimage = 0 1049 endif 1050 endif 1051 if width == '' 1052 let width = matchstr(parline, ':width:\s*\zs.\{-}\ze\s*$') 1053 endif 1054 if height == '' 1055 let height = matchstr(parline, ':height:\s*\zs.\{-}\ze\s*$') 1056 endif 1057 if alt == '' 1058 let alt = matchstr(parline, ':alt:\s*\zs.\{-}\ze\s*$') 1059 endif 1060 if title == '' 1061 let title = matchstr(parline, ':title:\s*\zs.\{-}\ze\s*$') 1062 endif 1063 if align == '' 1064 let align = matchstr(parline, ':align:\s*\zs.\{-}\ze\s*$') 1065 endif 1066 if figwidth == '' 1067 let figwidth = matchstr(parline, ':figwidth:\s*\zs.\{-}\ze\s*$') 1068 endif 1069 if figclass == '' 1070 let figclass = matchstr(parline, ':figclass:\s*\zs.\{-}\ze\s*$') 1071 endif 1072 if figalign == '' 1073 let figalign = matchstr(parline, ':figalign:\s*\zs.\{-}\ze\s*$') 1074 endif 1075 if scale == '' 1076 let scale = matchstr(parline, ':scale:\s*\zs.\{-}\ze\s*$') 1077 if scale =~ '\D' 1078 let scale = '' 1079 endif 1080 endif 1081 if target == '' 1082 let target = matchstr(parline, ':target:\s*\zs.\{-}\ze\s*$') 1083 if target == 'self' && src != '' 1084 let target = src 1085 endif 1086 while target =~ '_\s*$' 1087 let title = matchstr(target, '^\s*\(`\?\)\zs.*\ze\1_\s*$') 1088 " If ends in _ it is probably indirect link, process it 1089 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != '' 1090 let target = escape(g:vst_hlinkdb[title], '&\~') 1091 else 1092 let target = '#l'.tolower(VST_IdMaker(title)) 1093 endif 1094 endwhile 1095 endif 1096 if class == '' 1097 let class = matchstr(parline, ':class:\s*\zs.\{-}\ze\s*$') 1098 endif 1099 if identify == '' 1100 let identify = matchstr(parline, ':identify:') 1101 if identify != '' 1102 if executable('identify') && noimage == 0 1103 let [width, height] = VST_IdentifyImage(src, parline) 1104 else 1105 let [width, height] = ['', ''] 1106 endif 1107 endif 1108 endif 1109 endfor 1110 1111 if src != '' 1112 let src = 'src="'.VST_ProtectLiteral(src).'"' 1113 endif 1114 if scale != '' 1115 if width != '' 1116 let width = width*scale/100 1117 endif 1118 if height != '' 1119 let height = height*scale/100 1120 endif 1121 endif 1122 if width != '' 1123 let width = 'width="'.width.'"' 1124 endif 1125 if height != '' 1126 let height = 'height="'.height.'"' 1127 endif 1128 if alt != '' 1129 let alt = 'alt="'.alt.'"' 1130 endif 1131 if title != '' 1132 let title = 'title="'.title.'"' 1133 endif 1134 " reST compatibility, if there is no figalign option but align 1135 " is defined it is probably reST document not supporting 1136 " figalign. 1137 if figalign == '' && align != '' 1138 let figalign = align 1139 let align = '' 1140 endif 1141 if class != '' 1142 if align == '' 1143 let class = 'class="'.class.'"' 1144 else 1145 let class = 'class="'.class.' vst'.align.'"' 1146 endif 1147 else 1148 if align == '' 1149 let class = '' 1150 else 1151 let class = 'class="vst'.align.'"' 1152 endif 1153 endif 1154 if target != '' 1155 if target =~ '_\s*$' 1156 let address = matchstr(VST_Hyperlink(target), '^.\{-}>\ze') 1157 else 1158 let address = '<vim:a href="'.VST_ProtectLiteral(target).'">' 1159 endif 1160 let imagepart = address."\n<vim:img ".src.' '.width.' '.height.' '.class.' '.alt.' '.title." />\n</vim:a>" 1161 else 1162 let imagepart = "\n<vim:img ".src.' '.width.' '.height.' '.class.' '.alt.' '.title." />\n" 1163 endif 1164 1165 if figclass != '' 1166 if figalign == '' 1167 let figclass = 'class="'.figclass.'"' 1168 else 1169 let figclass = 'class="'.figclass.' vst'.figalign.'"' 1170 endif 1171 else 1172 if figalign == '' 1173 let figclass = 'class="figure"' 1174 else 1175 let figclass = 'class="figure vst'.figalign.'"' 1176 endif 1177 endif 1178 1179 if figwidth != '' 1180 if figwidth == 'image' 1181 if exists('width') 1182 let figw = matchstr(width, '\d\+') 1183 let figwidth = 'style="width:'.figw.'px"' 1184 endif 1185 else 1186 let figwidth = 'style="width:'.figwidth.'px"' 1187 endif 1188 endif 1189 let g:paras[i] = divindent.'<vim:figure '.figclass.' '.figwidth.">\n".divindent.imagepart 1190 " }}} 1191 elseif medtype == 'footnote' 1192 " Footnote \[\d\+\] {{{ 1193 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1194 let indent = repeat(' ', g:pindent[i]) 1195 let g:paras[i] = 1196 \ substitute(g:paras[i], '^\s*\.\. \[\(\d\+\)\]', indent.'<vim:footnote>\n'.indent.'<vim:div class="fnumber"><vim:a href="#target-\1" name="footnote-\1">[\1]</vim:a></vim:div>\n'.indent.'<vim:div class="ftext">', '') 1197 let firstpar = matchstr(g:paras[i], '<vim:div class="ftext">\zs.*') 1198 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g') 1199 let firstpar = VST_Structure(split(firstpar, "\n")) 1200 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ftext">\zs.*', '', '') 1201 let g:paras[i] .= firstpar 1202 " }}} 1203 elseif medtype == 'autofootnote' 1204 " Footnote \[#\] {{{ 1205 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1206 let indent = repeat(' ', g:pindent[i]) 1207 if !exists('b:vst_afs') 1208 let g:autofnote = s:maxfnumber + s:maxlnumber + 1 1209 let b:vst_afs = 1 1210 endif 1211 let k = g:autofnote 1212 let g:paras[i] = 1213 \ substitute(g:paras[i], '^\s*\.\. \[#\]', indent.'<vim:footnote>\n'.indent.'<vim:div class="fnumber"><vim:a href="#target-'.k.'" name="footnote-'.k.'">['.k.']</vim:a></vim:div>\n'.indent.'<vim:div class="ftext">', '') 1214 let firstpar = matchstr(g:paras[i], '<vim:div class="ftext">\zs.*') 1215 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g') 1216 let firstpar = VST_Structure(split(firstpar, "\n")) 1217 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ftext">\zs.*', '', '') 1218 let g:paras[i] .= firstpar 1219 let g:autofnote += 1 1220 let medtype = 'footnote' 1221 " }}} 1222 elseif medtype == 'labelfootnote' 1223 " Footnote \[#\k\+\] {{{ 1224 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1225 let indent = repeat(' ', g:pindent[i]) 1226 let label = matchstr(g:paras[i], '^\s*\.\. \[#\zs\k\+\ze\]') 1227 let k = g:lfnotes[label] 1228 let g:paras[i] = 1229 \ substitute(g:paras[i], '^\s*\.\. \[#\k\+\]', indent.'<vim:footnote>\n'.indent.'<vim:div class="fnumber"><vim:a href="#target-'.k.'" name="footnote-'.k.'">['.k.']</vim:a></vim:div>\n'.indent.'<vim:div class="ftext">', '') 1230 let firstpar = matchstr(g:paras[i], '<vim:div class="ftext">\zs.*') 1231 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g') 1232 let firstpar = VST_Structure(split(firstpar, "\n")) 1233 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ftext">\zs.*', '', '') 1234 let g:paras[i] .= firstpar 1235 let medtype = 'footnote' 1236 " }}} 1237 elseif medtype == 'citation' 1238 " Citation \[\k\+\] {{{ 1239 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1240 let indent = repeat(' ', g:pindent[i]) 1241 let label = matchstr(g:paras[i], '^\s*\.\. \[\zs\k\+\ze\]') 1242 let g:paras[i] = 1243 \ substitute(g:paras[i], '^\s*\.\. \[\k\+\]', indent.'<vim:citation>\n'.indent.'<vim:div class="cnumber"><vim:a href="#ctarget-'.label.'" name="citation-'.label.'">['.label.']</vim:a></vim:div>\n'.indent.'<vim:div class="ctext">', '') 1244 let firstpar = matchstr(g:paras[i], '<vim:div class="ctext">\zs.*') 1245 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '\n', 'g') 1246 let firstpar = VST_Structure(split(firstpar, "\n")) 1247 let g:paras[i] = substitute(g:paras[i], '<vim:div class="ctext">\zs.*', '', '') 1248 let g:paras[i] .= firstpar 1249 " }}} 1250 elseif medtype == 'class' 1251 " Multi element class {{{ 1252 " We don't need to change content of par, it is purely virtual MED 1253 let classname = matchstr(g:paras[i], '^\s*\.\. class::\s*\zs.*\ze\s*$') 1254 let g:paras[i] = VST_IdMaker(classname) 1255 let indent = repeat(' ', g:pindent[i]) 1256 " }}} 1257 elseif medtype == 'comment' 1258 " Multi element comment {{{ 1259 let indent = repeat(' ', g:pindent[i]) 1260 let g:paras[i] = '<vim:comment>'.g:paras[i] 1261 " }}} 1262 elseif medtype == 'compound' 1263 " Multi element compound {{{ 1264 let indent = repeat(' ', g:pindent[i]) 1265 if firstpar =~ '\n\s*:class:' 1266 let class = 'vstcompound '.VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*\(\n\|$\)')) 1267 else 1268 let class = 'vstcompound' 1269 endif 1270 let g:paras[i] = indent.'<vim:block id="id-'.i.'" class="'.tolower(class).'">' 1271 let g:vst_containers += [tolower(class)] 1272 1273 let medtype = 'block' 1274 1275 " }}} 1276 elseif medtype == 'container' 1277 " Multi line div {{{ 1278 let indent = repeat(' ', g:pindent[i]) 1279 let class = matchstr(g:paras[i], '^\s*\.\. container::\s*\zs.*\ze\s*') 1280 let class = VST_IdMaker(class) 1281 let g:paras[i] = indent.'<vim:container id="id-'.i.'" class="'.tolower(class).'">' 1282 let g:vst_containers += [tolower(class)] 1283 " }}} 1284 elseif medtype == 'topic' 1285 " Multi element topic {{{ 1286 let indent = repeat(' ', g:pindent[i]) 1287 if firstpar =~ '\n\s*:class:' 1288 let class = 'topic '.VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*')) 1289 let name = matchstr(firstpar, '^.*\ze\s*\n') 1290 else 1291 let name = matchstr(firstpar, '^.*\ze\s*$') 1292 let class = 'topic' 1293 endif 1294 let g:paras[i] = divindent.'<vim:topic class="'.tolower(class).'">' 1295 let title = name 1296 if title != '' 1297 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>' 1298 else 1299 let title = '' 1300 endif 1301 let firstpar = '' 1302 1303 let g:paras[i] .= "\n".title 1304 " }}} 1305 elseif medtype == 'sidebar' 1306 " Multi element sidebar {{{ 1307 let indent = repeat(' ', g:pindent[i]) 1308 if firstpar =~ '\n\s*:class:' 1309 let class = 'vstsidebar '.VST_IdMaker(matchstr(firstpar, '\n\s*:class:\s*\zs.*\ze\s*\(\n\|$\)')) 1310 else 1311 let class = 'vstsidebar' 1312 endif 1313 let name = matchstr(firstpar, '^.*\ze\s*\n') 1314 if firstpar =~ ':subtitle:' 1315 let subtitle = matchstr(firstpar, ':subtitle:\s*\zs.\{-}\ze\s*\(\n\|$\)') 1316 else 1317 let subtitle = '' 1318 endif 1319 let g:paras[i] = divindent.'<vim:sidebar class="'.tolower(class).'">' 1320 let title = name 1321 if title != '' 1322 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>' 1323 else 1324 let title = '' 1325 endif 1326 1327 if subtitle != '' 1328 let title .= "\n".'<vim:p class="notesubtitle">'.subtitle.'</vim:p>' 1329 endif 1330 let firstpar = '' 1331 1332 let g:paras[i] .= "\n".title 1333 " }}} 1334 elseif medtype == 'block' 1335 " Multi line div {{{ 1336 let indent = repeat(' ', g:pindent[i]) 1337 let class = matchstr(g:paras[i], '^\s*\.\. block::\s*\zs.*\ze\s*') 1338 let class = VST_IdMaker(class) 1339 let g:paras[i] = indent.'<vim:block id="id-'.i.'" class="'.tolower(class).'">' 1340 let g:vst_containers += [tolower(class)] 1341 " }}} 1342 elseif medtype == 'pullquote' 1343 " Bigger blockquote {{{ 1344 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1345 let indent = repeat(' ', g:pindent[i]) 1346 let g:paras[i] = 1347 \ substitute(g:paras[i], '^\s*\.\. pull-quote::', indent.'<vim:pullquote'.VST_AddClass(i,1,' ','').'>', '') 1348 " }}} 1349 elseif medtype == 'unknown' 1350 " Unknown multi element div {{{ 1351 let indent = repeat(' ', g:pindent[i]) 1352 let g:paras[i] = indent.'<vim:unknown>'.g:paras[i] 1353 " }}} 1354 else 1355 let g:paras[i] = divindent.'<vim:div class="note">' 1356 let title = 'Unknown' 1357 let title = divindent.'<vim:p><vim:span class="notetitle">'.title.'</vim:span></vim:p>' 1358 if firstpar != '' 1359 let firstpar = substitute(firstpar, '\(^\|\n\)\s\+', '', 'g') 1360 let g:paras[i] = g:paras[i]."\n".title.VST_Structure(split(firstpar, "\n")) 1361 else 1362 let g:paras[i] = g:paras[i]."\n".title."\n" 1363 endif 1364 endif 1365 1366 " }}} 1367 let j = i + 1 1368 while j < len(g:paras) 1369 let noteindent = g:pindent[j] - g:pindent[i] 1370 if g:pindent[i] >= g:pindent[j] || g:ptype[j] == 'notend' || g:ptype[j] == 'blank' 1371 if medtype =~ 'footnote\|citation' 1372 call insert(g:paras, repeat(' ', g:pindent[j]).'</vim:div></vim:'.medtype.'>', j) 1373 elseif medtype == 'class' 1374 if j - i == 1 1375 call insert(g:paras, repeat(' ', g:pindent[j]).'', j) 1376 else 1377 call insert(g:paras, repeat(' ', g:pindent[j]).'<vim:class'.classname.' />', j) 1378 endif 1379 else 1380 call insert(g:paras, repeat(' ', g:pindent[j]).'</vim:'.medtype.'>', j) 1381 endif 1382 call insert(g:pindent, g:pindent[i], j) 1383 "call insert(g:pindent, g:pindent[j-1], j) 1384 call insert(g:ptype, 'notend', j) 1385 call insert(g:plinen, 0, j) 1386 break 1387 else 1388 "if g:pindent[j] == noteindent 1389 if g:ptype[j] == 'blockquote' && g:pindent[j] == noteindent 1390 let g:ptype[j] = 'p' 1391 endif 1392 endif 1393 let j += 1 1394 endwhile 1395 1396 endif 1397 let i += 1 1398 endwhile 1399 " }}} 1400 " Detect and create transitions (<hr>) {{{ 1401 let i = 0 1402 for par in g:paras 1403 if i < len(g:paras) 1404 if g:paras[i] !~ '\n' && g:paras[i] =~ '^\s*'.s:vst_headdef.'\s*$' 1405 if g:ptype[i] !~ '^pre' 1406 let g:ptype[i] = 'hr' 1407 let class = VST_AddClass(i, 1, '', '') 1408 let g:paras[i] = substitute(g:paras[i], '.*', '\n<vim:hr '.class.'/>\n', '') 1409 endif 1410 endif 1411 endif 1412 let i += 1 1413 endfor 1414 " }}} 1415 " Detect blockquote paragraphs {{{ 1416 let i = 0 1417 while i < len(g:paras) 1418 if g:ptype[i] == 'p' && g:pindent[i] > g:pindent[i-1] 1419 if g:ptype[i] !~ '^pre' && g:ptype[i-1] !~ '^MED' && g:ptype[i-1] !~ 'optlist' 1420 let g:ptype[i] = 'blockquote' 1421 endif 1422 if g:ptype[i-1] =~ '^MED' && g:pindent[i] > g:pindent[i-1] + 3 1423 let g:ptype[i] = 'blockquote' 1424 endif 1425 endif 1426 let i += 1 1427 endwhile 1428 " }}} 1429 " Detect if par is a header (<hx>) {{{ 1430 let i = 0 1431 let h1 = '' 1432 let h2 = '' 1433 let h3 = '' 1434 let h4 = '' 1435 let h5 = '' 1436 while i < len(g:paras) 1437 if g:ptype[i] !~ '^pre' 1438 if g:paras[i] =~ '\n\s*'.s:vst_headdef.'\s*\(\n\|$\)' && g:ptype[i] !~ 'table' && g:paras[i] !~ 'vim:comment' 1439 let parlines = split(g:paras[i], '\n') 1440 if parlines[1] =~ '^\s*'.s:vst_headdef.'\s*$' 1441 let double = ' ' 1442 elseif parlines[0] == parlines[2] && parlines[0] =~ '^\s*'.s:vst_headdef.'\s*$' 1443 let double = 'd' 1444 call remove(parlines, 0) 1445 endif 1446 let lchar = matchstr(parlines[1], '.\ze\s*$').double 1447 if lchar =~ s:vst_headchars 1448 if h1 == '' || lchar == h1 1449 let h1 = lchar 1450 let g:ptype[i] = 'h1' 1451 elseif h2 == '' || lchar == h2 1452 let h2 = lchar 1453 let g:ptype[i] = 'h2' 1454 elseif h3 == '' || lchar == h3 1455 let h3 = lchar 1456 let g:ptype[i] = 'h3' 1457 elseif h4 == '' || lchar == h4 1458 let h4 = lchar 1459 let g:ptype[i] = 'h4' 1460 elseif h5 == '' || lchar == h5 1461 let h5 = lchar 1462 let g:ptype[i] = 'h5' 1463 else 1464 let g:ptype[i] = 'h6' 1465 endif 1466 let modlchar = substitute(lchar, '[d ]', '', 'g') 1467 let g:vst_headers[g:ptype[i]] = repeat(modlchar, 9).double 1468 1469 if len(parlines) > 2 1470 let g:paras[i] = join(parlines[0:1], "\n") 1471 call insert(g:paras, join(parlines[2:], "\n"), i+1) 1472 call insert(g:pindent, g:pindent[i], i+1) 1473 call insert(g:plinen, 0, i+1) 1474 1475 if parlines[2] =~ '^\s*(\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\))\s' 1476 " LISTDEF: 1477 call insert(g:ptype, 'oli', i+1) 1478 elseif parlines[2] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s' 1479 " LISTDEF: 1480 call insert(g:ptype, 'oli', i+1) 1481 elseif parlines[2] =~ '^\s*'.s:vst_bulletdef.'\s' 1482 call insert(g:ptype, 'uli', i+1) 1483 elseif parlines[2] =~ '^\s*:.\{-1,}:\(\s\+\|$\)' 1484 call insert(g:ptype, 'field', i+1) 1485 elseif parlines[2] =~ '^\s*::\s*$' 1486 call insert(g:ptype, 'emptypre', i+1) 1487 elseif parlines[2] =~ '^\s*| ' 1488 call insert(g:ptype, 'verse', i+1) 1489 elseif parlines[2] =~ '^\s*+-\{3,}' 1490 call insert(g:ptype, 'table', i+1) 1491 elseif parlines[2] =~ '^\s*+=\{3,}' 1492 call insert(g:ptype, 'bltable', i+1) 1493 elseif parlines[2] =~ '^\s*\(--\|-\|/\|:\|+\)\S.\{-}\( \|$\)' && doc[line] !~ '^\s*\(--\s\|:\S\+:`\)' 1494 call insert(g:ptype, 'optlist', i+1) 1495 elseif parlines[2] =~ '^\s*>>>' 1496 call insert(g:ptype, 'doctest', i+1) 1497 elseif parlines[2] =~ '^\s*=\{2,}\s\+=\{2,}' 1498 call insert(g:ptype, 'simpletbl', i+1) 1499 else 1500 " Everything after ornament put into next 1501 " paragraph sub type. Ugly but prevents worse 1502 " things. 1503 call insert(g:ptype, 'sub'.g:ptype[i], i+1) 1504 endif 1505 else 1506 let g:paras[i] = join(parlines, "\n") 1507 endif 1508 endif 1509 endif 1510 endif 1511 let i += 1 1512 endwhile 1513 " }}} 1514 1514 " Formatting 1515 1515 " Create dl paragraph {{{ 1516 1516 if string(g:ptype) =~ "'dl'" 1517 let i = 01518 while i < len(g:paras)1519 if g:ptype[i] == 'dl'1520 "let initind = strlen(matchstr(g:paras[i], '\n\zs\s*\ze.\{-}'))1521 let parlines = split(g:paras[i], '\n')1522 let initind = strlen(matchstr(parlines[-1], '^\s*'))1523 let j = i + 11524 while j < len(g:paras)1525 if g:pindent[j] < initind || g:ptype[j] == 'blank'1526 let newind = repeat(' ', g:pindent[j])1527 call insert(g:paras, newind.'</vim:dd>'."\n".newind.'</vim:dl>', j)1528 call insert(g:pindent, g:pindent[i], j)1529 call insert(g:ptype, 'dlend', j)1530 call insert(g:plinen, 0, j)1531 1532 call insert(g:paras, repeat(' ', g:pindent[i]).'<vim:dl'.VST_AddClass(i,1,' ','').'>', i)1533 call insert(g:pindent, g:pindent[i], i)1534 call insert(g:ptype, 'dlbegin', i)1535 call insert(g:plinen, 0, i)1536 1537 " Recompensate paragraph inserted before current position.1538 let i += 11539 1540 break1541 else1542 if g:ptype[j] == 'blockquote'1543 if g:pindent[j] == initind1544 let g:ptype[j] = 'p'1545 endif1546 endif1547 1548 endif1549 let j += 11550 endwhile1551 1552 endif1553 let i += 11554 endwhile1517 let i = 0 1518 while i < len(g:paras) 1519 if g:ptype[i] == 'dl' 1520 "let initind = strlen(matchstr(g:paras[i], '\n\zs\s*\ze.\{-}')) 1521 let parlines = split(g:paras[i], '\n') 1522 let initind = strlen(matchstr(parlines[-1], '^\s*')) 1523 let j = i + 1 1524 while j < len(g:paras) 1525 if g:pindent[j] < initind || g:ptype[j] == 'blank' 1526 let newind = repeat(' ', g:pindent[j]) 1527 call insert(g:paras, newind.'</vim:dd>'."\n".newind.'</vim:dl>', j) 1528 call insert(g:pindent, g:pindent[i], j) 1529 call insert(g:ptype, 'dlend', j) 1530 call insert(g:plinen, 0, j) 1531 1532 call insert(g:paras, repeat(' ', g:pindent[i]).'<vim:dl'.VST_AddClass(i,1,' ','').'>', i) 1533 call insert(g:pindent, g:pindent[i], i) 1534 call insert(g:ptype, 'dlbegin', i) 1535 call insert(g:plinen, 0, i) 1536 1537 " Recompensate paragraph inserted before current position. 1538 let i += 1 1539 1540 break 1541 else 1542 if g:ptype[j] == 'blockquote' 1543 if g:pindent[j] == initind 1544 let g:ptype[j] = 'p' 1545 endif 1546 endif 1547 1548 endif 1549 let j += 1 1550 endwhile 1551 1552 endif 1553 let i += 1 1554 endwhile 1555 1555 endif 1556 1556 " }}} 1557 1557 " Detect and pre-prepare definition list (<dl>) {{{ 1558 1558 if string(g:ptype) =~ "'dl'" 1559 let i = 01560 while i < len(g:paras)1561 if g:ptype[i] == 'dl'1562 let defterm = matchlist(g:paras[i], '^\(.\{-}\n\)\(\s*\)\(.*\)')1563 let defpar = split(substitute(defterm[3], '\n\s*', '\n', 'g'), "\n")1564 let defterm[1] = VST_SpecCharacter(defterm[1])1565 let defpart = "\n".'<vim:dt class="normal">'.defterm[1].'</vim:dt>'."\n".defterm[2].'<vim:dd class="normal">'."\n".defterm[2]1566 let g:paras[i] = defpart.VST_Structure(defpar)1567 endif1568 let i += 11569 endwhile1559 let i = 0 1560 while i < len(g:paras) 1561 if g:ptype[i] == 'dl' 1562 let defterm = matchlist(g:paras[i], '^\(.\{-}\n\)\(\s*\)\(.*\)') 1563 let defpar = split(substitute(defterm[3], '\n\s*', '\n', 'g'), "\n") 1564 let defterm[1] = VST_SpecCharacter(defterm[1]) 1565 let defpart = "\n".'<vim:dt class="normal">'.defterm[1].'</vim:dt>'."\n".defterm[2].'<vim:dd class="normal">'."\n".defterm[2] 1566 let g:paras[i] = defpart.VST_Structure(defpar) 1567 endif 1568 let i += 1 1569 endwhile 1570 1570 endif 1571 1571 " }}} … … 1573 1573 " This can be only one paragraph so don't worry about other pre troubles 1574 1574 if string(g:ptype) =~ "'prequoted'" 1575 let i = 01576 while i < len(g:paras)1577 if g:ptype[i] == 'prequoted'1578 " In pre paragraphs special characters also have to be1579 " escaped.1580 let g:paras[i] = VST_SpecCharacter(g:paras[i])1581 " Prevent splitting for auto footnotes and hyperlinks1582 let g:paras[i] = substitute(g:paras[i], '\[', '\[', 'g')1583 let g:paras[i] = substitute(g:paras[i], '_', '\_', 'g')1584 1585 if g:paras[i-3] =~ '^\s*::\s*$'1586 let g:paras[i] = '<vim:pre class="quoted'.VST_AddClass(i-3, 0, ' ', '').'">'1587 \."\n".g:paras[i]."\n".'</vim:pre>'1588 else1589 let g:paras[i] = '<vim:pre class="quoted">'."\n".g:paras[i]1590 \."\n".'</vim:pre>'1591 endif1592 1593 endif1594 let i += 11595 endwhile1575 let i = 0 1576 while i < len(g:paras) 1577 if g:ptype[i] == 'prequoted' 1578 " In pre paragraphs special characters also have to be 1579 " escaped. 1580 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1581 " Prevent splitting for auto footnotes and hyperlinks 1582 let g:paras[i] = substitute(g:paras[i], '\[', '\[', 'g') 1583 let g:paras[i] = substitute(g:paras[i], '_', '\_', 'g') 1584 1585 if g:paras[i-3] =~ '^\s*::\s*$' 1586 let g:paras[i] = '<vim:pre class="quoted'.VST_AddClass(i-3, 0, ' ', '').'">' 1587 \."\n".g:paras[i]."\n".'</vim:pre>' 1588 else 1589 let g:paras[i] = '<vim:pre class="quoted">'."\n".g:paras[i] 1590 \."\n".'</vim:pre>' 1591 endif 1592 1593 endif 1594 let i += 1 1595 endwhile 1596 1596 endif 1597 " }}}1597 " }}} 1598 1598 " Create option list paragraph {{{ 1599 1599 if string(g:ptype) =~ "'optlist'" 1600 let i = 01601 while i < len(g:paras)1602 if g:ptype[i] == 'optlist'1603 " Detect indentation of option list1604 let listindent = strlen(matchstr(g:paras[i], '^\s*\zs\(--\|-\|/\|:\|+\)\S.\{-} \s*'))1605 let j = i + 11606 while j < len(g:paras)1607 if g:pindent[j] <= g:pindent[i] || g:ptype[j] == 'blank'1608 let newind = repeat(' ', g:pindent[j])1609 call insert(g:paras, newind.'</vim:dd>'."\n".newind.'</vim:dl class="option'.VST_AddClass(i,0, ' ','').'">', j)1610 call insert(g:pindent, g:pindent[i], j)1611 call insert(g:ptype, 'optend', j)1612 call insert(g:plinen, 0, j)1613 1614 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:dl class="option'.VST_AddClass(i,0, ' ','').'">', i)1615 call insert(g:pindent, g:pindent[i], i)1616 call insert(g:ptype, 'optbegin', i)1617 call insert(g:plinen, 0, i)1618 1619 " Recompensate inserted paragraph before current position.1620 let i += 11621 1622 break1623 else1624 if g:ptype[j] == 'blockquote'1625 if g:pindent[j] == g:pindent[i] + listindent1626 let g:ptype[j] = 'p'1627 endif1628 endif1629 1630 endif1631 let j += 11632 endwhile1633 1634 let g:paras[i] = VST_SpecCharacter(g:paras[i])1635 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\(--\|-\|/\|:\|+\)\(\S.\{-}\) ', '\n<vim:dt class="option">\2\3</vim:dt>\n\1<vim:dd class="option">\n\1<vim:p>', '')1636 let g:paras[i] = substitute(g:paras[i], '\n\(\s*\)\(--\|-\|/\|:\|+\)\(\S.\{-}\) ', '</vim:p></vim:dd>\n\1<vim:dt class="option">\2\3</vim:dt>\n\1<vim:dd class="option">\n\1<vim:p>', 'g')1637 let g:paras[i] = substitute(g:paras[i], '$', '</vim:p>', '')1638 endif1639 let i += 11640 endwhile1600 let i = 0 1601 while i < len(g:paras) 1602 if g:ptype[i] == 'optlist' 1603 " Detect indentation of option list 1604 let listindent = strlen(matchstr(g:paras[i], '^\s*\zs\(--\|-\|/\|:\|+\)\S.\{-} \s*')) 1605 let j = i + 1 1606 while j < len(g:paras) 1607 if g:pindent[j] <= g:pindent[i] || g:ptype[j] == 'blank' 1608 let newind = repeat(' ', g:pindent[j]) 1609 call insert(g:paras, newind.'</vim:dd>'."\n".newind.'</vim:dl class="option'.VST_AddClass(i,0, ' ','').'">', j) 1610 call insert(g:pindent, g:pindent[i], j) 1611 call insert(g:ptype, 'optend', j) 1612 call insert(g:plinen, 0, j) 1613 1614 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:dl class="option'.VST_AddClass(i,0, ' ','').'">', i) 1615 call insert(g:pindent, g:pindent[i], i) 1616 call insert(g:ptype, 'optbegin', i) 1617 call insert(g:plinen, 0, i) 1618 1619 " Recompensate inserted paragraph before current position. 1620 let i += 1 1621 1622 break 1623 else 1624 if g:ptype[j] == 'blockquote' 1625 if g:pindent[j] == g:pindent[i] + listindent 1626 let g:ptype[j] = 'p' 1627 endif 1628 endif 1629 1630 endif 1631 let j += 1 1632 endwhile 1633 1634 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1635 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\(--\|-\|/\|:\|+\)\(\S.\{-}\) ', '\n<vim:dt class="option">\2\3</vim:dt>\n\1<vim:dd class="option">\n\1<vim:p>', '') 1636 let g:paras[i] = substitute(g:paras[i], '\n\(\s*\)\(--\|-\|/\|:\|+\)\(\S.\{-}\) ', '</vim:p></vim:dd>\n\1<vim:dt class="option">\2\3</vim:dt>\n\1<vim:dd class="option">\n\1<vim:p>', 'g') 1637 let g:paras[i] = substitute(g:paras[i], '$', '</vim:p>', '') 1638 endif 1639 let i += 1 1640 endwhile 1641 1641 endif 1642 1642 " }}} 1643 1643 " Create field list {{{ 1644 1644 if string(g:ptype) =~ "'field'" 1645 let i = 01646 while i < len(g:paras)1647 if g:ptype[i] == 'field'1648 let g:paras[i] = VST_SpecCharacter(g:paras[i])1649 let parlines = split(g:paras[i], '\(^\s*\|\n\s*\):\@=')1650 let j = 01651 for parline in parlines1652 let fkey = tolower(matchstr(parlines[j], '^\s*:\zs.\{-}\ze:'))1653 let fcontent = matchstr(parlines[j], '^\s*:.\{-}:\s*\zs.*')1654 if fkey == 'date' && fcontent == 'NONE'1655 let parlines[j] = ''1656 endif1657 if fkey != ''1658 let g:vst_fielddb[fkey] = fcontent1659 endif1660 let parlines[j] = substitute(parlines[j], '^\s*:', '<vim:dt class="field">', '')1661 let parlines[j] = substitute(parlines[j], '\(vim\)\@<!:', ':</vim:dt><vim:dd class="field">', '')1662 let parlines[j] .= '</vim:dd>'."\n"1663 let parlines[j] = substitute(parlines[j], '\c\(class="field">\)\(organization\|date\|status\|revision\|version\|dedication\|abstract\|copyright\)', '\1\u\2', 'g')1664 " Adjustments for special types of fields: dedication, abstract1665 " Has to wait for fixing MEDding of field lists1666 let parlines[j] = substitute(parlines[j], 'class="field">Dedication:</vim:dt><vim:dd class="field">', 'class="field fdedication">Dedication</vim:dt><vim:dd class="field fdedication">','')1667 let parlines[j] = substitute(parlines[j], 'class="field">Abstract:</vim:dt><vim:dd class="field">', 'class="field fabstract">Abstract</vim:dt><vim:dd class="field fabstract">','')1668 let j += 11669 endfor1670 let g:paras[i] = join(parlines, "\n")1671 let g:paras[i] = '<vim:dl class="field'.VST_AddClass(i,0, ' ', '').'">'.g:paras[i]1672 let g:paras[i] = substitute(g:paras[i], '\(Address:</vim:dt><vim:dd class="field">\)\(.\{-}\)</vim:dd>', '\=submatch(1)."<vim:pre class=\"address\">".substitute(submatch(2), "\\(^\\|\\n\\)\\s\\+", "\\n", "g")."</vim:pre></vim:dd>"','g')1673 if has('unix')1674 " On unices above substitute leaves ^M intead of new line, replace1675 " it with real new line1676 let g:paras[i] = substitute(g:paras[i], '\%d13', '\n', 'g')1677 endif1678 let g:paras[i] .= '</vim:dl>'1679 1680 endif1681 let i += 11682 endwhile1645 let i = 0 1646 while i < len(g:paras) 1647 if g:ptype[i] == 'field' 1648 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 1649 let parlines = split(g:paras[i], '\(^\s*\|\n\s*\):\@=') 1650 let j = 0 1651 for parline in parlines 1652 let fkey = tolower(matchstr(parlines[j], '^\s*:\zs.\{-}\ze:')) 1653 let fcontent = matchstr(parlines[j], '^\s*:.\{-}:\s*\zs.*') 1654 if fkey == 'date' && fcontent == 'NONE' 1655 let parlines[j] = '' 1656 endif 1657 if fkey != '' 1658 let g:vst_fielddb[fkey] = fcontent 1659 endif 1660 let parlines[j] = substitute(parlines[j], '^\s*:', '<vim:dt class="field">', '') 1661 let parlines[j] = substitute(parlines[j], '\(vim\)\@<!:', ':</vim:dt><vim:dd class="field">', '') 1662 let parlines[j] .= '</vim:dd>'."\n" 1663 let parlines[j] = substitute(parlines[j], '\c\(class="field">\)\(organization\|date\|status\|revision\|version\|dedication\|abstract\|copyright\)', '\1\u\2', 'g') 1664 " Adjustments for special types of fields: dedication, abstract 1665 " Has to wait for fixing MEDding of field lists 1666 let parlines[j] = substitute(parlines[j], 'class="field">Dedication:</vim:dt><vim:dd class="field">', 'class="field fdedication">Dedication</vim:dt><vim:dd class="field fdedication">','') 1667 let parlines[j] = substitute(parlines[j], 'class="field">Abstract:</vim:dt><vim:dd class="field">', 'class="field fabstract">Abstract</vim:dt><vim:dd class="field fabstract">','') 1668 let j += 1 1669 endfor 1670 let g:paras[i] = join(parlines, "\n") 1671 let g:paras[i] = '<vim:dl class="field'.VST_AddClass(i,0, ' ', '').'">'.g:paras[i] 1672 let g:paras[i] = substitute(g:paras[i], '\(Address:</vim:dt><vim:dd class="field">\)\(.\{-}\)</vim:dd>', '\=submatch(1)."<vim:pre class=\"address\">".substitute(submatch(2), "\\(^\\|\\n\\)\\s\\+", "\\n", "g")."</vim:pre></vim:dd>"','g') 1673 if has('unix') 1674 " On unices above substitute leaves ^M intead of new line, replace 1675 " it with real new line 1676 let g:paras[i] = substitute(g:paras[i], '\%d13', '\n', 'g') 1677 endif 1678 let g:paras[i] .= '</vim:dl>' 1679 1680 endif 1681 let i += 1 1682 endwhile 1683 1683 endif 1684 1684 " }}} … … 1687 1687 " syntax 1688 1688 if string(g:ptype) =~ "'meta'" 1689 let i = 01690 while i < len(g:paras)1691 if g:ptype[i] == 'meta'1692 let parlines = split(g:paras[i], '\(^\s*\|\n\s*\):\@=')1693 let j = 01694 for parline in parlines1695 let mkey = tolower(matchstr(parlines[j], '^\s*:\zs.\{-}\ze:'))1696 let mcontent = matchstr(parlines[j], '^\s*:.\{-}:\s*\zs.*')1697 if mkey != ''1698 let g:vst_metadb[mkey] = mcontent1699 endif1700 let j += 11701 endfor1702 let g:paras[i] = ''1703 endif1704 let i += 11705 endwhile1689 let i = 0 1690 while i < len(g:paras) 1691 if g:ptype[i] == 'meta' 1692 let parlines = split(g:paras[i], '\(^\s*\|\n\s*\):\@=') 1693 let j = 0 1694 for parline in parlines 1695 let mkey = tolower(matchstr(parlines[j], '^\s*:\zs.\{-}\ze:')) 1696 let mcontent = matchstr(parlines[j], '^\s*:.\{-}:\s*\zs.*') 1697 if mkey != '' 1698 let g:vst_metadb[mkey] = mcontent 1699 endif 1700 let j += 1 1701 endfor 1702 let g:paras[i] = '' 1703 endif 1704 let i += 1 1705 endwhile 1706 1706 endif 1707 1707 " }}} 1708 1708 " Create image paragraphs (.. image::) {{{ 1709 1709 if string(g:ptype) =~ "'img'" 1710 let i = 01711 while i < len(g:paras)-11712 if g:ptype[i] == 'img'1713 let g:paras[i] = VST_ImagePar(g:paras[i], 1)1714 endif1715 let i += 11716 endwhile1710 let i = 0 1711 while i < len(g:paras)-1 1712 if g:ptype[i] == 'img' 1713 let g:paras[i] = VST_ImagePar(g:paras[i], 1) 1714 endif 1715 let i += 1 1716 endwhile 1717 1717 endif 1718 1718 " }}} 1719 1719 " Create comment paragraph - comment (.. comment::) {{{ 1720 1720 if string(g:ptype) =~ "'comment'" 1721 let i = 01722 while i < len(g:paras)1723 if g:ptype[i] == 'comment'1724 let g:paras[i] = '<vim:comment>'.substitute(g:paras[i], '^\s*\.\. comment::', '', '').'</vim:comment>'1725 endif1726 let i += 11727 endwhile1721 let i = 0 1722 while i < len(g:paras) 1723 if g:ptype[i] == 'comment' 1724 let g:paras[i] = '<vim:comment>'.substitute(g:paras[i], '^\s*\.\. comment::', '', '').'</vim:comment>' 1725 endif 1726 let i += 1 1727 endwhile 1728 1728 endif 1729 1729 " }}} 1730 1730 " Create rubric paragraph (.. rubric::) {{{ 1731 1731 if string(g:ptype) =~ "'rubric'" 1732 let i = 01733 while i < len(g:paras)1734 if g:ptype[i] == 'rubric'1735 if g:paras[i] =~ ':class:'1736 let class = matchstr(g:paras[i], ':class:\s*\zs.*\ze\s*$')1737 let g:paras[i] = substitute(g:paras[i], '\s*:class:.*$', '', '')1738 let g:paras[i] = '<vim:rubric class="'.class.'">'.substitute(g:paras[i], '\s*\.\. rubric::', '', '').'</vim:rubric>'1739 else1740 let g:paras[i] = '<vim:rubric'.VST_AddClass(i, 1, ' ', '').'>'.substitute(g:paras[i], '\s*\.\. rubric::', '', '').'</vim:rubric>'1741 endif1742 endif1743 let i += 11744 endwhile1732 let i = 0 1733 while i < len(g:paras) 1734 if g:ptype[i] == 'rubric' 1735 if g:paras[i] =~ ':class:' 1736 let class = matchstr(g:paras[i], ':class:\s*\zs.*\ze\s*$') 1737 let g:paras[i] = substitute(g:paras[i], '\s*:class:.*$', '', '') 1738 let g:paras[i] = '<vim:rubric class="'.class.'">'.substitute(g:paras[i], '\s*\.\. rubric::', '', '').'</vim:rubric>' 1739 else 1740 let g:paras[i] = '<vim:rubric'.VST_AddClass(i, 1, ' ', '').'>'.substitute(g:paras[i], '\s*\.\. rubric::', '', '').'</vim:rubric>' 1741 endif 1742 endif 1743 let i += 1 1744 endwhile 1745 1745 endif 1746 1746 " }}} 1747 1747 " Create ul paragraph {{{ 1748 1748 if string(g:ptype) =~ "'uli'" 1749 let i = 01750 while i < len(g:paras)1751 if g:ptype[i] == 'uli'1752 " LISTDEF:1753 " Detect style of unordered list1754 let style = matchstr(g:paras[i], '^\s*\zs'.s:vst_bulletdef.'\s\+')1755 let listindent = strlen(matchstr(g:paras[i], '^\s*\zs'.s:vst_bulletdef.'\s\+'))1756 if style =~ '+'1757 let ustyle = 'square'1758 elseif style =~ '\*'1759 let ustyle = 'circle'1760 elseif style =~ '-'1761 let ustyle = 'disc'1762 else1763 let ustyle = 'disc'1764 endif1765 let j = i + 11766 while j < len(g:paras)1767 if g:pindent[j] <= g:pindent[i] || g:ptype[j] == 'blank' || g:ptype[j] == 'hr'1768 let newind = repeat(' ', g:pindent[j])1769 call insert(g:paras, newind.'</vim:li>'."\n".newind.'</vim:ul class="'.ustyle.VST_AddClass(i,0,' ','').'">', j)1770 call insert(g:pindent, g:pindent[i], j)1771 call insert(g:ptype, 'ulend', j)1772 call insert(g:plinen, 0, j)1773 1774 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:ul class="'.ustyle.VST_AddClass(i,0,' ','').'">', i)1775 call insert(g:pindent, g:pindent[i], i)1776 call insert(g:ptype, 'ulbegin', i)1777 call insert(g:plinen, 0, i)1778 1779 " Recompensate inserted paragraph before current position.1780 let i += 11781 1782 break1783 else1784 if g:ptype[j] == 'blockquote'1785 if g:pindent[j] == g:pindent[i] + listindent1786 let g:ptype[j] = 'p'1787 endif1788 endif1789 1790 endif1791 let j += 11792 endwhile1793 1794 if ustyle == 'disc'1795 " Potential danger: this also includes * and +1796 let elements = split(g:paras[i], '\(^\|\n\)\s*[\u2022\u2023\u2043\u204c\u204d\u25d8\u25e6\u2619\u2765\u2767-]\s\+')1797 elseif ustyle == 'circle'1798 let elements = split(g:paras[i], '\(^\|\n\)\s*\*\s\+')1799 elseif ustyle == 'square'1800 let elements = split(g:paras[i], '\(^\|\n\)\s*+\s\+')1801 endif1802 for inc in range(len(elements))1803 let s:vst_bulletdef = '[\u2022\u2023\u2043\u204c\u204d\u25d8\u25e6\u2619\u2765\u2767*+-]'1804 let elements[inc] = substitute(elements[inc], '\n\s*', '\n', 'g')1805 let elements[inc] = VST_Structure(split(elements[inc], "\n"))1806 endfor1807 let g:paras[i] = '<vim:li>'.join(elements, "</vim:li>\n<vim:li>")1808 1809 endif1810 let i += 11811 endwhile1749 let i = 0 1750 while i < len(g:paras) 1751 if g:ptype[i] == 'uli' 1752 " LISTDEF: 1753 " Detect style of unordered list 1754 let style = matchstr(g:paras[i], '^\s*\zs'.s:vst_bulletdef.'\s\+') 1755 let listindent = strlen(matchstr(g:paras[i], '^\s*\zs'.s:vst_bulletdef.'\s\+')) 1756 if style =~ '+' 1757 let ustyle = 'square' 1758 elseif style =~ '\*' 1759 let ustyle = 'circle' 1760 elseif style =~ '-' 1761 let ustyle = 'disc' 1762 else 1763 let ustyle = 'disc' 1764 endif 1765 let j = i + 1 1766 while j < len(g:paras) 1767 if g:pindent[j] <= g:pindent[i] || g:ptype[j] == 'blank' || g:ptype[j] == 'hr' 1768 let newind = repeat(' ', g:pindent[j]) 1769 call insert(g:paras, newind.'</vim:li>'."\n".newind.'</vim:ul class="'.ustyle.VST_AddClass(i,0,' ','').'">', j) 1770 call insert(g:pindent, g:pindent[i], j) 1771 call insert(g:ptype, 'ulend', j) 1772 call insert(g:plinen, 0, j) 1773 1774 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:ul class="'.ustyle.VST_AddClass(i,0,' ','').'">', i) 1775 call insert(g:pindent, g:pindent[i], i) 1776 call insert(g:ptype, 'ulbegin', i) 1777 call insert(g:plinen, 0, i) 1778 1779 " Recompensate inserted paragraph before current position. 1780 let i += 1 1781 1782 break 1783 else 1784 if g:ptype[j] == 'blockquote' 1785 if g:pindent[j] == g:pindent[i] + listindent 1786 let g:ptype[j] = 'p' 1787 endif 1788 endif 1789 1790 endif 1791 let j += 1 1792 endwhile 1793 1794 if ustyle == 'disc' 1795 " Potential danger: this also includes * and + 1796 let elements = split(g:paras[i], '\(^\|\n\)\s*[\u2022\u2023\u2043\u204c\u204d\u25d8\u25e6\u2619\u2765\u2767-]\s\+') 1797 elseif ustyle == 'circle' 1798 let elements = split(g:paras[i], '\(^\|\n\)\s*\*\s\+') 1799 elseif ustyle == 'square' 1800 let elements = split(g:paras[i], '\(^\|\n\)\s*+\s\+') 1801 endif 1802 for inc in range(len(elements)) 1803 let s:vst_bulletdef = '[\u2022\u2023\u2043\u204c\u204d\u25d8\u25e6\u2619\u2765\u2767*+-]' 1804 let elements[inc] = substitute(elements[inc], '\n\s*', '\n', 'g') 1805 let elements[inc] = VST_Structure(split(elements[inc], "\n")) 1806 endfor 1807 let g:paras[i] = '<vim:li>'.join(elements, "</vim:li>\n<vim:li>") 1808 1809 endif 1810 let i += 1 1811 endwhile 1812 1812 endif 1813 1813 " }}} 1814 1814 " Create ol paragraph {{{ 1815 1815 if string(g:ptype) =~ "'oli'" 1816 let i = 01817 while i < len(g:paras)1818 if g:ptype[i] == 'oli'1819 " Detect style of ordered list1820 " LISTDEF:1821 let style = matchstr(g:paras[i], '^\s*(\?\zs\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)\ze[\]:.)}]\s*')1822 let listindent = strlen(matchstr(g:paras[i], '^\s*(\?\zs\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*'))1823 if style =~ '^\(I\|[ICDVLMX]\{2,}\)$'1824 let ostyle = 'upperroman'1825 elseif style =~ '^\(i\|[icdvlmx]\{2,}\)$'1826 let ostyle = 'lowerroman'1827 elseif style =~ '[a-z]'1828 let ostyle = 'loweralpha'1829 elseif style =~ '[A-Z]'1830 let ostyle = 'upperalpha'1831 elseif style =~ '[0-9#]'1832 let ostyle = 'decimal'1833 endif1834 let j = i + 11835 while j < len(g:paras)1836 if g:pindent[j] <= g:pindent[i] || g:ptype[j] == 'blank' || g:ptype[j] == 'hr'1837 call insert(g:paras, repeat(' ' , g:pindent[j]).'</vim:li>'.repeat(' ' , g:pindent[j]).'</vim:ol class="'.ostyle.VST_AddClass(i,0,' ','').'">', j)1838 call insert(g:pindent, g:pindent[i], j)1839 call insert(g:ptype, 'olend', j)1840 call insert(g:plinen, 0, j)1841 1842 " Get number of first element1843 " LISTDEF:1844 let start = tolower(matchstr(g:paras[i], '^\s*(\?\zs\(\d\+\|[icdvlmxICDVLMX]\+\|[a-zA-Z]\|#\)\ze'))1845 if start == '1' || start == 'a' || start == '#' || start == 'i'1846 let number = ''1847 elseif start =~ '[0-9]'1848 let number = ' start="'.start.'"'1849 elseif start =~ '[icdvlmx][icdvlmx]'1850 let rtable = split(start, '\ze.')1851 let j = 01852 while j < len(rtable)1853 if rtable[j] == 'i'1854 let rtable[j] = 11855 elseif rtable[j] == 'v'1856 let rtable[j] = 51857 elseif rtable[j] == 'x'1858 let rtable[j] = 101859 elseif rtable[j] == 'l'1860 let rtable[j] = 501861 elseif rtable[j] == 'c'1862 let rtable[j] = 1001863 elseif rtable[j] == 'd'1864 let rtable[j] = 5001865 elseif rtable[j] == 'm'1866 let rtable[j] = 10001867 endif1868 let j += 11869 endwhile1870 let j = 01871 while j < len(rtable)1872 if get(rtable, j+1) != 0 && rtable[j] < rtable[j+1]1873 let rtable[j] = rtable[j] * -11874 endif1875 let j += 11876 endwhile1877 1878 exe 'let total = '.join(rtable, '+')1879 let number = ' start="'.total.'"'1880 else1881 let number = ' start="'.(char2nr(start)-96).'"'1882 endif1883 1884 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:ol class="'.ostyle.VST_AddClass(i,0,' ','').'"'.number.'>', i)1885 call insert(g:pindent, g:pindent[i], i)1886 call insert(g:ptype, 'olbegin', i)1887 call insert(g:plinen, 0, i)1888 1889 " Recompensate inserted paragraph before current position.1890 let i += 11891 1892 break1893 else1894 if g:ptype[j] == 'blockquote'1895 if g:pindent[j] == g:pindent[i] + listindent1896 let g:ptype[j] = 'p'1897 endif1898 endif1899 endif1900 let j += 11901 endwhile1902 1903 " LISTDEF:1904 1905 let space = matchstr(g:paras[i], '^\s*')1906 if ostyle == 'upperroman'1907 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?\(I\|[ICDVLMX]\{2,}\|#\)[\]:.)}]\s*')1908 elseif ostyle == 'lowerroman'1909 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?\(i\|[icdvlmx]\{2,}\|#\)[\]:.)}]\s*')1910 elseif ostyle == 'loweralpha'1911 " Allow max 2 characters for "head" of alpha lists. It will give1912 " enough combinations withoug allowing for messing with content1913 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?[a-z#]\{,2}[\]:.)}]\s*')1914 elseif ostyle == 'upperalpha'1915 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?[A-Z#]\{,2}[\]:.)}]\s*')1916 elseif ostyle == 'decimal'1917 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?[0-9#]\+[\]:.)}]\s*')1918 endif1919 for inc in range(len(elements))1920 let elements[inc] = substitute(elements[inc], '\n\s*', '\n', 'g')1921 let elements[inc] = VST_Structure(split(elements[inc], "\n"))1922 endfor1923 let g:paras[i] = '<vim:li>'.join(elements, "</vim:li>\n<vim:li>")1924 1925 endif1926 let i += 11927 endwhile1816 let i = 0 1817 while i < len(g:paras) 1818 if g:ptype[i] == 'oli' 1819 " Detect style of ordered list 1820 " LISTDEF: 1821 let style = matchstr(g:paras[i], '^\s*(\?\zs\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)\ze[\]:.)}]\s*') 1822 let listindent = strlen(matchstr(g:paras[i], '^\s*(\?\zs\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s*')) 1823 if style =~ '^\(I\|[ICDVLMX]\{2,}\)$' 1824 let ostyle = 'upperroman' 1825 elseif style =~ '^\(i\|[icdvlmx]\{2,}\)$' 1826 let ostyle = 'lowerroman' 1827 elseif style =~ '[a-z]' 1828 let ostyle = 'loweralpha' 1829 elseif style =~ '[A-Z]' 1830 let ostyle = 'upperalpha' 1831 elseif style =~ '[0-9#]' 1832 let ostyle = 'decimal' 1833 endif 1834 let j = i + 1 1835 while j < len(g:paras) 1836 if g:pindent[j] <= g:pindent[i] || g:ptype[j] == 'blank' || g:ptype[j] == 'hr' 1837 call insert(g:paras, repeat(' ' , g:pindent[j]).'</vim:li>'.repeat(' ' , g:pindent[j]).'</vim:ol class="'.ostyle.VST_AddClass(i,0,' ','').'">', j) 1838 call insert(g:pindent, g:pindent[i], j) 1839 call insert(g:ptype, 'olend', j) 1840 call insert(g:plinen, 0, j) 1841 1842 " Get number of first element 1843 " LISTDEF: 1844 let start = tolower(matchstr(g:paras[i], '^\s*(\?\zs\(\d\+\|[icdvlmxICDVLMX]\+\|[a-zA-Z]\|#\)\ze')) 1845 if start == '1' || start == 'a' || start == '#' || start == 'i' 1846 let number = '' 1847 elseif start =~ '[0-9]' 1848 let number = ' start="'.start.'"' 1849 elseif start =~ '[icdvlmx][icdvlmx]' 1850 let rtable = split(start, '\ze.') 1851 let j = 0 1852 while j < len(rtable) 1853 if rtable[j] == 'i' 1854 let rtable[j] = 1 1855 elseif rtable[j] == 'v' 1856 let rtable[j] = 5 1857 elseif rtable[j] == 'x' 1858 let rtable[j] = 10 1859 elseif rtable[j] == 'l' 1860 let rtable[j] = 50 1861 elseif rtable[j] == 'c' 1862 let rtable[j] = 100 1863 elseif rtable[j] == 'd' 1864 let rtable[j] = 500 1865 elseif rtable[j] == 'm' 1866 let rtable[j] = 1000 1867 endif 1868 let j += 1 1869 endwhile 1870 let j = 0 1871 while j < len(rtable) 1872 if get(rtable, j+1) != 0 && rtable[j] < rtable[j+1] 1873 let rtable[j] = rtable[j] * -1 1874 endif 1875 let j += 1 1876 endwhile 1877 1878 exe 'let total = '.join(rtable, '+') 1879 let number = ' start="'.total.'"' 1880 else 1881 let number = ' start="'.(char2nr(start)-96).'"' 1882 endif 1883 1884 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:ol class="'.ostyle.VST_AddClass(i,0,' ','').'"'.number.'>', i) 1885 call insert(g:pindent, g:pindent[i], i) 1886 call insert(g:ptype, 'olbegin', i) 1887 call insert(g:plinen, 0, i) 1888 1889 " Recompensate inserted paragraph before current position. 1890 let i += 1 1891 1892 break 1893 else 1894 if g:ptype[j] == 'blockquote' 1895 if g:pindent[j] == g:pindent[i] + listindent 1896 let g:ptype[j] = 'p' 1897 endif 1898 endif 1899 endif 1900 let j += 1 1901 endwhile 1902 1903 " LISTDEF: 1904 1905 let space = matchstr(g:paras[i], '^\s*') 1906 if ostyle == 'upperroman' 1907 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?\(I\|[ICDVLMX]\{2,}\|#\)[\]:.)}]\s*') 1908 elseif ostyle == 'lowerroman' 1909 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?\(i\|[icdvlmx]\{2,}\|#\)[\]:.)}]\s*') 1910 elseif ostyle == 'loweralpha' 1911 " Allow max 2 characters for "head" of alpha lists. It will give 1912 " enough combinations withoug allowing for messing with content 1913 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?[a-z#]\{,2}[\]:.)}]\s*') 1914 elseif ostyle == 'upperalpha' 1915 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?[A-Z#]\{,2}[\]:.)}]\s*') 1916 elseif ostyle == 'decimal' 1917 let elements = split(g:paras[i], '\(^\|\n\)\s*(\?[0-9#]\+[\]:.)}]\s*') 1918 endif 1919 for inc in range(len(elements)) 1920 let elements[inc] = substitute(elements[inc], '\n\s*', '\n', 'g') 1921 let elements[inc] = VST_Structure(split(elements[inc], "\n")) 1922 endfor 1923 let g:paras[i] = '<vim:li>'.join(elements, "</vim:li>\n<vim:li>") 1924 1925 endif 1926 let i += 1 1927 endwhile 1928 1928 endif 1929 1929 " }}} 1930 1930 " Create internal anchors - intlink (.. _blah blah:){{{ 1931 1931 if string(g:ptype) =~ "'intlink'" 1932 let i = 01933 while i < len(g:paras)1934 if g:ptype[i] == 'intlink'1935 " Testing for links broken into multiple lines1936 if len(substitute(g:paras[i], '^\s*\.\. _.\{-}:\_s*', '', '')) == 01937 let title = tolower(matchstr(g:paras[i], '^\s*\.\. _\zs.\{-}\ze:'))1938 let g:paras[i] = "\n".'<vim:p id="l'.VST_IdMaker(title).'"></vim:p>'."\n"1939 else1940 let g:paras[i] = ''1941 endif1942 endif1943 let i += 11944 endwhile1932 let i = 0 1933 while i < len(g:paras) 1934 if g:ptype[i] == 'intlink' 1935 " Testing for links broken into multiple lines 1936 if len(substitute(g:paras[i], '^\s*\.\. _.\{-}:\_s*', '', '')) == 0 1937 let title = tolower(matchstr(g:paras[i], '^\s*\.\. _\zs.\{-}\ze:')) 1938 let g:paras[i] = "\n".'<vim:p id="l'.VST_IdMaker(title).'"></vim:p>'."\n" 1939 else 1940 let g:paras[i] = '' 1941 endif 1942 endif 1943 let i += 1 1944 endwhile 1945 1945 endif 1946 1946 " }}} 1947 1947 " Create table of contents - toc (.. contents::) {{{ 1948 1948 if string(g:ptype) =~ "'toc'" 1949 let i = 01950 while i < len(g:paras)1951 if g:ptype[i] == 'toc'1952 let b:IsTOC = 11953 if matchstr(g:paras[i], '\n\s*:depth:') != ''1954 " This juggling is necessary to make corrections on different1955 " treating of TOC levels in LaTeX and HTML.1956 let depth = matchstr(g:paras[i], '\n\s*:depth:\s*\zs\d\+\ze') + 11957 let s:vst_tocdepth = depth - 11958 let g:paras[i] = substitute(g:paras[i], '\s*:depth:.\{-}\(\n\|$\)', '', 'g')1959 endif1960 if matchstr(g:paras[i], '\n\s*:class:') != ''1961 let tocclass = 'toc '.VST_IdMaker(matchstr(g:paras[i], '\n\s*:class:\s*\zs.\{-1,}\ze\s*\(\n\|$\)'))1962 let g:paras[i] = substitute(g:paras[i], '\s*:class:.\{-}\(\n\|$\)', '', 'g')1963 else1964 let tocclass = 'toc'1965 endif1966 if matchstr(g:paras[i], '::\s*\zs.\{-}\ze\(\n\|$\)') != ''1967 " Alternative title of toc1968 let toc = '<vim:p id="tocheader" class="'.tocclass.'">'.matchstr(g:paras[i], '::\s*\zs.\{-}\ze\(\n\|$\)')."<\/vim:p>\n"1969 else1970 let toc = "<vim:p id=\"tocheader\" class=\"".tocclass."\">Contents<\/vim:p>\n"1971 endif1972 let toc .= "<vim:ul class=\"".tocclass."\">\n"1973 let j = 01974 while j < len(g:paras)1975 if g:ptype[j] =~ '^h\d'1976 let hdepth = strpart(g:ptype[j], '1')1977 if exists('depth') && depth != ''1978 if hdepth > depth1979 let j += 11980 continue1981 endif1982 endif1983 let g:paras[j] = VST_SpecCharacter(g:paras[j])1984 let stitle = matchstr(g:paras[j], '^\s*\zs.*\ze\n')1985 let htitle = VST_IdMaker(tolower(stitle))1986 let tocli = repeat(' ', hdepth).'<vim:li class="'.g:ptype[j].'" id="toc-l'.htitle.'"><vim:a href="#l'.htitle.'">'.stitle.'</vim:a></vim:li>'1987 let toc .= tocli."\n"1988 endif1989 let j += 11990 endwhile1991 let toc .= "<\/vim:ul class=\"toc\">\n<vim:!--.. comment:: end of toc -->"1992 let g:paras[i] = toc1993 endif1994 let i += 11995 endwhile1949 let i = 0 1950 while i < len(g:paras) 1951 if g:ptype[i] == 'toc' 1952 let b:IsTOC = 1 1953 if matchstr(g:paras[i], '\n\s*:depth:') != '' 1954 " This juggling is necessary to make corrections on different 1955 " treating of TOC levels in LaTeX and HTML. 1956 let depth = matchstr(g:paras[i], '\n\s*:depth:\s*\zs\d\+\ze') + 1 1957 let s:vst_tocdepth = depth - 1 1958 let g:paras[i] = substitute(g:paras[i], '\s*:depth:.\{-}\(\n\|$\)', '', 'g') 1959 endif 1960 if matchstr(g:paras[i], '\n\s*:class:') != '' 1961 let tocclass = 'toc '.VST_IdMaker(matchstr(g:paras[i], '\n\s*:class:\s*\zs.\{-1,}\ze\s*\(\n\|$\)')) 1962 let g:paras[i] = substitute(g:paras[i], '\s*:class:.\{-}\(\n\|$\)', '', 'g') 1963 else 1964 let tocclass = 'toc' 1965 endif 1966 if matchstr(g:paras[i], '::\s*\zs.\{-}\ze\(\n\|$\)') != '' 1967 " Alternative title of toc 1968 let toc = '<vim:p id="tocheader" class="'.tocclass.'">'.matchstr(g:paras[i], '::\s*\zs.\{-}\ze\(\n\|$\)')."<\/vim:p>\n" 1969 else 1970 let toc = "<vim:p id=\"tocheader\" class=\"".tocclass."\">Contents<\/vim:p>\n" 1971 endif 1972 let toc .= "<vim:ul class=\"".tocclass."\">\n" 1973 let j = 0 1974 while j < len(g:paras) 1975 if g:ptype[j] =~ '^h\d' 1976 let hdepth = strpart(g:ptype[j], '1') 1977 if exists('depth') && depth != '' 1978 if hdepth > depth 1979 let j += 1 1980 continue 1981 endif 1982 endif 1983 let g:paras[j] = VST_SpecCharacter(g:paras[j]) 1984 let stitle = matchstr(g:paras[j], '^\s*\zs.*\ze\n') 1985 let htitle = VST_IdMaker(tolower(stitle)) 1986 let tocli = repeat(' ', hdepth).'<vim:li class="'.g:ptype[j].'" id="toc-l'.htitle.'"><vim:a href="#l'.htitle.'">'.stitle.'</vim:a></vim:li>' 1987 let toc .= tocli."\n" 1988 endif 1989 let j += 1 1990 endwhile 1991 let toc .= "<\/vim:ul class=\"toc\">\n<vim:!--.. comment:: end of toc -->" 1992 let g:paras[i] = toc 1993 endif 1994 let i += 1 1995 endwhile 1996 1996 endif 1997 1997 " }}} … … 1999 1999 let i = 0 2000 2000 while i < len(g:paras) 2001 if g:ptype[i] =~ '^h\d'2002 if g:ptype[i] == 'h1' && !exists("g:vst_doc_title")2003 let g:vst_doc_title = substitute(g:paras[i], '^.*\zs\n.*$', '', '')2004 endif2005 let g:paras[i] = VST_SpecCharacter(g:paras[i])2006 let stitle = tolower(matchstr(g:paras[i], '^\s*\zs.*\ze\n'))2007 let stitle = VST_IdMaker(stitle)2008 let g:paras[i] = substitute(g:paras[i], '^.*\zs\n.*$', '</vim:'.g:ptype[i].'>', '')2009 let g:paras[i] = substitute(g:paras[i], '^\s*', '\0<vim:'.g:ptype[i].VST_AddClass(i,1,' ','').' id="l'.stitle.'">', '')2010 endif2011 let i += 12001 if g:ptype[i] =~ '^h\d' 2002 if g:ptype[i] == 'h1' && !exists("g:vst_doc_title") 2003 let g:vst_doc_title = substitute(g:paras[i], '^.*\zs\n.*$', '', '') 2004 endif 2005 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 2006 let stitle = tolower(matchstr(g:paras[i], '^\s*\zs.*\ze\n')) 2007 let stitle = VST_IdMaker(stitle) 2008 let g:paras[i] = substitute(g:paras[i], '^.*\zs\n.*$', '</vim:'.g:ptype[i].'>', '') 2009 let g:paras[i] = substitute(g:paras[i], '^\s*', '\0<vim:'.g:ptype[i].VST_AddClass(i,1,' ','').' id="l'.stitle.'">', '') 2010 endif 2011 let i += 1 2012 2012 endwhile 2013 2013 " }}} 2014 2014 " Create document title (.. title::) {{{ 2015 2015 if string(g:ptype) =~ "'title'" 2016 let i = 02017 while i < len(g:paras)2018 if g:ptype[i] == 'title'2019 let g:vst_doc_title = substitute(g:paras[i], '^\s*\.\. title::\s*', '', '')2020 let g:paras[i] = ''2021 endif2022 let i += 12023 endwhile2016 let i = 0 2017 while i < len(g:paras) 2018 if g:ptype[i] == 'title' 2019 let g:vst_doc_title = substitute(g:paras[i], '^\s*\.\. title::\s*', '', '') 2020 let g:paras[i] = '' 2021 endif 2022 let i += 1 2023 endwhile 2024 2024 endif 2025 2025 " }}} 2026 2026 " Create verse paragraphs ("| ") {{{ 2027 2027 if string(g:ptype) =~ "'verse'" 2028 let i = 02029 while i < len(g:paras)2030 if g:ptype[i] == 'verse'2031 let g:paras[i] = VST_SpecCharacter(g:paras[i])2032 let g:paras[i] = VST_CreateVerse(g:paras[i])2033 2034 let g:paras[i] = substitute(g:paras[i], '<vim:p class="verse', '\0'.VST_AddClass(i,0, ' ',''), '')2035 endif2036 let i += 12037 endwhile2028 let i = 0 2029 while i < len(g:paras) 2030 if g:ptype[i] == 'verse' 2031 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 2032 let g:paras[i] = VST_CreateVerse(g:paras[i]) 2033 2034 let g:paras[i] = substitute(g:paras[i], '<vim:p class="verse', '\0'.VST_AddClass(i,0, ' ',''), '') 2035 endif 2036 let i += 1 2037 endwhile 2038 2038 endif 2039 2039 " }}} 2040 2040 " Create raw LaTeX paragraph (next after .. raw:: latex) {{{ 2041 2041 if string(g:ptype) =~ "'rawlatexcontent'" 2042 let i = 02043 while i < len(g:paras)2044 if g:ptype[i] == 'rawlatexcontent'2045 let class = VST_AddClass(i,1, ' ', '')2046 let g:paras[i] = "<vim:rawlatex".class.">\n".VST_ProtectLiteral(g:paras[i])."\n</vim:rawlatex>"2047 endif2048 let i += 12049 endwhile2042 let i = 0 2043 while i < len(g:paras) 2044 if g:ptype[i] == 'rawlatexcontent' 2045 let class = VST_AddClass(i,1, ' ', '') 2046 let g:paras[i] = "<vim:rawlatex".class.">\n".VST_ProtectLiteral(g:paras[i])."\n</vim:rawlatex>" 2047 endif 2048 let i += 1 2049 endwhile 2050 2050 endif 2051 2051 " }}} 2052 2052 " Create raw HTML paragraph (next after .. raw:: html) {{{ 2053 2053 if string(g:ptype) =~ "'rawhtmlcontent'" 2054 let i = 02055 while i < len(g:paras)2056 if g:ptype[i] == 'rawhtmlcontent'2057 let g:paras[i] = "<vim:rawhtml>\n".VST_ProtectLiteral(g:paras[i])."\n</vim:rawhtml>"2058 endif2059 let i += 12060 endwhile2054 let i = 0 2055 while i < len(g:paras) 2056 if g:ptype[i] == 'rawhtmlcontent' 2057 let g:paras[i] = "<vim:rawhtml>\n".VST_ProtectLiteral(g:paras[i])."\n</vim:rawhtml>" 2058 endif 2059 let i += 1 2060 endwhile 2061 2061 endif 2062 2062 " }}} 2063 2063 " Create raw both paragraph (next after .. raw:: <both>) {{{ 2064 2064 if string(g:ptype) =~ "'rawbothcontent'" 2065 let i = 02066 while i < len(g:paras)2067 if g:ptype[i] == 'rawbothcontent'2068 let g:paras[i] = "<vim:rawboth>\n".g:paras[i]."\n</vim:rawboth>"2069 endif2070 let i += 12071 endwhile2065 let i = 0 2066 while i < len(g:paras) 2067 if g:ptype[i] == 'rawbothcontent' 2068 let g:paras[i] = "<vim:rawboth>\n".g:paras[i]."\n</vim:rawboth>" 2069 endif 2070 let i += 1 2071 endwhile 2072 2072 endif 2073 2073 " }}} 2074 2074 " Create LaTeX only paragraph - latexonly (.. raw:: latex) {{{ 2075 2075 if string(g:ptype) =~ "'latexonly'" 2076 let i = 02077 while i < len(g:paras)2078 if g:ptype[i] == 'latexonly'2079 let g:paras[i] = substitute(g:paras[i], '\(\s*\)$', '\n\1</vim:latexonly>', '')2080 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. latexonly::\s*\n', '\n\1<vim:latexonly>\n', '')2081 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. latexonly::', '\n\1<vim:latexonly>\n', '')2082 endif2083 let i += 12084 endwhile2076 let i = 0 2077 while i < len(g:paras) 2078 if g:ptype[i] == 'latexonly' 2079 let g:paras[i] = substitute(g:paras[i], '\(\s*\)$', '\n\1</vim:latexonly>', '') 2080 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. latexonly::\s*\n', '\n\1<vim:latexonly>\n', '') 2081 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. latexonly::', '\n\1<vim:latexonly>\n', '') 2082 endif 2083 let i += 1 2084 endwhile 2085 2085 endif 2086 2086 " }}} 2087 2087 " Create HTML only paragraph - htmlonly (.. raw:: html) {{{ 2088 2088 if string(g:ptype) =~ "'htmlonly'" 2089 let i = 02090 while i < len(g:paras)2091 if g:ptype[i] == 'htmlonly'2092 let g:paras[i] = substitute(g:paras[i], '\(\s*\)$', '\n\1</vim:htmlonly>', '')2093 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. htmlonly::\s*\n', '\n\1<vim:htmlonly>\n', '')2094 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. htmlonly::', '\n\1<vim:htmlonly>\n', '')2095 endif2096 let i += 12097 endwhile2089 let i = 0 2090 while i < len(g:paras) 2091 if g:ptype[i] == 'htmlonly' 2092 let g:paras[i] = substitute(g:paras[i], '\(\s*\)$', '\n\1</vim:htmlonly>', '') 2093 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. htmlonly::\s*\n', '\n\1<vim:htmlonly>\n', '') 2094 let g:paras[i] = substitute(g:paras[i], '^\(\s*\)\.\. htmlonly::', '\n\1<vim:htmlonly>\n', '') 2095 endif 2096 let i += 1 2097 endwhile 2098 2098 endif 2099 2099 " }}} 2100 2100 " Check and embrace paragraphs in blockquote tags {{{ 2101 2101 if string(g:ptype) =~ "'blockquote'" 2102 let i = 02103 while i < len(g:paras)2104 if g:ptype[i] == 'blockquote'2105 let j = i + 12106 while j < len(g:paras)2107 let noteindent = g:pindent[j] - g:pindent[i]2108 if g:pindent[i] > g:pindent[j] || g:ptype[j] == 'blank' || g:ptype[j] == 'notend'2109 call insert(g:paras, repeat(' ' , g:pindent[i]).'</vim:blockquote>', j)2110 call insert(g:pindent, g:pindent[i], j)2111 call insert(g:ptype, 'blockend', j)2112 call insert(g:plinen, 0, j)2113 2114 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:blockquote'.VST_AddClass(i,1,' ', '').'>', i)2115 call insert(g:pindent, g:pindent[i], i)2116 call insert(g:ptype, 'blockbegin', i)2117 call insert(g:plinen, 0, i)2118 2119 " Recompensate inserted paragraph before current position.2120 let i += 12121 2122 " Region embraced , now I have to take care about paragraph2123 let g:ptype[i] = 'p'2124 2125 break2126 2127 endif2128 let j += 12129 endwhile2130 endif2131 let i += 12132 endwhile2102 let i = 0 2103 while i < len(g:paras) 2104 if g:ptype[i] == 'blockquote' 2105 let j = i + 1 2106 while j < len(g:paras) 2107 let noteindent = g:pindent[j] - g:pindent[i] 2108 if g:pindent[i] > g:pindent[j] || g:ptype[j] == 'blank' || g:ptype[j] == 'notend' 2109 call insert(g:paras, repeat(' ' , g:pindent[i]).'</vim:blockquote>', j) 2110 call insert(g:pindent, g:pindent[i], j) 2111 call insert(g:ptype, 'blockend', j) 2112 call insert(g:plinen, 0, j) 2113 2114 call insert(g:paras, repeat(' ' , g:pindent[i]).'<vim:blockquote'.VST_AddClass(i,1,' ', '').'>', i) 2115 call insert(g:pindent, g:pindent[i], i) 2116 call insert(g:ptype, 'blockbegin', i) 2117 call insert(g:plinen, 0, i) 2118 2119 " Recompensate inserted paragraph before current position. 2120 let i += 1 2121 2122 " Region embraced , now I have to take care about paragraph 2123 let g:ptype[i] = 'p' 2124 2125 break 2126 2127 endif 2128 let j += 1 2129 endwhile 2130 endif 2131 let i += 1 2132 endwhile 2133 2133 endif 2134 2134 " }}} 2135 2135 " Create table {{{ 2136 2136 if string(g:ptype) =~ "'table'" 2137 let i = 02138 while i < len(g:paras)2139 if g:ptype[i] =~ 'table'2140 let g:tclen = []2141 let g:thash = {}2142 let g:tabb = []2143 let g:taba = []2144 2145 let lines = split(g:paras[i], '\n')2146 let newrow = 02147 unlet! trow2148 2149 let line_count = 02150 let headfoot_counter = 02151 unlet! usedthead2152 unlet! usedtfoot2153 2154 for line in lines2155 let row = substitute(line, '^\s*\|\s*$', '', 'g')2156 if row =~ '^+'2157 if exists('trow')2158 2159 let g:tabb += [deepcopy(trow)]2160 2161 let rl = 02162 while rl < len(trow)2163 let trow[rl] = VST_SpecCharacter(trow[rl])2164 let cell = split(trow[rl], "\n")2165 let trow[rl] = VST_Structure(cell)2166 let rl += 12167 endwhile2168 2169 let g:taba += [trow]2170 2171 endif2172 if row =~ '^+=' && line_count > 02173 let headfoot_counter += 12174 endif2175 " Add head/foot structure elements to the end of last cell in2176 " row. Later switch order of elements by regexps.2177 if headfoot_counter > 0 && !exists('usedthead') && !exists('usedtfoot')2178 let g:taba[-1][-1] .= '</vim:thead>'2179 let usedthead = 12180 endif2181 if headfoot_counter > 1 && !exists('usedtfoot')2182 let g:taba[-1][-1] .= '<vim:tfoot>'2183 let usedtfoot = 12184 endif2185 let g:hf = headfoot_counter2186 let newrow = 12187 let g:thash[len(split(row, '+'))] = split(row, '+')2188 continue2189 else2190 if newrow == 12191 let trow = split(row, '\(^\| \)|\( \|$\)')2192 let newrow = 02193 else2194 let tmprow = split(row, '\(^\| \)|\( \|$\)')2195 let rl = 02196 while rl < len(tmprow)2197 let trow[rl] .= "\n".tmprow[rl]2198 let rl += 12199 endwhile2200 endif2201 endif2202 let line_count += 12203 endfor2204 2205 2206 " Get lengths of most standard cells in table, need this for testing2207 " of cells for length if they are longer2208 let g:tstandard = g:thash[max(keys(g:thash))]2209 let tl = 02210 while tl < len(g:tstandard)2211 let g:tclen += [len(g:tstandard[tl])]2212 let tl += 12213 endwhile2214 2215 " Check relative sizes of table columns2216 " I need this to declare widths of columns in LaTeX export2217 exe 'let g:sum = '.join(g:tclen, '+')2218 let g:sizes = []2219 for col in g:tclen2220 let colwidth = col*90/g:sum2221 if len(colwidth) == 12222 let colwidth = '0'.colwidth2223 endif2224 let g:sizes += [colwidth]2225 endfor2226 2227 " insertion of columns size for proper breaking of text in table cells2228 let colnumber = join(g:sizes, '+').'+'2229 2230 let tl = 02231 let g:ctable = ''2232 while tl < len(g:tabb)2233 let trow = g:tabb[tl]2234 let g:ctable .= '<vim:tr>'2235 let cn = 02236 let tcc = cn2237 while cn < len(trow)2238 let cll = trow[cn]2239 if stridx(cll, "\n") != -12240 let g:celllength = strlen(matchstr(cll, '^.\{-}\ze\n')) + 22241 else2242 let g:celllength = strlen(cll) + 22243 endif2244 let k = 02245 let tempst = 02246 while 12247 if k < 22248 let tempst += g:tclen[tcc+k] + k2249 else2250 let tempst += g:tclen[tcc+k] + 12251 endif2252 if g:celllength == tempst2253 if k > 02254 let tccplus = tcc + k2255 exe 'let g:summa = '.join(g:sizes[tcc : tccplus], '+')2256 if exists("g:vst_center_multicol") && g:vst_center_multicol != 12257 let g:ctable .= "<vim:td colspan=\"".(k+1)."\" summary=\"".g:summa."\">".g:taba[tl][cn]."</vim:td>"2258 else2259 let g:ctable .= "<vim:td colspan=\"".(k+1)."\" style=\"text-align: center;\" summary=\"".g:summa."\">".g:taba[tl][cn]."</vim:td>"2260 endif2261 else2262 let g:ctable .= "<vim:td>".g:taba[tl][cn]."</vim:td>"2263 endif2264 let tcc += k2265 break2266 else2267 let k += 12268 continue2269 endif2270 endwhile2271 let tcc += 12272 let cn += 12273 endwhile2274 let g:ctable .= "\n</vim:tr>"2275 let tl += 12276 endwhile2277 2278 2279 " Check if table is borderless2280 if g:ptype[i] == 'bltable'2281 let class = 'vstbless'2282 else2283 let class = 'vstborder'2284 endif2285 " Info about borders is awful abuse of summary...2286 let ttable = "<vim:table class=\"".class.VST_AddClass(i,0,' ','')."\" summary=\"".class."coln".colnumber."\">\n".g:ctable."</vim:table>"2287 2288 if headfoot_counter > 02289 let ttable = substitute(ttable, '<vim:table[^>]*>', '\0\n<vim:thead>', '')2290 let ttable = substitute(ttable, '\(</vim:thead>\)\(</vim:td>\n</vim:tr>\)', '\2\n\1\n', '')2291 endif2292 if headfoot_counter == 22293 let ttable = substitute(ttable, '<.vim:table>', '</vim:tfoot>\n\0', '')2294 let ttable = substitute(ttable, '\(<vim:tfoot>\)\(</vim:td>\n</vim:tr>\)', '\2\n\1\n', '')2295 endif2296 2297 let g:paras[i] = ttable2298 2299 endif2300 let i += 12301 endwhile2302 unlet! trow2303 unlet! row2137 let i = 0 2138 while i < len(g:paras) 2139 if g:ptype[i] =~ 'table' 2140 let g:tclen = [] 2141 let g:thash = {} 2142 let g:tabb = [] 2143 let g:taba = [] 2144 2145 let lines = split(g:paras[i], '\n') 2146 let newrow = 0 2147 unlet! trow 2148 2149 let line_count = 0 2150 let headfoot_counter = 0 2151 unlet! usedthead 2152 unlet! usedtfoot 2153 2154 for line in lines 2155 let row = substitute(line, '^\s*\|\s*$', '', 'g') 2156 if row =~ '^+' 2157 if exists('trow') 2158 2159 let g:tabb += [deepcopy(trow)] 2160 2161 let rl = 0 2162 while rl < len(trow) 2163 let trow[rl] = VST_SpecCharacter(trow[rl]) 2164 let cell = split(trow[rl], "\n") 2165 let trow[rl] = VST_Structure(cell) 2166 let rl += 1 2167 endwhile 2168 2169 let g:taba += [trow] 2170 2171 endif 2172 if row =~ '^+=' && line_count > 0 2173 let headfoot_counter += 1 2174 endif 2175 " Add head/foot structure elements to the end of last cell in 2176 " row. Later switch order of elements by regexps. 2177 if headfoot_counter > 0 && !exists('usedthead') && !exists('usedtfoot') 2178 let g:taba[-1][-1] .= '</vim:thead>' 2179 let usedthead = 1 2180 endif 2181 if headfoot_counter > 1 && !exists('usedtfoot') 2182 let g:taba[-1][-1] .= '<vim:tfoot>' 2183 let usedtfoot = 1 2184 endif 2185 let g:hf = headfoot_counter 2186 let newrow = 1 2187 let g:thash[len(split(row, '+'))] = split(row, '+') 2188 continue 2189 else 2190 if newrow == 1 2191 let trow = split(row, '\(^\| \)|\( \|$\)') 2192 let newrow = 0 2193 else 2194 let tmprow = split(row, '\(^\| \)|\( \|$\)') 2195 let rl = 0 2196 while rl < len(tmprow) 2197 let trow[rl] .= "\n".tmprow[rl] 2198 let rl += 1 2199 endwhile 2200 endif 2201 endif 2202 let line_count += 1 2203 endfor 2204 2205 2206 " Get lengths of most standard cells in table, need this for testing 2207 " of cells for length if they are longer 2208 let g:tstandard = g:thash[max(keys(g:thash))] 2209 let tl = 0 2210 while tl < len(g:tstandard) 2211 let g:tclen += [len(g:tstandard[tl])] 2212 let tl += 1 2213 endwhile 2214 2215 " Check relative sizes of table columns 2216 " I need this to declare widths of columns in LaTeX export 2217 exe 'let g:sum = '.join(g:tclen, '+') 2218 let g:sizes = [] 2219 for col in g:tclen 2220 let colwidth = col*90/g:sum 2221 if len(colwidth) == 1 2222 let colwidth = '0'.colwidth 2223 endif 2224 let g:sizes += [colwidth] 2225 endfor 2226 2227 " insertion of columns size for proper breaking of text in table cells 2228 let colnumber = join(g:sizes, '+').'+' 2229 2230 let tl = 0 2231 let g:ctable = '' 2232 while tl < len(g:tabb) 2233 let trow = g:tabb[tl] 2234 let g:ctable .= '<vim:tr>' 2235 let cn = 0 2236 let tcc = cn 2237 while cn < len(trow) 2238 let cll = trow[cn] 2239 if stridx(cll, "\n") != -1 2240 let g:celllength = strlen(matchstr(cll, '^.\{-}\ze\n')) + 2 2241 else 2242 let g:celllength = strlen(cll) + 2 2243 endif 2244 let k = 0 2245 let tempst = 0 2246 while 1 2247 if k < 2 2248 let tempst += g:tclen[tcc+k] + k 2249 else 2250 let tempst += g:tclen[tcc+k] + 1 2251 endif 2252 if g:celllength == tempst 2253 if k > 0 2254 let tccplus = tcc + k 2255 exe 'let g:summa = '.join(g:sizes[tcc : tccplus], '+') 2256 if exists("g:vst_center_multicol") && g:vst_center_multicol != 1 2257 let g:ctable .= "<vim:td colspan=\"".(k+1)."\" summary=\"".g:summa."\">".g:taba[tl][cn]."</vim:td>" 2258 else 2259 let g:ctable .= "<vim:td colspan=\"".(k+1)."\" style=\"text-align: center;\" summary=\"".g:summa."\">".g:taba[tl][cn]."</vim:td>" 2260 endif 2261 else 2262 let g:ctable .= "<vim:td>".g:taba[tl][cn]."</vim:td>" 2263 endif 2264 let tcc += k 2265 break 2266 else 2267 let k += 1 2268 continue 2269 endif 2270 endwhile 2271 let tcc += 1 2272 let cn += 1 2273 endwhile 2274 let g:ctable .= "\n</vim:tr>" 2275 let tl += 1 2276 endwhile 2277 2278 2279 " Check if table is borderless 2280 if g:ptype[i] == 'bltable' 2281 let class = 'vstbless' 2282 else 2283 let class = 'vstborder' 2284 endif 2285 " Info about borders is awful abuse of summary... 2286 let ttable = "<vim:table class=\"".class.VST_AddClass(i,0,' ','')."\" summary=\"".class."coln".colnumber."\">\n".g:ctable."</vim:table>" 2287 2288 if headfoot_counter > 0 2289 let ttable = substitute(ttable, '<vim:table[^>]*>', '\0\n<vim:thead>', '') 2290 let ttable = substitute(ttable, '\(</vim:thead>\)\(</vim:td>\n</vim:tr>\)', '\2\n\1\n', '') 2291 endif 2292 if headfoot_counter == 2 2293 let ttable = substitute(ttable, '<.vim:table>', '</vim:tfoot>\n\0', '') 2294 let ttable = substitute(ttable, '\(<vim:tfoot>\)\(</vim:td>\n</vim:tr>\)', '\2\n\1\n', '') 2295 endif 2296 2297 let g:paras[i] = ttable 2298 2299 endif 2300 let i += 1 2301 endwhile 2302 unlet! trow 2303 unlet! row 2304 2304 endif 2305 2305 " }}} … … 2307 2307 let i = 0 2308 2308 while i < len(g:paras) 2309 if g:ptype[i] =~ 'subh\d'2310 let g:paras[i] = VST_SpecCharacter(g:paras[i])2311 let g:paras[i] = "\n".repeat(' ', g:pindent[i]).'<vim:p class="'.g:ptype[i].'">'."\n".g:paras[i]2312 " Remove last line of subtitle if this is ornament.2313 " Treatment of headers in reST is weird.2314 let g:paras[i] = substitute(g:paras[i], '\n\s*'.s:vst_headdef.'\s*$', '', '')2315 let g:paras[i] .= "\n".repeat(' ', g:pindent[i])."</vim:p>\n"2316 endif2317 let i += 12309 if g:ptype[i] =~ 'subh\d' 2310 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 2311 let g:paras[i] = "\n".repeat(' ', g:pindent[i]).'<vim:p class="'.g:ptype[i].'">'."\n".g:paras[i] 2312 " Remove last line of subtitle if this is ornament. 2313 " Treatment of headers in reST is weird. 2314 let g:paras[i] = substitute(g:paras[i], '\n\s*'.s:vst_headdef.'\s*$', '', '') 2315 let g:paras[i] .= "\n".repeat(' ', g:pindent[i])."</vim:p>\n" 2316 endif 2317 let i += 1 2318 2318 endwhile 2319 2319 " }}} 2320 2320 " Doctest paragraphs {{{ 2321 2321 if string(g:ptype) =~ "'doctest'" 2322 let i = 02323 while i < len(g:paras)2324 if g:ptype[i] == 'doctest'2325 let class = VST_AddClass(i,1, ' ', '')2326 let g:paras[i] = VST_SpecCharacter(g:paras[i])2327 let g:paras[i] = "\n".repeat(' ', g:pindent[i])."<vim:pre".class.">\n".g:paras[i]2328 let g:paras[i] .= "\n".repeat(' ', g:pindent[i])."</vim:pre>\n"2329 endif2330 let i += 12331 endwhile2322 let i = 0 2323 while i < len(g:paras) 2324 if g:ptype[i] == 'doctest' 2325 let class = VST_AddClass(i,1, ' ', '') 2326 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 2327 let g:paras[i] = "\n".repeat(' ', g:pindent[i])."<vim:pre".class.">\n".g:paras[i] 2328 let g:paras[i] .= "\n".repeat(' ', g:pindent[i])."</vim:pre>\n" 2329 endif 2330 let i += 1 2331 endwhile 2332 2332 endif 2333 2333 " }}} 2334 2334 " Simple table paragraphs {{{ 2335 2335 if string(g:ptype) =~ "'simpletbl'" 2336 let i = 02337 while i < len(g:paras)2338 2339 if g:ptype[i] == 'simpletbl'2340 2341 unlet! usedthead2342 unlet! usedtfoot2343 unlet! usethead2344 2345 let plines = split(g:paras[i], '\n')2346 let header = substitute(plines[0], '^\s\+', '', '')2347 " Remove framing === === lines2348 let plines = plines[1:-2]2349 let usethead = 02350 for j in range(len(plines))2351 let plines[j] = substitute(plines[j], '^\s\{'.g:pindent[i].'}', '', '')2352 if plines[j] =~ '^\(=\{2,}\s*\)\+$'2353 let usethead += 12354 endif2355 endfor2356 " Get width of cols {{{2357 let cols = []2358 for k in split(header, '[^=]=')2359 let cols += [len(matchstr(header, '^=*\s*'))]2360 let header = substitute(header, '^=*\s*', '', '')2361 endfor2362 " Due to nature of formatting last column may seem narrower than rest.2363 " Add 1 to slightly recompense that.2364 let cols[-1] += 12365 " Calculate percentage widths of columns.2366 exe 'let total_width = '.join(cols, '+')2367 let sizes = []2368 for col in cols2369 let colwidth = col*90/total_width2370 if len(colwidth) == 12371 let colwidth = '0'.colwidth2372 endif2373 let sizes += [colwidth]2374 endfor2375 let col_desc = join(sizes, '+').'+'2376 " }}}2377 " Split plines into separate cells {{{2378 let table = []2379 for line in plines2380 2381 let trow = []2382 2383 for k in range(len(cols))2384 if k == len(cols)-12385 let trow += [line]2386 else2387 let trow += [line[0:(cols[k]-1)]]2388 let line = line[(cols[k]):]2389 endif2390 endfor2391 2392 let table += [trow]2393 2394 endfor2395 " }}}2396 " Now create real, multiline if necessary, cells {{{2397 let rtable = []2398 for k in range(len(table))2399 2400 let row = table[k]2401 2402 if k == 02403 let prevrow = ['-----']2404 else2405 let prevrow = table[k-1]2406 endif2407 2408 if row[0] =~ '^\s*$'2409 if prevrow[0] =~ '[-=]\{2,}'2410 let addrow = 02411 else2412 let addrow = 12413 endif2414 else2415 let addrow = 02416 endif2417 2418 if addrow == 02419 let temprow = []2420 for j in range(len(cols))2421 if row[j] !~ '^[=-]\{2,}'2422 let temprow += [row[j]]2423 elseif row[j] =~ '^=\{2,}'2424 let temprow += ['-vst-thfelem-']2425 endif2426 endfor2427 let rtable += [temprow]2428 elseif addrow == 12429 for j in range(len(cols))2430 if row[j] !~ '^[=-]\{2,}'2431 let temprow[j] .= "\n".row[j]2432 elseif row[j] =~ '^=\{2,}'2433 let temprow += ['-vst-thfelem-']2434 endif2435 endfor2436 endif2437 2438 endfor2439 " }}}2440 2441 " Translate data structure into Vim reStructured Text markup2442 " Go through cells, call Structure function, join().2443 let class = VST_AddClass(i,0, ' ', '')2444 let g:paras[i] = '<vim:table class="vstborder'.class."\" summary=\"vstbordercoln".col_desc."\">\n"2445 2446 " insert thead at the beginning2447 if usethead > 02448 let g:paras[i] .= "<vim:thead>\n"2449 endif2450 2451 for k in range(len(rtable))2452 let row = rtable[k]2453 2454 if row == []2455 let k += 12456 continue2457 endif2458 2459 " Interpret text inside of cells looking for structures {{{2460 for j in range(len(row))2461 if row[j] =~ '^-vst-thfelem-$'2462 let j += 12463 continue2464 else2465 let row[j] = VST_SpecCharacter(row[j])2466 let cellt = split(row[j], "\n")2467 " Remove in-frontal space from one-line cells to avoid2468 " interpretation of text as blockquote2469 "if len(cellt) == 12470 "let cellt[0] = substitute(cellt[0], '^\s\+', '', '')2471 "endif2472 let row[j] = VST_Structure(cellt)2473 endif2474 endfor2475 " }}}2476 2477 " Create marked text and add thead and tfoot when appropriate2478 if usethead > 0 && !exists("usedthead") && join(row, '') =~ '^\(-vst-thfelem-\)\+$'2479 let g:paras[i] .= "\n</vim:thead>\n"2480 let usedthead = 12481 continue2482 endif2483 if usethead > 1 && exists("usedthead") && join(row, '') =~ '^\(-vst-thfelem-\)\+$'2484 let g:paras[i] .= "\n<vim:tfoot>\n"2485 unlet usedthead2486 let usedtfoot = 12487 continue2488 endif2489 2490 let g:paras[i] .= '<vim:tr><vim:td>'.join(row, '</vim:td><vim:td>').'</vim:td></vim:tr>'."\n"2491 2492 2493 endfor2494 2495 if exists("usedtfoot")2496 unlet usedtfoot2497 let g:paras[i] .= "\n</vim:tfoot>\n"2498 endif2499 2500 unlet! usedthead2501 unlet! usedtfoot2502 unlet! usethead2503 2504 let g:paras[i] .= '</vim:table>'2505 2506 endif2507 let i += 12508 endwhile2336 let i = 0 2337 while i < len(g:paras) 2338 2339 if g:ptype[i] == 'simpletbl' 2340 2341 unlet! usedthead 2342 unlet! usedtfoot 2343 unlet! usethead 2344 2345 let plines = split(g:paras[i], '\n') 2346 let header = substitute(plines[0], '^\s\+', '', '') 2347 " Remove framing === === lines 2348 let plines = plines[1:-2] 2349 let usethead = 0 2350 for j in range(len(plines)) 2351 let plines[j] = substitute(plines[j], '^\s\{'.g:pindent[i].'}', '', '') 2352 if plines[j] =~ '^\(=\{2,}\s*\)\+$' 2353 let usethead += 1 2354 endif 2355 endfor 2356 " Get width of cols {{{ 2357 let cols = [] 2358 for k in split(header, '[^=]=') 2359 let cols += [len(matchstr(header, '^=*\s*'))] 2360 let header = substitute(header, '^=*\s*', '', '') 2361 endfor 2362 " Due to nature of formatting last column may seem narrower than rest. 2363 " Add 1 to slightly recompense that. 2364 let cols[-1] += 1 2365 " Calculate percentage widths of columns. 2366 exe 'let total_width = '.join(cols, '+') 2367 let sizes = [] 2368 for col in cols 2369 let colwidth = col*90/total_width 2370 if len(colwidth) == 1 2371 let colwidth = '0'.colwidth 2372 endif 2373 let sizes += [colwidth] 2374 endfor 2375 let col_desc = join(sizes, '+').'+' 2376 " }}} 2377 " Split plines into separate cells {{{ 2378 let table = [] 2379 for line in plines 2380 2381 let trow = [] 2382 2383 for k in range(len(cols)) 2384 if k == len(cols)-1 2385 let trow += [line] 2386 else 2387 let trow += [line[0:(cols[k]-1)]] 2388 let line = line[(cols[k]):] 2389 endif 2390 endfor 2391 2392 let table += [trow] 2393 2394 endfor 2395 " }}} 2396 " Now create real, multiline if necessary, cells {{{ 2397 let rtable = [] 2398 for k in range(len(table)) 2399 2400 let row = table[k] 2401 2402 if k == 0 2403 let prevrow = ['-----'] 2404 else 2405 let prevrow = table[k-1] 2406 endif 2407 2408 if row[0] =~ '^\s*$' 2409 if prevrow[0] =~ '[-=]\{2,}' 2410 let addrow = 0 2411 else 2412 let addrow = 1 2413 endif 2414 else 2415 let addrow = 0 2416 endif 2417 2418 if addrow == 0 2419 let temprow = [] 2420 for j in range(len(cols)) 2421 if row[j] !~ '^[=-]\{2,}' 2422 let temprow += [row[j]] 2423 elseif row[j] =~ '^=\{2,}' 2424 let temprow += ['-vst-thfelem-'] 2425 endif 2426 endfor 2427 let rtable += [temprow] 2428 elseif addrow == 1 2429 for j in range(len(cols)) 2430 if row[j] !~ '^[=-]\{2,}' 2431 let temprow[j] .= "\n".row[j] 2432 elseif row[j] =~ '^=\{2,}' 2433 let temprow += ['-vst-thfelem-'] 2434 endif 2435 endfor 2436 endif 2437 2438 endfor 2439 " }}} 2440 2441 " Translate data structure into Vim reStructured Text markup 2442 " Go through cells, call Structure function, join(). 2443 let class = VST_AddClass(i,0, ' ', '') 2444 let g:paras[i] = '<vim:table class="vstborder'.class."\" summary=\"vstbordercoln".col_desc."\">\n" 2445 2446 " insert thead at the beginning 2447 if usethead > 0 2448 let g:paras[i] .= "<vim:thead>\n" 2449 endif 2450 2451 for k in range(len(rtable)) 2452 let row = rtable[k] 2453 2454 if row == [] 2455 let k += 1 2456 continue 2457 endif 2458 2459 " Interpret text inside of cells looking for structures {{{ 2460 for j in range(len(row)) 2461 if row[j] =~ '^-vst-thfelem-$' 2462 let j += 1 2463 continue 2464 else 2465 let row[j] = VST_SpecCharacter(row[j]) 2466 let cellt = split(row[j], "\n") 2467 " Remove in-frontal space from one-line cells to avoid 2468 " interpretation of text as blockquote 2469 "if len(cellt) == 1 2470 " let cellt[0] = substitute(cellt[0], '^\s\+', '', '') 2471 "endif 2472 let row[j] = VST_Structure(cellt) 2473 endif 2474 endfor 2475 " }}} 2476 2477 " Create marked text and add thead and tfoot when appropriate 2478 if usethead > 0 && !exists("usedthead") && join(row, '') =~ '^\(-vst-thfelem-\)\+$' 2479 let g:paras[i] .= "\n</vim:thead>\n" 2480 let usedthead = 1 2481 continue 2482 endif 2483 if usethead > 1 && exists("usedthead") && join(row, '') =~ '^\(-vst-thfelem-\)\+$' 2484 let g:paras[i] .= "\n<vim:tfoot>\n" 2485 unlet usedthead 2486 let usedtfoot = 1 2487 continue 2488 endif 2489 2490 let g:paras[i] .= '<vim:tr><vim:td>'.join(row, '</vim:td><vim:td>').'</vim:td></vim:tr>'."\n" 2491 2492 2493 endfor 2494 2495 if exists("usedtfoot") 2496 unlet usedtfoot 2497 let g:paras[i] .= "\n</vim:tfoot>\n" 2498 endif 2499 2500 unlet! usedthead 2501 unlet! usedtfoot 2502 unlet! usethead 2503 2504 let g:paras[i] .= '</vim:table>' 2505 2506 endif 2507 let i += 1 2508 endwhile 2509 2509 endif 2510 2510 " }}} … … 2512 2512 let i = 0 2513 2513 while i < len(g:paras) 2514 if g:ptype[i] == 'p'2515 let g:paras[i] = VST_SpecCharacter(g:paras[i])2516 if g:paras[i] =~ '^\s\+---\?\s.*\S' && g:ptype[i+1] == 'blockend'2517 let class = VST_AddClass(i,0, '', '')2518 let g:paras[i] = "\n".repeat(' ', g:pindent[i])."<vim:p class=\"attribution".class."\">\n".g:paras[i]2519 else2520 let class = VST_AddClass(i,1, ' ', '')2521 let g:paras[i] = "\n".repeat(' ', g:pindent[i])."<vim:p".class.">\n".g:paras[i]2522 endif2523 let g:paras[i] .= "\n".repeat(' ', g:pindent[i])."</vim:p>\n"2524 endif2525 let i += 12514 if g:ptype[i] == 'p' 2515 let g:paras[i] = VST_SpecCharacter(g:paras[i]) 2516 if g:paras[i] =~ '^\s\+---\?\s.*\S' && g:ptype[i+1] == 'blockend' 2517 let class = VST_AddClass(i,0, '', '') 2518 let g:paras[i] = "\n".repeat(' ', g:pindent[i])."<vim:p class=\"attribution".class."\">\n".g:paras[i] 2519 else 2520 let class = VST_AddClass(i,1, ' ', '') 2521 let g:paras[i] = "\n".repeat(' ', g:pindent[i])."<vim:p".class.">\n".g:paras[i] 2522 endif 2523 let g:paras[i] .= "\n".repeat(' ', g:pindent[i])."</vim:p>\n" 2524 endif 2525 let i += 1 2526 2526 endwhile 2527 2527 " }}} 2528 2528 " Insert raw files placeholders {{{ 2529 2529 if string(g:ptype) =~ "'raw\(latex\|html\|both\)'" 2530 let i = 02531 while i < len(g:paras)2532 if g:ptype[i] =~ '^raw\(latex\|html\|both\)$'2533 if g:paras[i] =~ ':file:'2534 let file = matchstr(g:paras[i], ':file:\s*\zs.*')2535 let g:paras[i] = '-vst-raw-file-placeholder:'.VST_ProtectLiteral(file)2536 else2537 let g:paras[i] = ''2538 endif2539 endif2540 let i += 12541 endwhile2530 let i = 0 2531 while i < len(g:paras) 2532 if g:ptype[i] =~ '^raw\(latex\|html\|both\)$' 2533 if g:paras[i] =~ ':file:' 2534 let file = matchstr(g:paras[i], ':file:\s*\zs.*') 2535 let g:paras[i] = '-vst-raw-file-placeholder:'.VST_ProtectLiteral(file) 2536 else 2537 let g:paras[i] = '' 2538 endif 2539 endif 2540 let i += 1 2541 endwhile 2542 2542 endif 2543 2543 " }}} 2544 2544 " Insert MED-classes {{{ 2545 2545 if string(g:ptype) =~ "'MED-class'" 2546 let i = 02547 while i < len(g:paras)2548 if i == len(doc) - 12549 let nextline = i - 12550 else2551 let nextline = i + 12552 endif2553 if g:ptype[i] == 'MED-class' && g:ptype[nextline] != 'notend'2554 let name = g:paras[i]2555 let j = i + 12556 while j < len(g:paras)2557 if g:ptype[j] == 'notend' && g:pindent[j] == g:pindent[i] && g:paras[j] =~ '^\s*<vim:class'.name2558 let g:paras[j] = ''2559 break2560 else2561 if g:ptype[j] !~ '^[uo]li$'2562 let initial = matchstr(g:paras[j], '^\_s*\zs<vim:\w\+[^>]*>')2563 if initial !~ 'class\s*=\s*[''"]'2564 let final = substitute(initial, '\(/\)\?>', ' class="'.name.'" \1>', '')2565 elseif initial =~ 'class\s*=\s*[''"]'2566 let final = substitute(initial, '\(class\s*=\s*\)\([''"]\)\(.\{-}\)\2', '\1\2\3 '.name.'\2', '')2567 endif2568 let g:paras[j] = substitute(g:paras[j], initial, final, '')2569 endif2570 let j += 12571 endif2572 endwhile2573 endif2574 let i += 12575 endwhile2546 let i = 0 2547 while i < len(g:paras) 2548 if i == len(doc) - 1 2549 let nextline = i - 1 2550 else 2551 let nextline = i + 1 2552 endif 2553 if g:ptype[i] == 'MED-class' && g:ptype[nextline] != 'notend' 2554 let name = g:paras[i] 2555 let j = i + 1 2556 while j < len(g:paras) 2557 if g:ptype[j] == 'notend' && g:pindent[j] == g:pindent[i] && g:paras[j] =~ '^\s*<vim:class'.name 2558 let g:paras[j] = '' 2559 break 2560 else 2561 if g:ptype[j] !~ '^[uo]li$' 2562 let initial = matchstr(g:paras[j], '^\_s*\zs<vim:\w\+[^>]*>') 2563 if initial !~ 'class\s*=\s*[''"]' 2564 let final = substitute(initial, '\(/\)\?>', ' class="'.name.'" \1>', '') 2565 elseif initial =~ 'class\s*=\s*[''"]' 2566 let final = substitute(initial, '\(class\s*=\s*\)\([''"]\)\(.\{-}\)\2', '\1\2\3 '.name.'\2', '') 2567 endif 2568 let g:paras[j] = substitute(g:paras[j], initial, final, '') 2569 endif 2570 let j += 1 2571 endif 2572 endwhile 2573 endif 2574 let i += 1 2575 endwhile 2576 2576 endif 2577 2577 " }}} … … 2579 2579 let i = 0 2580 2580 while i < len(g:paras) 2581 if g:ptype[i] == 'link'2582 let g:paras[i] = ''2583 elseif g:ptype[i] == 'anonlink'2584 let g:paras[i] = ''2585 elseif g:ptype[i] == 'replacement'2586 let g:paras[i] = ''2587 elseif g:ptype[i] == 'rawhtml'2588 let g:paras[i] = ''2589 elseif g:ptype[i] == 'rawlatex'2590 let g:paras[i] = ''2591 elseif g:ptype[i] == 'rawboth'2592 let g:paras[i] = ''2593 elseif g:ptype[i] == 'emptypre'2594 let g:paras[i] = ''2595 elseif g:ptype[i] == 'role'2596 let g:paras[i] = ''2597 elseif g:ptype[i] == 'MED-class'2598 let g:paras[i] = ''2599 endif2600 let i += 12581 if g:ptype[i] == 'link' 2582 let g:paras[i] = '' 2583 elseif g:ptype[i] == 'anonlink' 2584 let g:paras[i] = '' 2585 elseif g:ptype[i] == 'replacement' 2586 let g:paras[i] = '' 2587 elseif g:ptype[i] == 'rawhtml' 2588 let g:paras[i] = '' 2589 elseif g:ptype[i] == 'rawlatex' 2590 let g:paras[i] = '' 2591 elseif g:ptype[i] == 'rawboth' 2592 let g:paras[i] = '' 2593 elseif g:ptype[i] == 'emptypre' 2594 let g:paras[i] = '' 2595 elseif g:ptype[i] == 'role' 2596 let g:paras[i] = '' 2597 elseif g:ptype[i] == 'MED-class' 2598 let g:paras[i] = '' 2599 endif 2600 let i += 1 2601 2601 endwhile 2602 2602 " }}} … … 2604 2604 let i = 0 2605 2605 while i < len(g:paras) 2606 " Careful checking if given construct exists in paragraph.2607 " BIG speed gains.2608 if g:ptype[i] !~ '^pre\|^hr\|^blank'2609 if g:paras[i] =~ '|'2610 let g:paras[i] = VST_Replacement(g:paras[i])2611 endif2612 if g:paras[i] =~ '[*`=]'2613 let g:paras[i] = VST_Markup(g:paras[i])2614 endif2615 if g:paras[i] =~ ':`' || g:paras[i] =~ '`:'2616 let g:paras[i] = VST_Roles(g:paras[i])2617 endif2618 if g:paras[i] =~ '\[\d\+\]_'2619 let g:paras[i] = VST_Footnotes(g:paras[i])2620 endif2621 if g:paras[i] =~ 'http' || g:paras[i] =~ 'mailto' || g:paras[i] =~ 'ftp'2622 let g:paras[i] = VST_SA_Hyperlink(g:paras[i])2623 endif2624 if g:paras[i] =~ '\[#\k\+\]_'2625 let g:paras[i] = VST_LabelFootnote(g:paras[i])2626 endif2627 if g:paras[i] =~ '\[\k\+\]_'2628 let g:paras[i] = VST_Citations(g:paras[i])2629 endif2630 endif2631 let i += 12606 " Careful checking if given construct exists in paragraph. 2607 " BIG speed gains. 2608 if g:ptype[i] !~ '^pre\|^hr\|^blank' 2609 if g:paras[i] =~ '|' 2610 let g:paras[i] = VST_Replacement(g:paras[i]) 2611 endif 2612 if g:paras[i] =~ '[*`=]' 2613 let g:paras[i] = VST_Markup(g:paras[i]) 2614 endif 2615 if g:paras[i] =~ ':`' || g:paras[i] =~ '`:' 2616 let g:paras[i] = VST_Roles(g:paras[i]) 2617 endif 2618 if g:paras[i] =~ '\[\d\+\]_' 2619 let g:paras[i] = VST_Footnotes(g:paras[i]) 2620 endif 2621 if g:paras[i] =~ 'http' || g:paras[i] =~ 'mailto' || g:paras[i] =~ 'ftp' 2622 let g:paras[i] = VST_SA_Hyperlink(g:paras[i]) 2623 endif 2624 if g:paras[i] =~ '\[#\k\+\]_' 2625 let g:paras[i] = VST_LabelFootnote(g:paras[i]) 2626 endif 2627 if g:paras[i] =~ '\[\k\+\]_' 2628 let g:paras[i] = VST_Citations(g:paras[i]) 2629 endif 2630 endif 2631 let i += 1 2632 2632 endwhile 2633 2633 " }}} … … 2668 2668 " Remove links created inside of image src 2669 2669 let file = substitute(file, '<\(vim:\)\?img\([^>]\{-}\)src="<vim:a href=".\{-}">\([^<]*\)</vim:a>"', 2670 \ '<\1img\2src="\3"', 'g')2671 " let file = substitute(file, ' \n', '', 'g')2670 \ '<\1img\2src="\3"', 'g') 2671 " let file = substitute(file, ' \n', '', 'g') 2672 2672 " Remove too much of empty space at the end of footnotes 2673 2673 let file = substitute(file, '\n\(</vim:div></vim:footnote>\)', '\1', 'g') … … 2677 2677 " Restore structure from temporary variables {{{ 2678 2678 if len(g:paras_rez) > 0 2679 let g:paras = g:paras_rez[-1]2680 call remove(g:paras_rez, -1)2679 let g:paras = g:paras_rez[-1] 2680 call remove(g:paras_rez, -1) 2681 2681 endif 2682 2682 if len(g:ptype_rez) > 0 2683 let g:ptype = g:ptype_rez[-1]2684 call remove(g:ptype_rez, -1)2683 let g:ptype = g:ptype_rez[-1] 2684 call remove(g:ptype_rez, -1) 2685 2685 endif 2686 2686 if len(g:pindent_rez) > 0 2687 let g:pindent = g:pindent_rez[-1]2688 call remove(g:pindent_rez, -1)2687 let g:pindent = g:pindent_rez[-1] 2688 call remove(g:pindent_rez, -1) 2689 2689 endif 2690 2690 if len(g:plinen_rez) > 0 2691 let g:plinen = g:plinen_rez[-1]2692 call remove(g:plinen_rez, -1)2691 let g:plinen = g:plinen_rez[-1] 2692 call remove(g:plinen_rez, -1) 2693 2693 endif 2694 2694 " }}} … … 2703 2703 " VST_DictTable: creation of nice looking table from dictionary {{{ 2704 2704 " Description: Go through all key value pairs and create nicely looking table 2705 " db: dictionary itself2705 " db: dictionary itself 2706 2706 " key: header of key column 2707 2707 " value: header of value column … … 2709 2709 function! VST_DictTable(db, key, value, sort) 2710 2710 2711 let valmargin = 202712 let dict = a:db2713 let table = a:key.repeat(' ', valmargin-strlen(a:key)).a:value."\n"2714 if a:sort == 02715 for key in keys(dict)2716 if dict[key] !~ '^\s*$'2717 if valmargin - strlen(key) < 12718 let table .= key."\n".repeat(' ', valmargin).substitute(dict[key], '\n', ' ', 'g')."\n"2719 else2720 let table .= key.repeat(' ', valmargin - strlen(key)).substitute(dict[key], '\n', ' ', 'g')."\n"2721 endif2722 endif2723 endfor2724 else2725 for key in sort(keys(dict))2726 if dict[key] !~ '^\s*$'2727 if valmargin - strlen(key) < 12728 let table .= key."\n".repeat(' ', valmargin).substitute(dict[key], '\n', ' ', 'g')."\n"2729 else2730 let table .= key.repeat(' ', valmargin - strlen(key)).substitute(dict[key], '\n', ' ', 'g')."\n"2731 endif2732 endif2733 endfor2734 endif2735 2736 "return table2737 call input(table)2738 "echo table2711 let valmargin = 20 2712 let dict = a:db 2713 let table = a:key.repeat(' ', valmargin-strlen(a:key)).a:value."\n" 2714 if a:sort == 0 2715 for key in keys(dict) 2716 if dict[key] !~ '^\s*$' 2717 if valmargin - strlen(key) < 1 2718 let table .= key."\n".repeat(' ', valmargin).substitute(dict[key], '\n', ' ', 'g')."\n" 2719 else 2720 let table .= key.repeat(' ', valmargin - strlen(key)).substitute(dict[key], '\n', ' ', 'g')."\n" 2721 endif 2722 endif 2723 endfor 2724 else 2725 for key in sort(keys(dict)) 2726 if dict[key] !~ '^\s*$' 2727 if valmargin - strlen(key) < 1 2728 let table .= key."\n".repeat(' ', valmargin).substitute(dict[key], '\n', ' ', 'g')."\n" 2729 else 2730 let table .= key.repeat(' ', valmargin - strlen(key)).substitute(dict[key], '\n', ' ', 'g')."\n" 2731 endif 2732 endif 2733 endfor 2734 endif 2735 2736 "return table 2737 call input(table) 2738 "echo table 2739 2739 2740 2740 endfunction … … 2743 2743 " Description: Go through all 3 element items in list and render them in 2744 2744 " nicely looking table 2745 " list: list itself2745 " list: list itself 2746 2746 " fcol: header of first column 2747 2747 " scol: header of second column … … 2750 2750 function! VST_TocTable(list, fcol, scol, tcol, sinfo) 2751 2751 2752 let secmargin = 152753 let thdmargin = 402754 let table = a:fcol.repeat(' ', secmargin-len(a:fcol))2755 \ .a:scol.repeat(' ',thdmargin-len(a:scol)).a:tcol."\n"2756 2757 let i = 02758 while i < len(a:list)2759 let [level, title, line] = a:list[i]2760 let title = substitute(title, '\n.\{-}$', '', '')2761 " Add a markers around name of section were cursor is2762 if !exists("a:list[i+1]")2763 let nextsection = line('$')2764 else2765 let nextsection = a:list[i+1][2]2766 endif2767 let title = b:vst_toc_numbers[title].' '.substitute(title, '^\s\+', '', '')2768 if a:sinfo >= line && a:sinfo < nextsection2769 let title = '[[[ '.title.' ]]]'2770 endif2771 let table .= level.' '.g:vst_headers[level].' '2772 \ .repeat(' ', secmargin-len(level.g:vst_headers[level].' '))2773 \ .title.repeat(' ', thdmargin-len(title)).' '.line."\n"2774 let i += 12775 endwhile2776 2777 return table2752 let secmargin = 15 2753 let thdmargin = 40 2754 let table = a:fcol.repeat(' ', secmargin-len(a:fcol)) 2755 \ .a:scol.repeat(' ',thdmargin-len(a:scol)).a:tcol."\n" 2756 2757 let i = 0 2758 while i < len(a:list) 2759 let [level, title, line] = a:list[i] 2760 let title = substitute(title, '\n.\{-}$', '', '') 2761 " Add a markers around name of section were cursor is 2762 if !exists("a:list[i+1]") 2763 let nextsection = line('$') 2764 else 2765 let nextsection = a:list[i+1][2] 2766 endif 2767 let title = b:vst_toc_numbers[title].' '.substitute(title, '^\s\+', '', '') 2768 if a:sinfo >= line && a:sinfo < nextsection 2769 let title = '[[[ '.title.' ]]]' 2770 endif 2771 let table .= level.' '.g:vst_headers[level].' ' 2772 \ .repeat(' ', secmargin-len(level.g:vst_headers[level].' ')) 2773 \ .title.repeat(' ', thdmargin-len(title)).' '.line."\n" 2774 let i += 1 2775 endwhile 2776 2777 return table 2778 2778 2779 2779 endfunction … … 2781 2781 " VST_CreateDBs: creation of databases {{{ 2782 2782 function! VST_CreateDBs(table) 2783 " Preprocess table to get class of role into the same line2784 " Preprocessing here is nice idea for links, they don't have to be changed2785 " physically in document, no messing with adding/removing lines. It slow2786 " things down but more precise processing is Good Thing(tm)2787 " table: text to analyze in List form2788 let preproc = a:table2789 let i = 02790 while i < len(preproc)2791 if i == len(preproc) - 12792 let nextline = i - 12793 else2794 let nextline = i + 12795 endif2796 if preproc[i] =~ '^\s*\.\. role:'2797 if preproc[nextline] =~ '^\s*:class:'2798 let preproc[i] = preproc[i].' -vst-role-'.preproc[nextline]2799 else2800 let preproc[i] = preproc[i].' -vst-role-'2801 endif2802 endif2803 " Connect multiline link definitions2804 if preproc[i] =~ '^\s*\(\.\. _\|__ \)'2805 if preproc[nextline] !~ '^\s*\(\.\. _\|__ \)' && preproc[nextline] !~ '^\s*$'2806 let findent = strlen(matchstr(preproc[i], '^\s*'))2807 let sindent = strlen(matchstr(preproc[nextline], '^\s*'))2808 if (findent + 3) <= sindent2809 let preproc[i] = substitute(preproc[i], '\s\+$', '', '')2810 \.substitute(preproc[nextline], '^\s\+', '', '')2811 call remove(preproc, nextline)2812 " Turn counter down to process more than 2 lines2813 let i -= 12814 endif2815 endif2816 endif2817 let i += 12818 endwhile2819 2820 for i in range(len(preproc))2821 if preproc[i] =~ '^\s*\.\. _'2822 " Hyperlink database2823 let title = tolower(matchstr(preproc[i], '_\zs.\{-}\ze:'))2824 let url = matchstr(preproc[i], '_.\{-}:\s*\zs.*')2825 let k = 12826 while url == '' && len(preproc) > (i+k) && stridx(preproc[i+k], '_') > -12827 let url = matchstr(preproc[i+k], '_.\{-}:\s*\zs.*')2828 let k += 12829 endwhile2830 unlet! k2831 if url =~ '@' && url !~ '^http\|^s\?ftp'2832 let url = 'mailto:'.url2833 endif2834 if title != '' && title != '_'2835 let g:vst_hlinkdb[title] = url2836 endif2837 elseif preproc[i] =~ '^\s*\.\. role'2838 let rolekey = matchstr(preproc[i], 'role::\s*\zs.\{-}\ze\s*-vst-role-')2839 let rolevalue = matchstr(preproc[i], '-vst-role-\s*:class:\s*\zs.*\ze\s*$')2840 if rolevalue == ''2841 let rolevalue = rolekey2842 endif2843 let g:vst_roledb[rolekey] = rolevalue2844 endif2845 endfor2846 " Add embedded reusable URIs2847 " I have to join and split file again to avoid problems with: links2848 " splitted across lines and more than one link in line2849 let dbfile = join(a:table)2850 " This is done only for links, compress white space2851 let dbfile = substitute(dbfile, '\s\+', ' ', 'g')2852 let dbtable = split(dbfile, '>`_[^_]')2853 let i = 02854 while i < len(dbtable)-12855 " Hyperlink database2856 let expr= matchstr(dbtable[i], '.*`\zs.\{-}$')2857 if expr =~ '^<'2858 let title = tolower(matchstr(expr, '<\zs.*'))2859 else2860 let title = tolower(matchstr(expr, '\zs.\{-}\ze <.*$'))2861 endif2862 let url = matchstr(expr, ' <\zs.\{-}$')2863 if url =~ '@' && url !~ '^http\|^ftp'2864 let url = 'mailto:'.url2865 endif2866 if title != ''2867 let g:vst_hlinkdb[title] = url2868 endif2869 let i += 12870 endwhile2783 " Preprocess table to get class of role into the same line 2784 " Preprocessing here is nice idea for links, they don't have to be changed 2785 " physically in document, no messing with adding/removing lines. It slow 2786 " things down but more precise processing is Good Thing(tm) 2787 " table: text to analyze in List form 2788 let preproc = a:table 2789 let i = 0 2790 while i < len(preproc) 2791 if i == len(preproc) - 1 2792 let nextline = i - 1 2793 else 2794 let nextline = i + 1 2795 endif 2796 if preproc[i] =~ '^\s*\.\. role:' 2797 if preproc[nextline] =~ '^\s*:class:' 2798 let preproc[i] = preproc[i].' -vst-role-'.preproc[nextline] 2799 else 2800 let preproc[i] = preproc[i].' -vst-role-' 2801 endif 2802 endif 2803 " Connect multiline link definitions 2804 if preproc[i] =~ '^\s*\(\.\. _\|__ \)' 2805 if preproc[nextline] !~ '^\s*\(\.\. _\|__ \)' && preproc[nextline] !~ '^\s*$' 2806 let findent = strlen(matchstr(preproc[i], '^\s*')) 2807 let sindent = strlen(matchstr(preproc[nextline], '^\s*')) 2808 if (findent + 3) <= sindent 2809 let preproc[i] = substitute(preproc[i], '\s\+$', '', '') 2810 \.substitute(preproc[nextline], '^\s\+', '', '') 2811 call remove(preproc, nextline) 2812 " Turn counter down to process more than 2 lines 2813 let i -= 1 2814 endif 2815 endif 2816 endif 2817 let i += 1 2818 endwhile 2819 2820 for i in range(len(preproc)) 2821 if preproc[i] =~ '^\s*\.\. _' 2822 " Hyperlink database 2823 let title = tolower(matchstr(preproc[i], '_\zs.\{-}\ze:')) 2824 let url = matchstr(preproc[i], '_.\{-}:\s*\zs.*') 2825 let k = 1 2826 while url == '' && len(preproc) > (i+k) && stridx(preproc[i+k], '_') > -1 2827 let url = matchstr(preproc[i+k], '_.\{-}:\s*\zs.*') 2828 let k += 1 2829 endwhile 2830 unlet! k 2831 if url =~ '@' && url !~ '^http\|^s\?ftp' 2832 let url = 'mailto:'.url 2833 endif 2834 if title != '' && title != '_' 2835 let g:vst_hlinkdb[title] = url 2836 endif 2837 elseif preproc[i] =~ '^\s*\.\. role' 2838 let rolekey = matchstr(preproc[i], 'role::\s*\zs.\{-}\ze\s*-vst-role-') 2839 let rolevalue = matchstr(preproc[i], '-vst-role-\s*:class:\s*\zs.*\ze\s*$') 2840 if rolevalue == '' 2841 let rolevalue = rolekey 2842 endif 2843 let g:vst_roledb[rolekey] = rolevalue 2844 endif 2845 endfor 2846 " Add embedded reusable URIs 2847 " I have to join and split file again to avoid problems with: links 2848 " splitted across lines and more than one link in line 2849 let dbfile = join(a:table) 2850 " This is done only for links, compress white space 2851 let dbfile = substitute(dbfile, '\s\+', ' ', 'g') 2852 let dbtable = split(dbfile, '>`_[^_]') 2853 let i = 0 2854 while i < len(dbtable)-1 2855 " Hyperlink database 2856 let expr= matchstr(dbtable[i], '.*`\zs.\{-}$') 2857 if expr =~ '^<' 2858 let title = tolower(matchstr(expr, '<\zs.*')) 2859 else 2860 let title = tolower(matchstr(expr, '\zs.\{-}\ze <.*$')) 2861 endif 2862 let url = matchstr(expr, ' <\zs.\{-}$') 2863 if url =~ '@' && url !~ '^http\|^ftp' 2864 let url = 'mailto:'.url 2865 endif 2866 if title != '' 2867 let g:vst_hlinkdb[title] = url 2868 endif 2869 let i += 1 2870 endwhile 2871 2871 2872 2872 endfunction … … 2874 2874 " VST_FoldText: Create text for folds {{{ 2875 2875 function! VST_FoldText() 2876 let text = getline(v:foldstart)2877 let length = v:foldend - v:foldstart2878 let indent = '+'.v:folddashes.repeat(' ', 5-len(length)).length2879 \ .' lines: '2880 let line = b:vst_fold_numbers[text].' '.substitute(text, '^\s\+', '', '')2881 let symbol = repeat(' ', 50-len(line)).'('2882 \ .matchstr(getline(v:foldstart+1), '^\s*\zs...\ze').')'2883 return indent.repeat(' ', 15-len(indent)).line.symbol.' '2876 let text = getline(v:foldstart) 2877 let length = v:foldend - v:foldstart 2878 let indent = '+'.v:folddashes.repeat(' ', 5-len(length)).length 2879 \ .' lines: ' 2880 let line = b:vst_fold_numbers[text].' '.substitute(text, '^\s\+', '', '') 2881 let symbol = repeat(' ', 50-len(line)).'(' 2882 \ .matchstr(getline(v:foldstart+1), '^\s*\zs...\ze').')' 2883 return indent.repeat(' ', 15-len(indent)).line.symbol.' ' 2884 2884 endfunction 2885 2885 " }}} … … 2887 2887 " numbers - values for width of columns, String with + to separate numbers 2888 2888 function! VST_ColNumbers(numbers) 2889 let widths = split(a:numbers, '+')2890 let col_string = ''2891 for width in widths2892 let col_string .= '<col width="'.width.'%" />'2893 endfor2894 return col_string2889 let widths = split(a:numbers, '+') 2890 let col_string = '' 2891 for width in widths 2892 let col_string .= '<col width="'.width.'%" />' 2893 endfor 2894 return col_string 2895 2895 endfunction 2896 2896 " }}} 2897 2897 2898 2898 " Auxiliary functions: {{{ 2899 " Unicode2Char: Return char according to hex code {{{2899 " Unicode2Char: Return char according to hex code {{{ 2900 2900 " nr - decimal value of Unicode character 2901 2901 function! Unicode2Char(nr) 2902 let n = join(reverse(split(tolower(a:nr), '.\zs')), '')2903 2904 let r = 02905 let i = 02906 while i <= len(n)2907 if n[i] == 'a'2908 let p = 102909 elseif n[i] == 'b'2910 let p = 112911 elseif n[i] == 'c'2912 let p = 122913 elseif n[i] == 'd'2914 let p = 132915 elseif n[i] == 'e'2916 let p = 142917 elseif n[i] == 'f'2918 let p = 152919 else2920 let p = n[i]2921 endif2922 2923 if p == 02924 let fp = 02925 else2926 exe 'let fp = '.repeat('16*', i).p2927 endif2928 2929 let r += fp2930 2931 let i += 12932 endwhile2933 return nr2char(r)2902 let n = join(reverse(split(tolower(a:nr), '.\zs')), '') 2903 2904 let r = 0 2905 let i = 0 2906 while i <= len(n) 2907 if n[i] == 'a' 2908 let p = 10 2909 elseif n[i] == 'b' 2910 let p = 11 2911 elseif n[i] == 'c' 2912 let p = 12 2913 elseif n[i] == 'd' 2914 let p = 13 2915 elseif n[i] == 'e' 2916 let p = 14 2917 elseif n[i] == 'f' 2918 let p = 15 2919 else 2920 let p = n[i] 2921 endif 2922 2923 if p == 0 2924 let fp = 0 2925 else 2926 exe 'let fp = '.repeat('16*', i).p 2927 endif 2928 2929 let r += fp 2930 2931 let i += 1 2932 endwhile 2933 return nr2char(r) 2934 2934 endfunction 2935 2935 " }}} 2936 " VST_2html: Parse 2html directive {{{2936 " VST_2html: Parse 2html directive {{{ 2937 2937 " Description: Go through document looking for 2html directives, copy text of 2938 2938 " directive to new buffer and process it there with 2html.vim, at the end 2939 2939 " replace original text with colored text and additional <style> declaration. 2940 2940 function! VST_2html() 2941 silent call cursor(1,1)2942 syntax on2943 " Backup of important elements2944 let bufnumber = bufnr('%')2945 let z_rez = @z2946 let y_rez = @y2947 let @z = ''2948 let @y = ''2949 if exists('g:colors_name')2950 let col_scheme = g:colors_name2951 else2952 let col_scheme = 'default'2953 endif2954 " Saving 2html.vim options {{{2955 if exists('g:html_number_lines')2956 let h_number_lines = g:html_number_lines2957 else2958 let h_number_lines = 22959 endif2960 if exists('g:html_use_css')2961 let h_use_css = g:html_use_css2962 else2963 let h_use_css = 22964 endif2965 if exists('g:html_no_pre')2966 let h_no_pre = g:html_no_pre2967 else2968 let h_no_pre = 22969 endif2970 if exists('g:use_xhtml')2971 let h_use_xhtml = g:use_xhtml2972 else2973 let h_use_xhtml = 22974 endif2975 " }}}2976 " And set values necessary for good work2977 let g:html_number_lines = 02978 let g:html_use_css = 12979 let g:html_no_pre = 02980 let g:use_xhtml = 12981 if &compatible == 12982 set nocompatible2983 endif2984 if &splitbelow == 02985 let splitb = 02986 set splitbelow2987 else2988 let splitb = 12989 endif2990 2991 while search('<pre class="tohtml-[^"]\+">', 'W')2992 let @z = ''2993 let @y = ''2994 let line = line('.')2995 " Retrieve filetype and colorscheme data2996 let data = matchstr(getline('.'), '<pre class="tohtml-\zs.\{-}\ze">')2997 let darray = split(data, '----')2998 let filetype = darray[0]2999 if len(darray) > 13000 let cscheme = darray[1]3001 endif3002 let line2 = search('<\/pre>', 'W')3003 " There may be situation, by an user error, omission, etc. 2html3004 " directive will be empty. In that case silently quit.3005 if line + 1 == line23006 return3007 endif3008 silent exe (line+1).','.(line2-1).' delete z'3009 silent below 1new tmp-2html3010 silent 0put z3011 silent exe 'setlocal ft='.filetype3012 if exists('cscheme')3013 silent! exe 'colorscheme '.cscheme3014 endif3015 " I have to revert special characters because TOhtml will do it once3016 " again destroing & entities3017 " list: <, >, ©3018 " How to prevent massacre of user used entities?3019 " How probably they are in pre?3020 %s/</</ge3021 %s/>/>/ge3022 %s/&/\&/ge3023 " @-entity was treated literally by 2html.vim3024 %s/@/@/ge3025 silent runtime syntax/2html.vim3026 " Remove html headers, I don't need them inside of file3027 " Still problem with style inside of body3028 silent g+<!DOCTYPE\|</\?html\|</\?head>\|</\?pre>\|</\?body>\|</\?p>\|<title>\|<meta +d3029 silent g+<?xml+d3030 if exists('cscheme')3031 silent exe 'g+^body+s+^body+.tohtml-'.filetype.'----'.cscheme.'+e'3032 else3033 silent exe 'g+^body+s+^body+.tohtml-'.filetype.'+e'3034 endif3035 " 2html.vim in full auto _always_ use html_no_pre = 1. Weird.3036 silent %s/ / /ge3037 silent %s/<br\/>//ge3038 " Restore @ -> @ to prevent mail harvesting3039 silent %s/@/\@/ge3040 silent call cursor(1,1)3041 silent /<style/,/<\/style/yank y3042 let style = split(@y, '\n')3043 let main_style = style[-3:-3]3044 let main_style_name = split(main_style[0], ' ')[0]3045 let style = style[2:-4]3046 silent call map(style, "main_style_name.' '.v:val")3047 let style = main_style + style3048 if exists('g:vst_2html_css')3049 let g:vst_2html_css += style3050 else3051 let g:vst_2html_css = style3052 endif3053 silent call cursor(1,1)3054 silent normal! "zyG3055 silent bwipeout! tmp-2html.html3056 silent bwipeout! tmp-2html3057 let @z = substitute(@z, '\n\+$', '', '')3058 if exists('cscheme')3059 let @z = substitute(@z, '.*</style>', '\n<pre class="tohtml-'.filetype.'----'.cscheme.'">', '')3060 else3061 let @z = substitute(@z, '.*</style>', '\n<pre class="tohtml-'.filetype.'">', '')3062 endif3063 silent exe 'buffer! '.bufnumber3064 silent exe line3065 silent! put z3066 let line3 = line('.') - 13067 silent exe line3068 silent delete3069 silent exe line33070 unlet! cscheme3071 endwhile3072 3073 " Restore settings3074 let @z = z_rez3075 let @y = y_rez3076 if splitb == 03077 set nosplitbelow3078 endif3079 silent exe 'buffer! '.bufnumber3080 silent exe 'colorscheme '.col_scheme3081 " Restoring 2html.vim options {{{3082 if h_number_lines == 23083 unlet g:html_number_lines3084 else3085 let g:html_number_lines = h_number_lines3086 endif3087 if h_use_css == 23088 unlet g:html_use_css3089 else3090 let g:html_use_css = h_use_css3091 endif3092 if h_no_pre == 23093 unlet g:html_no_pre3094 else3095 let g:html_no_pre = h_no_pre3096 endif3097 " }}}2941 silent call cursor(1,1) 2942 syntax on 2943 " Backup of important elements 2944 let bufnumber = bufnr('%') 2945 let z_rez = @z 2946 let y_rez = @y 2947 let @z = '' 2948 let @y = '' 2949 if exists('g:colors_name') 2950 let col_scheme = g:colors_name 2951 else 2952 let col_scheme = 'default' 2953 endif 2954 " Saving 2html.vim options {{{ 2955 if exists('g:html_number_lines') 2956 let h_number_lines = g:html_number_lines 2957 else 2958 let h_number_lines = 2 2959 endif 2960 if exists('g:html_use_css') 2961 let h_use_css = g:html_use_css 2962 else 2963 let h_use_css = 2 2964 endif 2965 if exists('g:html_no_pre') 2966 let h_no_pre = g:html_no_pre 2967 else 2968 let h_no_pre = 2 2969 endif 2970 if exists('g:use_xhtml') 2971 let h_use_xhtml = g:use_xhtml 2972 else 2973 let h_use_xhtml = 2 2974 endif 2975 " }}} 2976 " And set values necessary for good work 2977 let g:html_number_lines = 0 2978 let g:html_use_css = 1 2979 let g:html_no_pre = 0 2980 let g:use_xhtml = 1 2981 if &compatible == 1 2982 set nocompatible 2983 endif 2984 if &splitbelow == 0 2985 let splitb = 0 2986 set splitbelow 2987 else 2988 let splitb = 1 2989 endif 2990 2991 while search('<pre class="tohtml-[^"]\+">', 'W') 2992 let @z = '' 2993 let @y = '' 2994 let line = line('.') 2995 " Retrieve filetype and colorscheme data 2996 let data = matchstr(getline('.'), '<pre class="tohtml-\zs.\{-}\ze">') 2997 let darray = split(data, '----') 2998 let filetype = darray[0] 2999 if len(darray) > 1 3000 let cscheme = darray[1] 3001 endif 3002 let line2 = search('<\/pre>', 'W') 3003 " There may be situation, by an user error, omission, etc. 2html 3004 " directive will be empty. In that case silently quit. 3005 if line + 1 == line2 3006 return 3007 endif 3008 silent exe (line+1).','.(line2-1).' delete z' 3009 silent below 1new tmp-2html 3010 silent 0put z 3011 silent exe 'setlocal ft='.filetype 3012 if exists('cscheme') 3013 silent! exe 'colorscheme '.cscheme 3014 endif 3015 " I have to revert special characters because TOhtml will do it once 3016 " again destroing & entities 3017 " list: <, >, © 3018 " How to prevent massacre of user used entities? 3019 " How probably they are in pre? 3020 %s/</</ge 3021 %s/>/>/ge 3022 %s/&/\&/ge 3023 " @-entity was treated literally by 2html.vim 3024 %s/@/@/ge 3025 silent runtime syntax/2html.vim 3026 " Remove html headers, I don't need them inside of file 3027 " Still problem with style inside of body 3028 silent g+<!DOCTYPE\|</\?html\|</\?head>\|</\?pre>\|</\?body>\|</\?p>\|<title>\|<meta +d 3029 silent g+<?xml+d 3030 if exists('cscheme') 3031 silent exe 'g+^body+s+^body+.tohtml-'.filetype.'----'.cscheme.'+e' 3032 else 3033 silent exe 'g+^body+s+^body+.tohtml-'.filetype.'+e' 3034 endif 3035 " 2html.vim in full auto _always_ use html_no_pre = 1. Weird. 3036 silent %s/ / /ge 3037 silent %s/<br\/>//ge 3038 " Restore @ -> @ to prevent mail harvesting 3039 silent %s/@/\@/ge 3040 silent call cursor(1,1) 3041 silent /<style/,/<\/style/yank y 3042 let style = split(@y, '\n') 3043 let main_style = style[-3:-3] 3044 let main_style_name = split(main_style[0], ' ')[0] 3045 let style = style[2:-4] 3046 silent call map(style, "main_style_name.' '.v:val") 3047 let style = main_style + style 3048 if exists('g:vst_2html_css') 3049 let g:vst_2html_css += style 3050 else 3051 let g:vst_2html_css = style 3052 endif 3053 silent call cursor(1,1) 3054 silent normal! "zyG 3055 silent bwipeout! tmp-2html.html 3056 silent bwipeout! tmp-2html 3057 let @z = substitute(@z, '\n\+$', '', '') 3058 if exists('cscheme') 3059 let @z = substitute(@z, '.*</style>', '\n<pre class="tohtml-'.filetype.'----'.cscheme.'">', '') 3060 else 3061 let @z = substitute(@z, '.*</style>', '\n<pre class="tohtml-'.filetype.'">', '') 3062 endif 3063 silent exe 'buffer! '.bufnumber 3064 silent exe line 3065 silent! put z 3066 let line3 = line('.') - 1 3067 silent exe line 3068 silent delete 3069 silent exe line3 3070 unlet! cscheme 3071 endwhile 3072 3073 " Restore settings 3074 let @z = z_rez 3075 let @y = y_rez 3076 if splitb == 0 3077 set nosplitbelow 3078 endif 3079 silent exe 'buffer! '.bufnumber 3080 silent exe 'colorscheme '.col_scheme 3081 " Restoring 2html.vim options {{{ 3082 if h_number_lines == 2 3083 unlet g:html_number_lines 3084 else 3085 let g:html_number_lines = h_number_lines 3086 endif 3087 if h_use_css == 2 3088 unlet g:html_use_css 3089 else 3090 let g:html_use_css = h_use_css 3091 endif 3092 if h_no_pre == 2 3093 unlet g:html_no_pre 3094 else 3095 let g:html_no_pre = h_no_pre 3096 endif 3097 " }}} 3098 3098 3099 3099 endfunction 3100 3100 " }}} 3101 " VST_AddClass: Return class string if prev par is class (.. class::) {{{3101 " VST_AddClass: Return class string if prev par is class (.. class::) {{{ 3102 3102 " Description: Check previous paragraph and in case it is class return string 3103 " class="classname", classname or ''.3104 " parnumber - number of described paragraph3105 " full - check if return full declaration or name only3106 " 1 - full declaration class="classname"3107 " 0 - name only3108 " pre - prefix3109 " post - suffix3103 " class="classname", classname or ''. 3104 " parnumber - number of described paragraph 3105 " full - check if return full declaration or name only 3106 " 1 - full declaration class="classname" 3107 " 0 - name only 3108 " pre - prefix 3109 " post - suffix 3110 3110 function! VST_AddClass(parnumber, full, pre, post) 3111 " Escaping of special characters3112 if g:ptype[a:parnumber-1] == 'notend' && g:ptype[a:parnumber-2] == 'MED-class'3113 3114 "let name = matchstr(g:paras[a:parnumber-2], '^\s*\.\. class::\s*\zs.\{-1,}\ze\s*$')3115 let name = VST_IdMaker(g:paras[a:parnumber-2])3116 if a:full == 13117 let class = 'class="'.name.'"'3118 else3119 let class = name3120 endif3121 let class = a:pre.class.a:post3122 else3123 let class = ''3124 endif3125 3126 return class3111 " Escaping of special characters 3112 if g:ptype[a:parnumber-1] == 'notend' && g:ptype[a:parnumber-2] == 'MED-class' 3113 3114 "let name = matchstr(g:paras[a:parnumber-2], '^\s*\.\. class::\s*\zs.\{-1,}\ze\s*$') 3115 let name = VST_IdMaker(g:paras[a:parnumber-2]) 3116 if a:full == 1 3117 let class = 'class="'.name.'"' 3118 else 3119 let class = name 3120 endif 3121 let class = a:pre.class.a:post 3122 else 3123 let class = '' 3124 endif 3125 3126 return class 3127 3127 3128 3128 endfunction … … 3130 3130 " VST_AnonHyperlink: Create anonymous hyperlinks {{{ 3131 3131 function! VST_AnonHyperlink(text) 3132 let parlines = split(a:text, '-vst-anon-hyperlink-')3133 let i = 03134 let g:a0 = []3135 while i < len(g:vst_anonhlinkdb)3136 if g:vst_anonhlinkdb[i] =~ '_\s*$'3137 let href = g:vst_anonhlinkdb[i]3138 let title = tolower(matchstr(href, '\(\.\. __ :\|__\)\s*\(`\?\)\zs.*\ze\2_\s*$'))3139 while href =~ '_\s*$'3140 " If ends in _ it is probably indirect link, process it.3141 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != ''3142 let href = escape(g:vst_hlinkdb[title], '&\~')3143 else3144 let href = '#l'.VST_IdMaker(title)3145 endif3146 endwhile3147 else3148 let href = matchstr(g:vst_anonhlinkdb[i], '^\s*\(\.\. __:\|__\)\s*\zs.*')3149 endif3150 let g:a0 += [href]3151 if i < len(parlines) - 13152 let parlines[i] .= href3153 endif3154 let i += 13155 endwhile3156 let par = join(parlines, '')3157 3158 return par3132 let parlines = split(a:text, '-vst-anon-hyperlink-') 3133 let i = 0 3134 let g:a0 = [] 3135 while i < len(g:vst_anonhlinkdb) 3136 if g:vst_anonhlinkdb[i] =~ '_\s*$' 3137 let href = g:vst_anonhlinkdb[i] 3138 let title = tolower(matchstr(href, '\(\.\. __ :\|__\)\s*\(`\?\)\zs.*\ze\2_\s*$')) 3139 while href =~ '_\s*$' 3140 " If ends in _ it is probably indirect link, process it. 3141 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != '' 3142 let href = escape(g:vst_hlinkdb[title], '&\~') 3143 else 3144 let href = '#l'.VST_IdMaker(title) 3145 endif 3146 endwhile 3147 else 3148 let href = matchstr(g:vst_anonhlinkdb[i], '^\s*\(\.\. __:\|__\)\s*\zs.*') 3149 endif 3150 let g:a0 += [href] 3151 if i < len(parlines) - 1 3152 let parlines[i] .= href 3153 endif 3154 let i += 1 3155 endwhile 3156 let par = join(parlines, '') 3157 3158 return par 3159 3159 3160 3160 endfunction … … 3162 3162 " VST_AutoFootnote: Create auto-numbered footnotes [#]_ {{{ 3163 3163 function! VST_AutoFootnote(text) 3164 let parlines = split(a:text, '\[#]_')3165 let i = 03166 let k = s:maxfnumber + s:maxlnumber + 13167 while i < len(parlines)-13168 let parlines[i] .= '<vim:a href="#footnote-'.k.'" name="target-'.k.'">['.k.']</vim:a>'3169 let i += 13170 let k += 13171 endwhile3172 let par = join(parlines, '')3173 3174 return par3164 let parlines = split(a:text, '\[#]_') 3165 let i = 0 3166 let k = s:maxfnumber + s:maxlnumber + 1 3167 while i < len(parlines)-1 3168 let parlines[i] .= '<vim:a href="#footnote-'.k.'" name="target-'.k.'">['.k.']</vim:a>' 3169 let i += 1 3170 let k += 1 3171 endwhile 3172 let par = join(parlines, '') 3173 3174 return par 3175 3175 3176 3176 endfunction 3177 3177 " }}} 3178 " VST_Citations: Create citations [first]_ {{{3178 " VST_Citations: Create citations [first]_ {{{ 3179 3179 function! VST_Citations(text) 3180 let par = substitute(a:text, '\[\(\k\{-}\)]_', '<vim:a href="#citation-\1" name="ctarget-\1">[\1]</vim:a>', 'g')3181 3182 return par3180 let par = substitute(a:text, '\[\(\k\{-}\)]_', '<vim:a href="#citation-\1" name="ctarget-\1">[\1]</vim:a>', 'g') 3181 3182 return par 3183 3183 endfunction 3184 3184 " }}} … … 3186 3186 " Description: 3187 3187 function! VST_CreateVerse(text) 3188 " Escaping of special characters3189 let par = substitute(a:text, '\n\s*|\( *\)', '\="<vim:br />-vst-new-line-".repeat(" ", len(submatch(1)))', 'g')3190 let par = substitute(par, '^\s*|\( *\)', '\="<vim:p class=\"verse\">-vst-new-line-".repeat(" ", len(submatch(1)))', 'g')3191 let par .= "\n</vim:p>"3192 let par = substitute(par, '-vst-new-line-', '\n', 'g')3193 3194 return par3188 " Escaping of special characters 3189 let par = substitute(a:text, '\n\s*|\( *\)', '\="<vim:br />-vst-new-line-".repeat(" ", len(submatch(1)))', 'g') 3190 let par = substitute(par, '^\s*|\( *\)', '\="<vim:p class=\"verse\">-vst-new-line-".repeat(" ", len(submatch(1)))', 'g') 3191 let par .= "\n</vim:p>" 3192 let par = substitute(par, '-vst-new-line-', '\n', 'g') 3193 3194 return par 3195 3195 endfunction 3196 3196 " }}} 3197 3197 " VST_EscapingSlash: Remove escaping backslashes {{{ 3198 3198 function! VST_EscapingSlash(text) 3199 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g')3200 3201 " Special constructs for escaping:3202 " \*-> *3203 " \`-> `3204 " \=-> = (commented)3205 " \<Space> -> <Nop>3206 " \--> 3207 "3208 " To escape backslash, use backslash:3209 " \\*, \\<Space>, \\-3210 3211 " Remove single escaping backslash before letters and digits which can form3212 " lists enumerators:3213 let par = substitute(par, '\\\@<!\\\([A-Za-z0-9#][\]:.)}]\)', '\1', 'g')3214 3215 " Remove single escaping backslash befor | at the beginning of paragraph3216 " let par = substitute(par, '^\(\s*\)\\|', '\1|', 'g')3217 3218 " Take care about \*3219 let par = substitute(par, '\\\@<!\\\*', '*', 'g')3220 " And remove escaping \3221 let par = substitute(par, '\\\\\*', '\\*', 'g')3222 3223 " Take care about \`3224 let par = substitute(par, '\\\@<!\\`', '`', 'g')3225 " And remove escaping \3226 let par = substitute(par, '\\\\`', '\\`', 'g')3227 3228 " Take care about \=3229 " let par = substitute(par, '\\\@<!\\=', '=', 'g')3230 " And remove escaping \3231 " let par = substitute(par, '\\\\=', '\\=', 'g')3232 3233 " Take care about \<Space>3234 let par = substitute(par, '\\\@<!\\ \(-vst-new-line-\)\@!', '', 'g')3235 " And remove escaping \3236 let par = substitute(par, '\\\\ \(-vst-new-line-\)\@!', '\\ ', 'g')3237 " At last get rid of artificial new lines3238 let par = substitute(par, ' -vst-new-line- ', '\n', 'g')3239 3240 " Take care about \-3241 let par = substitute(par, '\\\@<!\\-', '\ ', 'g')3242 " And remove escaping \3243 let par = substitute(par, '\\\\-', '\\-', 'g')3244 3245 3246 return par3199 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g') 3200 3201 " Special constructs for escaping: 3202 " \* -> * 3203 " \` -> ` 3204 " \= -> = (commented) 3205 " \<Space> -> <Nop> 3206 " \- -> 3207 " 3208 " To escape backslash, use backslash: 3209 " \\*, \\<Space>, \\- 3210 3211 " Remove single escaping backslash before letters and digits which can form 3212 " lists enumerators: 3213 let par = substitute(par, '\\\@<!\\\([A-Za-z0-9#][\]:.)}]\)', '\1', 'g') 3214 3215 " Remove single escaping backslash befor | at the beginning of paragraph 3216 " let par = substitute(par, '^\(\s*\)\\|', '\1|', 'g') 3217 3218 " Take care about \* 3219 let par = substitute(par, '\\\@<!\\\*', '*', 'g') 3220 " And remove escaping \ 3221 let par = substitute(par, '\\\\\*', '\\*', 'g') 3222 3223 " Take care about \` 3224 let par = substitute(par, '\\\@<!\\`', '`', 'g') 3225 " And remove escaping \ 3226 let par = substitute(par, '\\\\`', '\\`', 'g') 3227 3228 " Take care about \= 3229 " let par = substitute(par, '\\\@<!\\=', '=', 'g') 3230 " And remove escaping \ 3231 " let par = substitute(par, '\\\\=', '\\=', 'g') 3232 3233 " Take care about \<Space> 3234 let par = substitute(par, '\\\@<!\\ \(-vst-new-line-\)\@!', '', 'g') 3235 " And remove escaping \ 3236 let par = substitute(par, '\\\\ \(-vst-new-line-\)\@!', '\\ ', 'g') 3237 " At last get rid of artificial new lines 3238 let par = substitute(par, ' -vst-new-line- ', '\n', 'g') 3239 3240 " Take care about \- 3241 let par = substitute(par, '\\\@<!\\-', '\ ', 'g') 3242 " And remove escaping \ 3243 let par = substitute(par, '\\\\-', '\\-', 'g') 3244 3245 3246 return par 3247 3247 endfunction 3248 3248 " }}} 3249 " VST_ExtraRoles: Change text :roles: into proper tags " {{{3249 " VST_ExtraRoles: Change text :roles: into proper tags " {{{ 3250 3250 function! VST_ExtraRoles(name, text) 3251 3251 3252 if len(filter(copy(keys(g:vst_roledb)), "v:val == a:name")) > 03253 let par = '<vim:span class="'.VST_IdMaker(g:vst_roledb[a:name]).'">'.a:text.'</vim:span>'3254 else3255 let par = a:text3256 endif3257 3258 return par3252 if len(filter(copy(keys(g:vst_roledb)), "v:val == a:name")) > 0 3253 let par = '<vim:span class="'.VST_IdMaker(g:vst_roledb[a:name]).'">'.a:text.'</vim:span>' 3254 else 3255 let par = a:text 3256 endif 3257 3258 return par 3259 3259 endfunction 3260 3260 " }}} 3261 " VST_FirstLine: Returns first and only first line " {{{3261 " VST_FirstLine: Returns first and only first line " {{{ 3262 3262 " without trailing spaces of given text 3263 3263 function! VST_FirstLine(text) 3264 return matchstr(a:text, '^\s*\ze.\{-}\ze\s*\(\n\|$\)')3264 return matchstr(a:text, '^\s*\ze.\{-}\ze\s*\(\n\|$\)') 3265 3265 3266 3266 endfunction 3267 3267 " }}} 3268 " VST_Footnotes: Create footnotes [\d\+]_ {{{3268 " VST_Footnotes: Create footnotes [\d\+]_ {{{ 3269 3269 function! VST_Footnotes(text) 3270 let parlines = split(a:text, '\(\[\d\+\]\)\@<=_')3271 let j = 03272 for parline in parlines3273 let parlines[j] = substitute(parlines[j], '\[\(\d\+\)]$', '<vim:a href="#footnote-\1" name="target-\1">\0</vim:a>', '')3274 let j += 13275 endfor3276 let par = join(parlines, '')3277 3278 return par3270 let parlines = split(a:text, '\(\[\d\+\]\)\@<=_') 3271 let j = 0 3272 for parline in parlines 3273 let parlines[j] = substitute(parlines[j], '\[\(\d\+\)]$', '<vim:a href="#footnote-\1" name="target-\1">\0</vim:a>', '') 3274 let j += 1 3275 endfor 3276 let par = join(parlines, '') 3277 3278 return par 3279 3279 3280 3280 endfunction 3281 3281 " }}} 3282 " VST_Hyperlink: Create inline `markup of hyperlinks`_ " {{{3282 " VST_Hyperlink: Create inline `markup of hyperlinks`_ " {{{ 3283 3283 function! VST_Hyperlink(text) 3284 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g')3285 " Technical spaces3286 " Adding spaces at the end and start of paragraph isn't elegant but3287 " catching of ^ and $ in regexps by \| is very expensive.3288 let par = ' '.par.' '3289 " `Inline external anchors`_3290 if par =~ '__'3291 " Embedded anonymous hyperlinks, Note: second space is nonbreaking3292 " space \x1603293 let par = substitute(par, "[- '\"([{</:>]\\@<=`\<\\(.\\{-1,}\\)\>`__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(1))."\" title=\"".VST_ProtectLiteral(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>"', 'g')3294 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\) \<\\(.\\{-1,}\\)\>`__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(3))."\" title=\"".submatch(1).submatch(2)."\">".submatch(1).submatch(2)."</vim:a>"', 'g')3295 " Multi word anon hyperlink (enclosed in backticks)3296 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"-vst-anon-hyperlink-\" title=\"".VST_RemoveTags(submatch(1).submatch(2))."\">".submatch(1).submatch(2)."</vim:a>"', 'g')3297 " One word anon hyperlink3298 let par = substitute(par, "[- '\"([{</:>]\\@<=\\([[:alnum:]._-]\\{-2,}\\)__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a href="-vst-anon-hyperlink-" title="\1">\1</vim:a>', 'g')3299 let par = substitute(par, "[- '\"([{</:>]\\@<=\\(\\k\\{-1,}\\)__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a href="-vst-anon-hyperlink-" title="\1">\1</vim:a>', 'g')3300 endif3301 " Embedded hyperlinks3302 let par = substitute(par, "[- '\"([{</:>]\\@<=`\<\\([^`]\\{-1,}\\)\>`_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(1))."\" title=\"".VST_ProtectLiteral(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>"', 'g')3303 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\) \<\\(.\\{-1,}\\)\>`_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(3))."\" title=\"".submatch(1).submatch(2)."\">".submatch(1).submatch(2)."</vim:a>"', 'g')3304 " Multi word hyperlink (enclosed in backticks)3305 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a hrefext=\"".VST_RemoveTags(submatch(1).submatch(2))."\" title=\"".VST_RemoveTags(submatch(1).submatch(2))."\">".submatch(1).submatch(2)."</vim:a>"', 'g')3306 " One word hyperlink3307 let par = substitute(par, "[- '\"([{</:>]\\@<=\\([[:alnum:]._-]\\{-2,}\\)_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a hrefext="\1" title="\1">\1</vim:a>', 'g')3308 let par = substitute(par, "[- '\"([{</:>]\\@<=\\(\\k\\{-1,}\\)_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a hrefext="\1" title="\1">\1</vim:a>', 'g')3309 3310 " Strange splitting is necessary to be sure it will be unique and only one3311 " hyperlink per element.3312 let parlines = split(par, 'vim:a h')3313 let j = 03314 for parline in parlines3315 if parline =~ '^refext='3316 let title = tolower(matchstr(parlines[j], '^refext="\zs.\{-}\ze"'))3317 let title = substitute(title, '\s\+-vst-new-line-\s\+', ' ', 'g')3318 " There was already some processing in text, while data in hlinkdb3319 " is in its crude form. I need to reverse some changes to match3320 " them:3321 let title = substitute(title, '&', '\&', 'g')3322 let title = substitute(title, '<', '<', 'g')3323 let title = substitute(title, '>', '>', 'g')3324 let title = substitute(title, '©', '(c)', 'g')3325 let title = substitute(title, '@', '@', 'g')3326 3327 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != ''3328 let href = escape(g:vst_hlinkdb[title], '&\~')3329 if href =~ '_\s*$'3330 while href =~ '_\s*$'3331 " If ends in _ it is probably indirect link, process it3332 " We need to remove _ from the end to get proper key name.3333 let shref = tolower(matchstr(href, '^\s*\(`\?\)\zs.*\ze\1_\s*$'))3334 if has_key(g:vst_hlinkdb, shref) && g:vst_hlinkdb[shref] != ''3335 let href = escape(g:vst_hlinkdb[shref], '&\~')3336 else3337 let href = '#l'.tolower(VST_IdMaker(shref))3338 endif3339 endwhile3340 else3341 let href = escape(g:vst_hlinkdb[title], '&\~')3342 endif3343 else3344 let href = '#l'.VST_IdMaker(title)3345 endif3346 let parlines[j] = substitute(parlines[j], '^refext=".\{-}"', 'ref="'.href.'"', 'g')3347 let parlines[j] = substitute(parlines[j], 'title="\(.\{-}\)"', '\="title=\"".substitute(submatch(1), " -vst-new-line-\s*", " ", "g")."\""', 'g')3348 endif3349 let j += 13350 endfor3351 let par = join(parlines, 'vim:a h')3352 3353 let par = substitute(par, '^ ', '', '')3354 let par = substitute(par, ' $', '', '')3355 let par = substitute(par, ' -vst-new-line- ', '\n', 'g')3356 " Without this regexp new line placeholders wouldn't be removed from3357 " broken embedded URIs3358 let par = substitute(par, ' -vst-new-line-\(\S\)', '\1', 'g')3359 3360 return par3284 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g') 3285 " Technical spaces 3286 " Adding spaces at the end and start of paragraph isn't elegant but 3287 " catching of ^ and $ in regexps by \| is very expensive. 3288 let par = ' '.par.' ' 3289 " `Inline external anchors`_ 3290 if par =~ '__' 3291 " Embedded anonymous hyperlinks, Note: second space is nonbreaking 3292 " space \x160 3293 let par = substitute(par, "[- '\"([{</:>]\\@<=`\<\\(.\\{-1,}\\)\>`__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(1))."\" title=\"".VST_ProtectLiteral(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>"', 'g') 3294 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\) \<\\(.\\{-1,}\\)\>`__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(3))."\" title=\"".submatch(1).submatch(2)."\">".submatch(1).submatch(2)."</vim:a>"', 'g') 3295 " Multi word anon hyperlink (enclosed in backticks) 3296 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"-vst-anon-hyperlink-\" title=\"".VST_RemoveTags(submatch(1).submatch(2))."\">".submatch(1).submatch(2)."</vim:a>"', 'g') 3297 " One word anon hyperlink 3298 let par = substitute(par, "[- '\"([{</:>]\\@<=\\([[:alnum:]._-]\\{-2,}\\)__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a href="-vst-anon-hyperlink-" title="\1">\1</vim:a>', 'g') 3299 let par = substitute(par, "[- '\"([{</:>]\\@<=\\(\\k\\{-1,}\\)__[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a href="-vst-anon-hyperlink-" title="\1">\1</vim:a>', 'g') 3300 endif 3301 " Embedded hyperlinks 3302 let par = substitute(par, "[- '\"([{</:>]\\@<=`\<\\([^`]\\{-1,}\\)\>`_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(1))."\" title=\"".VST_ProtectLiteral(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>"', 'g') 3303 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\) \<\\(.\\{-1,}\\)\>`_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a href=\"".VST_ProtectLiteral(submatch(3))."\" title=\"".submatch(1).submatch(2)."\">".submatch(1).submatch(2)."</vim:a>"', 'g') 3304 " Multi word hyperlink (enclosed in backticks) 3305 let par = substitute(par, "[- '\"([{</:>]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '\="<vim:a hrefext=\"".VST_RemoveTags(submatch(1).submatch(2))."\" title=\"".VST_RemoveTags(submatch(1).submatch(2))."\">".submatch(1).submatch(2)."</vim:a>"', 'g') 3306 " One word hyperlink 3307 let par = substitute(par, "[- '\"([{</:>]\\@<=\\([[:alnum:]._-]\\{-2,}\\)_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a hrefext="\1" title="\1">\1</vim:a>', 'g') 3308 let par = substitute(par, "[- '\"([{</:>]\\@<=\\(\\k\\{-1,}\\)_[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:a hrefext="\1" title="\1">\1</vim:a>', 'g') 3309 3310 " Strange splitting is necessary to be sure it will be unique and only one 3311 " hyperlink per element. 3312 let parlines = split(par, 'vim:a h') 3313 let j = 0 3314 for parline in parlines 3315 if parline =~ '^refext=' 3316 let title = tolower(matchstr(parlines[j], '^refext="\zs.\{-}\ze"')) 3317 let title = substitute(title, '\s\+-vst-new-line-\s\+', ' ', 'g') 3318 " There was already some processing in text, while data in hlinkdb 3319 " is in its crude form. I need to reverse some changes to match 3320 " them: 3321 let title = substitute(title, '&', '\&', 'g') 3322 let title = substitute(title, '<', '<', 'g') 3323 let title = substitute(title, '>', '>', 'g') 3324 let title = substitute(title, '©', '(c)', 'g') 3325 let title = substitute(title, '@', '@', 'g') 3326 3327 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != '' 3328 let href = escape(g:vst_hlinkdb[title], '&\~') 3329 if href =~ '_\s*$' 3330 while href =~ '_\s*$' 3331 " If ends in _ it is probably indirect link, process it 3332 " We need to remove _ from the end to get proper key name. 3333 let shref = tolower(matchstr(href, '^\s*\(`\?\)\zs.*\ze\1_\s*$')) 3334 if has_key(g:vst_hlinkdb, shref) && g:vst_hlinkdb[shref] != '' 3335 let href = escape(g:vst_hlinkdb[shref], '&\~') 3336 else 3337 let href = '#l'.tolower(VST_IdMaker(shref)) 3338 endif 3339 endwhile 3340 else 3341 let href = escape(g:vst_hlinkdb[title], '&\~') 3342 endif 3343 else 3344 let href = '#l'.VST_IdMaker(title) 3345 endif 3346 let parlines[j] = substitute(parlines[j], '^refext=".\{-}"', 'ref="'.href.'"', 'g') 3347 let parlines[j] = substitute(parlines[j], 'title="\(.\{-}\)"', '\="title=\"".substitute(submatch(1), " -vst-new-line-\s*", " ", "g")."\""', 'g') 3348 endif 3349 let j += 1 3350 endfor 3351 let par = join(parlines, 'vim:a h') 3352 3353 let par = substitute(par, '^ ', '', '') 3354 let par = substitute(par, ' $', '', '') 3355 let par = substitute(par, ' -vst-new-line- ', '\n', 'g') 3356 " Without this regexp new line placeholders wouldn't be removed from 3357 " broken embedded URIs 3358 let par = substitute(par, ' -vst-new-line-\(\S\)', '\1', 'g') 3359 3360 return par 3361 3361 endfunction 3362 3362 " }}} 3363 3363 " VST_IdentifyImage: Return dimensions of image {{{ 3364 3364 function! VST_IdentifyImage(imagename, line) 3365 let iscale = matchstr(a:line, ':identify:\s*\zs.\{-}\ze\s*$')3366 let istring = system('identify -format %wx%h "'.a:imagename.'"')3367 if istring =~ '^identify'3368 let width = ''3369 let height = ''3370 endif3371 " identify may return new line char at the end breaking some regexps in3372 " final stage.3373 let istring = substitute(istring, '\n', '', 'g')3374 let dimensions = split(istring, 'x')3375 if iscale != '' && iscale !~ '\D'3376 let width = dimensions[0]*iscale/1003377 let height = dimensions[1]*iscale/1003378 else3379 let [width, height] = dimensions3380 endif3381 3382 return [width, height]3365 let iscale = matchstr(a:line, ':identify:\s*\zs.\{-}\ze\s*$') 3366 let istring = system('identify -format %wx%h "'.a:imagename.'"') 3367 if istring =~ '^identify' 3368 let width = '' 3369 let height = '' 3370 endif 3371 " identify may return new line char at the end breaking some regexps in 3372 " final stage. 3373 let istring = substitute(istring, '\n', '', 'g') 3374 let dimensions = split(istring, 'x') 3375 if iscale != '' && iscale !~ '\D' 3376 let width = dimensions[0]*iscale/100 3377 let height = dimensions[1]*iscale/100 3378 else 3379 let [width, height] = dimensions 3380 endif 3381 3382 return [width, height] 3383 3383 3384 3384 endfunction 3385 3385 " }}} 3386 " VST_IdMaker: Create strings used in name and href {{{3386 " VST_IdMaker: Create strings used in name and href {{{ 3387 3387 " arguments of links 3388 3388 " Description: Split string to list (necessary to escape unholy mess with 3389 3389 " utf-8 && multibyte characters) and iterate through elements: 3390 " When char is \w or - leave unchanged,3391 " when \s change to -,3392 " when other use built-in char2nr() function.3390 " When char is \w or - leave unchanged, 3391 " when \s change to -, 3392 " when other use built-in char2nr() function. 3393 3393 function! VST_IdMaker(str) 3394 3394 " Changing to list is necessary to escape mess with utf-8 characters … … 3397 3397 let ix = 0 3398 3398 while ix < len(link) 3399 if link[ix] =~ '[a-zA-Z0-9_-]'3400 let out .= link[ix]3401 elseif link[ix] =~ '\s'3402 let out .= '-'3403 else3404 let out .= char2nr(link[ix])3405 endif3406 let ix += 13399 if link[ix] =~ '[a-zA-Z0-9_-]' 3400 let out .= link[ix] 3401 elseif link[ix] =~ '\s' 3402 let out .= '-' 3403 else 3404 let out .= char2nr(link[ix]) 3405 endif 3406 let ix += 1 3407 3407 endwhile 3408 3408 return out 3409 3409 endfunction 3410 3410 " }}} 3411 " VST_ImagePar: Process image par and return image {{{3411 " VST_ImagePar: Process image par and return image {{{ 3412 3412 " Description: Process image paragraph checking options and composing vim:img 3413 3413 " tag 3414 " par - image paragraph3415 " full - is this standalone image or replacement3416 " 1 - standalone image, put tag in new line3417 " 0 - tag inline, add inline class3414 " par - image paragraph 3415 " full - is this standalone image or replacement 3416 " 1 - standalone image, put tag in new line 3417 " 0 - tag inline, add inline class 3418 3418 function! VST_ImagePar(par, full) 3419 if a:full == 13420 let nl = "\n"3421 let inline = ''3422 else3423 " This will be inline image. No need for new line at the end of tag3424 " and we have to declare inlininess of it3425 let nl = ''3426 let inline = ' inline'3427 endif3428 let src = ''3429 let width = ''3430 let height = ''3431 let alt = ''3432 let title = ''3433 let identify = ''3434 let align = ''3435 let scale = ''3436 let target = ''3437 let class = ''3438 let parlines = split(a:par, '\n')3439 for parline in parlines3440 let parline = substitute(parline, '^\s*', '', '')3441 if src == ''3442 let src = matchstr(parline, '\(\.\. \)\?image::\s*\zs.\{-}\ze\s*$')3443 if !filereadable(escape(src, ' \#%'))3444 let noimage = 13445 let g:vst_error .= "No image: ".src."\n"3446 else3447 let noimage = 03448 endif3449 endif3450 if width == ''3451 let width = matchstr(parline, ':width:\s*\zs.\{-}\ze\s*$')3452 endif3453 if height == ''3454 let height = matchstr(parline, ':height:\s*\zs.\{-}\ze\s*$')3455 endif3456 if alt == ''3457 let alt = matchstr(parline, ':alt:\s*\zs.\{-}\ze\s*$')3458 endif3459 if title == ''3460 let title = matchstr(parline, ':title:\s*\zs.\{-}\ze\s*$')3461 endif3462 if align == ''3463 let align = matchstr(parline, ':align:\s*\zs.\{-}\ze\s*$')3464 endif3465 if scale == ''3466 let scale = matchstr(parline, ':scale:\s*\zs.\{-}\ze\s*$')3467 if scale =~ '\D'3468 let scale = ''3469 endif3470 endif3471 if target == ''3472 let target = matchstr(parline, ':target:\s*\zs.\{-}\ze\s*$')3473 if target == 'self' && src != ''3474 let target = src3475 endif3476 while target =~ '_\s*$'3477 " If ends in _ it is probably indirect link, process it3478 let title = matchstr(target, '^\s*\(`\?\)\zs.*\ze\1_\s*$')3479 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != ''3480 let href = escape(g:vst_hlinkdb[title], '&\~')3481 else3482 let href = '#l'.tolower(VST_IdMaker(title))3483 endif3484 endwhile3485 endif3486 if class == ''3487 let class = matchstr(parline, ':class:\s*\zs.\{-}\ze\s*$')3488 endif3489 if identify == ''3490 let identify = matchstr(parline, ':identify:')3491 if identify != ''3492 if executable('identify') && noimage == 03493 let [width, height] = VST_IdentifyImage(src, parline)3494 else3495 let [width, height] = ['', '']3496 endif3497 endif3498 endif3499 endfor3500 if src != ''3501 let tempsrc = VST_ProtectLiteral(src)3502 let src = 'src="'.tempsrc.'"'3503 endif3504 if scale != ''3505 if width != ''3506 let width = width*scale/1003507 endif3508 if height != ''3509 let height = height*scale/1003510 endif3511 endif3512 if width != ''3513 let width = ' width="'.width.'"'3514 endif3515 if height != ''3516 let height = ' height="'.height.'"'3517 endif3518 if alt != ''3519 let alt = ' alt="'.alt.'"'3520 else3521 let alt = ' alt="'.tempsrc.'"'3522 endif3523 if title != ''3524 let title = ' title="'.title.'"'3525 endif3526 if class != ''3527 if align == ''3528 let class = ' class="'.class.inline.'"'3529 else3530 let class = ' class="'.class.inline.' vst'.align.'"'3531 endif3532 else3533 if align == ''3534 if inline != ''3535 let class = ' class="inline"'3536 else3537 let class = ' '3538 endif3539 else3540 let class = ' class="vst'.align.'"'3541 endif3542 endif3543 3544 if src != ''3545 if target != ''3546 if target =~ '_\s*$'3547 let address = matchstr(VST_Hyperlink(target), '^.\{-}>\ze')3548 else3549 let address = '<vim:a href="'.VST_ProtectLiteral(target).'">'3550 endif3551 let para = address.nl."<vim:img ".src.width.height.class.alt.title." />".nl."</vim:a>"3552 else3553 let para = "\n<vim:img ".src.width.height.class.alt.title." />".nl3554 endif3555 else3556 let para = '<vim:!-- '.a:par.' -->'3557 endif3558 if a:full == 13559 return "<vim:p>\n".para."\n</vim:p>"3560 else3561 return para3562 endif3419 if a:full == 1 3420 let nl = "\n" 3421 let inline = '' 3422 else 3423 " This will be inline image. No need for new line at the end of tag 3424 " and we have to declare inlininess of it 3425 let nl = '' 3426 let inline = ' inline' 3427 endif 3428 let src = '' 3429 let width = '' 3430 let height = '' 3431 let alt = '' 3432 let title = '' 3433 let identify = '' 3434 let align = '' 3435 let scale = '' 3436 let target = '' 3437 let class = '' 3438 let parlines = split(a:par, '\n') 3439 for parline in parlines 3440 let parline = substitute(parline, '^\s*', '', '') 3441 if src == '' 3442 let src = matchstr(parline, '\(\.\. \)\?image::\s*\zs.\{-}\ze\s*$') 3443 if !filereadable(escape(src, ' \#%')) 3444 let noimage = 1 3445 let g:vst_error .= "No image: ".src."\n" 3446 else 3447 let noimage = 0 3448 endif 3449 endif 3450 if width == '' 3451 let width = matchstr(parline, ':width:\s*\zs.\{-}\ze\s*$') 3452 endif 3453 if height == '' 3454 let height = matchstr(parline, ':height:\s*\zs.\{-}\ze\s*$') 3455 endif 3456 if alt == '' 3457 let alt = matchstr(parline, ':alt:\s*\zs.\{-}\ze\s*$') 3458 endif 3459 if title == '' 3460 let title = matchstr(parline, ':title:\s*\zs.\{-}\ze\s*$') 3461 endif 3462 if align == '' 3463 let align = matchstr(parline, ':align:\s*\zs.\{-}\ze\s*$') 3464 endif 3465 if scale == '' 3466 let scale = matchstr(parline, ':scale:\s*\zs.\{-}\ze\s*$') 3467 if scale =~ '\D' 3468 let scale = '' 3469 endif 3470 endif 3471 if target == '' 3472 let target = matchstr(parline, ':target:\s*\zs.\{-}\ze\s*$') 3473 if target == 'self' && src != '' 3474 let target = src 3475 endif 3476 while target =~ '_\s*$' 3477 " If ends in _ it is probably indirect link, process it 3478 let title = matchstr(target, '^\s*\(`\?\)\zs.*\ze\1_\s*$') 3479 if has_key(g:vst_hlinkdb, title) && g:vst_hlinkdb[title] != '' 3480 let href = escape(g:vst_hlinkdb[title], '&\~') 3481 else 3482 let href = '#l'.tolower(VST_IdMaker(title)) 3483 endif 3484 endwhile 3485 endif 3486 if class == '' 3487 let class = matchstr(parline, ':class:\s*\zs.\{-}\ze\s*$') 3488 endif 3489 if identify == '' 3490 let identify = matchstr(parline, ':identify:') 3491 if identify != '' 3492 if executable('identify') && noimage == 0 3493 let [width, height] = VST_IdentifyImage(src, parline) 3494 else 3495 let [width, height] = ['', ''] 3496 endif 3497 endif 3498 endif 3499 endfor 3500 if src != '' 3501 let tempsrc = VST_ProtectLiteral(src) 3502 let src = 'src="'.tempsrc.'"' 3503 endif 3504 if scale != '' 3505 if width != '' 3506 let width = width*scale/100 3507 endif 3508 if height != '' 3509 let height = height*scale/100 3510 endif 3511 endif 3512 if width != '' 3513 let width = ' width="'.width.'"' 3514 endif 3515 if height != '' 3516 let height = ' height="'.height.'"' 3517 endif 3518 if alt != '' 3519 let alt = ' alt="'.alt.'"' 3520 else 3521 let alt = ' alt="'.tempsrc.'"' 3522 endif 3523 if title != '' 3524 let title = ' title="'.title.'"' 3525 endif 3526 if class != '' 3527 if align == '' 3528 let class = ' class="'.class.inline.'"' 3529 else 3530 let class = ' class="'.class.inline.' vst'.align.'"' 3531 endif 3532 else 3533 if align == '' 3534 if inline != '' 3535 let class = ' class="inline"' 3536 else 3537 let class = ' ' 3538 endif 3539 else 3540 let class = ' class="vst'.align.'"' 3541 endif 3542 endif 3543 3544 if src != '' 3545 if target != '' 3546 if target =~ '_\s*$' 3547 let address = matchstr(VST_Hyperlink(target), '^.\{-}>\ze') 3548 else 3549 let address = '<vim:a href="'.VST_ProtectLiteral(target).'">' 3550 endif 3551 let para = address.nl."<vim:img ".src.width.height.class.alt.title." />".nl."</vim:a>" 3552 else 3553 let para = "\n<vim:img ".src.width.height.class.alt.title." />".nl 3554 endif 3555 else 3556 let para = '<vim:!-- '.a:par.' -->' 3557 endif 3558 if a:full == 1 3559 return "<vim:p>\n".para."\n</vim:p>" 3560 else 3561 return para 3562 endif 3563 3563 endfunction 3564 3564 " }}} 3565 3565 " VST_LabelFootnote: Create auto-numbered footnotes [#first]_ {{{ 3566 3566 function! VST_LabelFootnote(text) 3567 let par = a:text3568 for label in keys(g:lfnotes)3569 let k = g:lfnotes[label]3570 let par = substitute(par, '\[#'.label.']_', '<vim:a href="#footnote-'.k.'" name="target-'.k.'">['.k.']</vim:a>', 'g')3571 endfor3572 3573 unlet! k3574 3575 return par3567 let par = a:text 3568 for label in keys(g:lfnotes) 3569 let k = g:lfnotes[label] 3570 let par = substitute(par, '\[#'.label.']_', '<vim:a href="#footnote-'.k.'" name="target-'.k.'">['.k.']</vim:a>', 'g') 3571 endfor 3572 3573 unlet! k 3574 3575 return par 3576 3576 3577 3577 endfunction 3578 3578 " }}} 3579 " VST_Markup: Create inline markup of text styles " {{{3579 " VST_Markup: Create inline markup of text styles " {{{ 3580 3580 function! VST_Markup(text) 3581 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g')3582 " Technical spaces3583 let par = ' '.par.' '3584 " Take care about escaping of asterisk3585 let par = substitute(par, '\\\@<!\\\*', '-vst-escape-asterisk-', 'g')3586 " Take care about single asterisk3587 let par = substitute(par, ' \* ', ' \* ', 'g')3588 " Take care about single asterisk inside of (), {}, [], '', ""3589 let par = substitute(par, "\\([[({<]\\)\\*\\([])}> ]\\)", '\1\*\2', 'g')3590 let par = substitute(par, "\\(['\"]\\)\\*\\([\"']\\)", '\1\*\2', 'g')3591 " Take care about double asterisk inside of (), {}, [], '', ""3592 let par = substitute(par, "\\([[({<]\\)\\*\\*\\([])}> ]\\)", '\1\*\*\2', 'g')3593 let par = substitute(par, "\\(['\"]\\)\\*\\*\\([\"']\\)", '\1\*\*\2', 'g')3594 " Take care about backticks inside of (), {}, [], '', ""3595 let par = substitute(par, "\\([[({<]\\)`\\([])}> ]\\)", '\1\`\2', 'g')3596 let par = substitute(par, "\\(['\"]\\)`\\([\"']\\)", '\1\`\2', 'g')3597 " Take care about double backticks inside of (), {}, [], '', ""3598 let par = substitute(par, "\\([[({<]\\)``\\([])}> ]\\)", '\1\`\`\2', 'g')3599 let par = substitute(par, "\\(['\"]\\)``\\([\"']\\)", '\1\`\`\2', 'g')3600 "" **strong**, Note: second space in next 3 LOC is nonbreaking space - \x1603601 let par = substitute(par, "[- '\"([{</:>~]\\@<=\\*\\* \\@<!\\(.\\{-}\\)\\*\\*[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:strong>\1</vim:strong>', 'g')3602 "" *emph*3603 let par = substitute(par, "[- '\"([{</:>~]\\@<=\\* \\@<!\\(.\\{-1,}\\)\\*[\\]<\\- '\")}>/\\\:.,;!?]\\@=", '<vim:em>\1</vim:em>', 'g')3604 "" ``literal`` (<code> like), ``code``, Note: space after :space: is3605 " nonbreaking space, not included into :space:3606 let par = substitute(par, "[- '\"([{</:>~]\\@<=``\\([^[:space:] ]\\)\\(.\\{-}\\)``[\\]<\\- '\")}>/\\\:.,;!?]\\@=", '\="<vim:code>".VST_ProtectLiteral(submatch(1).submatch(2))."</vim:code>"', 'g')3607 3608 let par = substitute(par, ' -vst-new-line- ', '\n', 'g')3609 3610 " Restore escaped asterisk3611 let par = substitute(par, '-vst-escape-asterisk-', '\\*', 'g')3612 " Restore asterisks3613 let par = substitute(par, '*', '*', 'g')3614 " Restore backticks3615 let par = substitute(par, '`', '`', 'g')3616 " Remove technical spaces3617 let par = substitute(par, ' $', '', '')3618 let par = substitute(par, '^ ', '', '')3619 3620 3621 return par3581 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g') 3582 " Technical spaces 3583 let par = ' '.par.' ' 3584 " Take care about escaping of asterisk 3585 let par = substitute(par, '\\\@<!\\\*', '-vst-escape-asterisk-', 'g') 3586 " Take care about single asterisk 3587 let par = substitute(par, ' \* ', ' \* ', 'g') 3588 " Take care about single asterisk inside of (), {}, [], '', "" 3589 let par = substitute(par, "\\([[({<]\\)\\*\\([])}> ]\\)", '\1\*\2', 'g') 3590 let par = substitute(par, "\\(['\"]\\)\\*\\([\"']\\)", '\1\*\2', 'g') 3591 " Take care about double asterisk inside of (), {}, [], '', "" 3592 let par = substitute(par, "\\([[({<]\\)\\*\\*\\([])}> ]\\)", '\1\*\*\2', 'g') 3593 let par = substitute(par, "\\(['\"]\\)\\*\\*\\([\"']\\)", '\1\*\*\2', 'g') 3594 " Take care about backticks inside of (), {}, [], '', "" 3595 let par = substitute(par, "\\([[({<]\\)`\\([])}> ]\\)", '\1\`\2', 'g') 3596 let par = substitute(par, "\\(['\"]\\)`\\([\"']\\)", '\1\`\2', 'g') 3597 " Take care about double backticks inside of (), {}, [], '', "" 3598 let par = substitute(par, "\\([[({<]\\)``\\([])}> ]\\)", '\1\`\`\2', 'g') 3599 let par = substitute(par, "\\(['\"]\\)``\\([\"']\\)", '\1\`\`\2', 'g') 3600 "" **strong**, Note: second space in next 3 LOC is nonbreaking space - \x160 3601 let par = substitute(par, "[- '\"([{</:>~]\\@<=\\*\\* \\@<!\\(.\\{-}\\)\\*\\*[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:strong>\1</vim:strong>', 'g') 3602 "" *emph* 3603 let par = substitute(par, "[- '\"([{</:>~]\\@<=\\* \\@<!\\(.\\{-1,}\\)\\*[\\]<\\- '\")}>/\\\:.,;!?]\\@=", '<vim:em>\1</vim:em>', 'g') 3604 "" ``literal`` (<code> like), ``code``, Note: space after :space: is 3605 " nonbreaking space, not included into :space: 3606 let par = substitute(par, "[- '\"([{</:>~]\\@<=``\\([^[:space:] ]\\)\\(.\\{-}\\)``[\\]<\\- '\")}>/\\\:.,;!?]\\@=", '\="<vim:code>".VST_ProtectLiteral(submatch(1).submatch(2))."</vim:code>"', 'g') 3607 3608 let par = substitute(par, ' -vst-new-line- ', '\n', 'g') 3609 3610 " Restore escaped asterisk 3611 let par = substitute(par, '-vst-escape-asterisk-', '\\*', 'g') 3612 " Restore asterisks 3613 let par = substitute(par, '*', '*', 'g') 3614 " Restore backticks 3615 let par = substitute(par, '`', '`', 'g') 3616 " Remove technical spaces 3617 let par = substitute(par, ' $', '', '') 3618 let par = substitute(par, '^ ', '', '') 3619 3620 3621 return par 3622 3622 endfunction 3623 3623 " }}} … … 3626 3626 " entities. 3627 3627 function! VST_ProtectLiteral(text) 3628 " Escaping of special characters3629 "let par = substitute(a:text, "[[`\_|:]", '\="\&#".char2nr(submatch(0)).";"', 'g')3630 let par = substitute(a:text, '`', '\`', 'g')3631 let par = substitute(par, '[', '\[', 'g')3632 let par = substitute(par, '\', '\\', 'g')3633 let par = substitute(par, '_', '\_', 'g')3634 let par = substitute(par, '|', '\|', 'g')3635 " : is required part of raw links, if we don't want to convert them,3636 " "remove" colon3637 let par = substitute(par, ':', '\:', 'g')3638 3639 return par3628 " Escaping of special characters 3629 "let par = substitute(a:text, "[[`\_|:]", '\="\&#".char2nr(submatch(0)).";"', 'g') 3630 let par = substitute(a:text, '`', '\`', 'g') 3631 let par = substitute(par, '[', '\[', 'g') 3632 let par = substitute(par, '\', '\\', 'g') 3633 let par = substitute(par, '_', '\_', 'g') 3634 let par = substitute(par, '|', '\|', 'g') 3635 " : is required part of raw links, if we don't want to convert them, 3636 " "remove" colon 3637 let par = substitute(par, ':', '\:', 'g') 3638 3639 return par 3640 3640 endfunction 3641 3641 " }}} 3642 " VST_RemoveTags: Returns given string without vim tags {{{3642 " VST_RemoveTags: Returns given string without vim tags {{{ 3643 3643 function! VST_RemoveTags(text) 3644 return substitute(a:text, '<.\?vim:[^>]\{-}>', '', 'g')3644 return substitute(a:text, '<.\?vim:[^>]\{-}>', '', 'g') 3645 3645 3646 3646 endfunction … … 3649 3649 function! VST_Replacement(text) 3650 3650 3651 let par = a:text3652 " Loop through entries in replacedb3653 " keys and values have to be proper Vim regexp constructs3654 for key in keys(g:vst_replacedb)3655 let replace = g:vst_replacedb[key]3656 "let replace = escape(g:vst_replacedb[key], '\&~')3657 " [^:] blocks processing of reST style image replacement3658 if replace =~ '^image:[^:]'3659 " Old style image, deprecated {{{3660 " Create image. We have here one line of pairs term:definition,3661 " but definition can be a string with spaces embraced in quotes.3662 " image:src with:420 alt:"this image"3663 let img = substitute(replace, '\(\w\+\):', ',"\1":', 'g')3664 let img = substitute(img, ':\([^"].\{-}\)\( \|$\)', ':"\1"', 'g')3665 let img = '{'.substitute(img, '^\s*,', '', 'g').'}'3666 unlet! g:image3667 let g:image = eval(img)3668 let replace = '<vim:img class="inline" '3669 for attr in keys(g:image)3670 if attr == 'image'3671 let item = 'src="'.g:image[attr].'" '3672 let replace .= item3673 elseif attr == 'identify' || attr == 'target'3674 continue3675 else3676 let item = attr.'="'.g:image[attr].'" '3677 let replace .= item3678 endif3679 endfor3680 let replace .= '/>'3681 if has_key(g:image, 'target')3682 if g:image['target'] == 'self'3683 let ttarget = g:image['image']3684 endif3685 let replace = '<vim:a href="'.g:image['image'].'">'.replace.'</vim:a>'3686 endif3687 let par = substitute(par, '|'.key.'|', replace, 'g')3688 " }}}3689 elseif replace =~ '^replace::'3690 " Plain replace {{{3691 if replace =~ ':ltrim:'3692 let ltrim = '\s*'3693 let rtrim = ''3694 elseif replace =~ ':trim:'3695 let ltrim = '\s*'3696 let rtrim = '\s*'3697 elseif replace =~ ':rtrim:'3698 let ltrim = ''3699 let rtrim = '\s*'3700 else3701 let ltrim = ''3702 let rtrim = ''3703 endif3704 " Process special characters in key: lt, gt, amp3705 " They were already processed in text3706 let key = substitute(key, '&', '\&', 'g')3707 let key = substitute(key, '<', '\<', 'g')3708 let key = substitute(key, '>', '\>', 'g')3709 let replace = matchstr(replace, '^replace::\s*\zs.\{-}\ze\_s*\(\.\. \|:trim:\|:ltrim:\|:rtrim:\|$\)')3710 "let replace = matchstr(replace, '^replace::\s*\zs.\{-}\ze\s*$')3711 let replace = escape(VST_SpecCharacter(replace), '&~\')3712 if par =~ '|_'3713 " Placeholder necessary to later trigger markup commands3714 let par = substitute(par, ltrim.'|'.key.'|__'.rtrim, '`{-vst-replace-{'.replace.'}-vst-replace-}`__', 'g')3715 let par = substitute(par, ltrim.'|'.key.'|_'.rtrim, '`{-vst-replace-{'.replace.'}-vst-replace-}`_', 'g')3716 if has_key(g:vst_hlinkdb, key)3717 " replace can contain markup - in text it will be proceed,3718 " in db no. Force3719 let proceed = VST_Markup(replace)3720 let proceed = VST_Roles(proceed)3721 let proceed = VST_EscapingSlash(proceed)3722 " And remove tags!3723 let proceed = substitute(proceed, '<.\?vim:[^>]\{-}>', '', 'g')3724 let g:vst_hlinkdb[tolower(proceed)] = g:vst_hlinkdb[key]3725 endif3726 endif3727 let par = substitute(par, ltrim.'|'.key.'|'.rtrim, replace, 'g')3728 " }}}3729 elseif replace =~ '^unicode::'3730 " Unicode {{{3731 if replace =~ ':ltrim:'3732 let ltrim = '\s*'3733 let rtrim = ''3734 elseif replace =~ ':trim:'3735 let ltrim = '\s*'3736 let rtrim = '\s*'3737 elseif replace =~ ':rtrim:'3738 let ltrim = ''3739 let rtrim = '\s*'3740 else3741 let ltrim = ''3742 let rtrim = ''3743 endif3744 let g:vst_encoding = "utf-8"3745 " We need this interference - without that character would be3746 " inserted improperly3747 let origenc = &encoding3748 set encoding=utf-83749 let key = substitute(key, '&', '\&', 'g')3750 let key = substitute(key, '<', '\<', 'g')3751 let key = substitute(key, '>', '\>', 'g')3752 let replace = matchstr(replace, '^unicode::\s*\zs.\{-}\ze\s*\(\.\. \|:trim:\|:ltrim:\|:rtrim:\|$\)')3753 let replace = substitute(replace, '\(0x\|x\|\\x\|U+\|u\|\\u\|&#x\)\([0-9a-fA-F]\+\)', '\=Unicode2Char(submatch(2))', 'g')3754 let replace = substitute(replace, '\_s' , '', 'g')3755 let replace = escape(VST_SpecCharacter(replace), '&~\')3756 if par =~ '|_'3757 let par = substitute(par, '|'.key.'|__', '`'.replace.'`__', 'g')3758 let par = substitute(par, '|'.key.'|_', '`'.replace.'`_', 'g')3759 if has_key(g:vst_hlinkdb, key)3760 " replace can contain markup - in text it will be proceed,3761 " in db no. Force3762 let proceed = VST_Markup(replace)3763 let proceed = VST_Roles(proceed)3764 let proceed = VST_EscapingSlash(proceed)3765 " And remove tags!3766 let proceed = substitute(proceed, '<.\?vim:[^>]\{-}>', '', 'g')3767 let g:vst_hlinkdb[tolower(proceed)] = g:vst_hlinkdb[key]3768 endif3769 endif3770 "let par = substitute(par, ltrim.'|'.key.'|__'.rtrim, '`'.replace.'`__', 'g')3771 "let par = substitute(par, ltrim.'|'.key.'|_'.rtrim, '`'.replace.'`_', 'g')3772 let par = substitute(par, ltrim.'|'.key.'|'.rtrim, replace, 'g')3773 let &encoding = origenc3774 " }}}3775 elseif replace =~ '^image::'3776 " Image replacement {{{3777 let replace = VST_ImagePar(replace, 0)3778 let replace = escape(replace, '&~\')3779 let par = substitute(par, '|'.key.'|', replace, 'g')3780 " }}}3781 elseif replace =~ '^date::'3782 " Date replacement {{{3783 let replace = matchstr(replace, 'date::\s*\zs.*$')3784 let replace = substitute(replace, '\s*$', '', '')3785 if exists("*strftime")3786 if replace == ''3787 let replace = strftime("%Y-%m-%d")3788 else3789 let replace = strftime(replace)3790 endif3791 else3792 let replace = localtime()3793 endif3794 3795 let replace = escape(replace, '&~\')3796 let par = substitute(par, '|'.key.'|', replace, 'g')3797 " }}}3798 elseif replace =~ '^\w\+::'3799 " Don't perform replacement of reST style replacement directives.3800 " This can cause big mess.3801 continue3802 endif3803 endfor3804 3805 3806 return par3651 let par = a:text 3652 " Loop through entries in replacedb 3653 " keys and values have to be proper Vim regexp constructs 3654 for key in keys(g:vst_replacedb) 3655 let replace = g:vst_replacedb[key] 3656 "let replace = escape(g:vst_replacedb[key], '\&~') 3657 " [^:] blocks processing of reST style image replacement 3658 if replace =~ '^image:[^:]' 3659 " Old style image, deprecated {{{ 3660 " Create image. We have here one line of pairs term:definition, 3661 " but definition can be a string with spaces embraced in quotes. 3662 " image:src with:420 alt:"this image" 3663 let img = substitute(replace, '\(\w\+\):', ',"\1":', 'g') 3664 let img = substitute(img, ':\([^"].\{-}\)\( \|$\)', ':"\1"', 'g') 3665 let img = '{'.substitute(img, '^\s*,', '', 'g').'}' 3666 unlet! g:image 3667 let g:image = eval(img) 3668 let replace = '<vim:img class="inline" ' 3669 for attr in keys(g:image) 3670 if attr == 'image' 3671 let item = 'src="'.g:image[attr].'" ' 3672 let replace .= item 3673 elseif attr == 'identify' || attr == 'target' 3674 continue 3675 else 3676 let item = attr.'="'.g:image[attr].'" ' 3677 let replace .= item 3678 endif 3679 endfor 3680 let replace .= '/>' 3681 if has_key(g:image, 'target') 3682 if g:image['target'] == 'self' 3683 let ttarget = g:image['image'] 3684 endif 3685 let replace = '<vim:a href="'.g:image['image'].'">'.replace.'</vim:a>' 3686 endif 3687 let par = substitute(par, '|'.key.'|', replace, 'g') 3688 " }}} 3689 elseif replace =~ '^replace::' 3690 " Plain replace {{{ 3691 if replace =~ ':ltrim:' 3692 let ltrim = '\s*' 3693 let rtrim = '' 3694 elseif replace =~ ':trim:' 3695 let ltrim = '\s*' 3696 let rtrim = '\s*' 3697 elseif replace =~ ':rtrim:' 3698 let ltrim = '' 3699 let rtrim = '\s*' 3700 else 3701 let ltrim = '' 3702 let rtrim = '' 3703 endif 3704 " Process special characters in key: lt, gt, amp 3705 " They were already processed in text 3706 let key = substitute(key, '&', '\&', 'g') 3707 let key = substitute(key, '<', '\<', 'g') 3708 let key = substitute(key, '>', '\>', 'g') 3709 let replace = matchstr(replace, '^replace::\s*\zs.\{-}\ze\_s*\(\.\. \|:trim:\|:ltrim:\|:rtrim:\|$\)') 3710 "let replace = matchstr(replace, '^replace::\s*\zs.\{-}\ze\s*$') 3711 let replace = escape(VST_SpecCharacter(replace), '&~\') 3712 if par =~ '|_' 3713 " Placeholder necessary to later trigger markup commands 3714 let par = substitute(par, ltrim.'|'.key.'|__'.rtrim, '`{-vst-replace-{'.replace.'}-vst-replace-}`__', 'g') 3715 let par = substitute(par, ltrim.'|'.key.'|_'.rtrim, '`{-vst-replace-{'.replace.'}-vst-replace-}`_', 'g') 3716 if has_key(g:vst_hlinkdb, key) 3717 " replace can contain markup - in text it will be proceed, 3718 " in db no. Force 3719 let proceed = VST_Markup(replace) 3720 let proceed = VST_Roles(proceed) 3721 let proceed = VST_EscapingSlash(proceed) 3722 " And remove tags! 3723 let proceed = substitute(proceed, '<.\?vim:[^>]\{-}>', '', 'g') 3724 let g:vst_hlinkdb[tolower(proceed)] = g:vst_hlinkdb[key] 3725 endif 3726 endif 3727 let par = substitute(par, ltrim.'|'.key.'|'.rtrim, replace, 'g') 3728 " }}} 3729 elseif replace =~ '^unicode::' 3730 " Unicode {{{ 3731 if replace =~ ':ltrim:' 3732 let ltrim = '\s*' 3733 let rtrim = '' 3734 elseif replace =~ ':trim:' 3735 let ltrim = '\s*' 3736 let rtrim = '\s*' 3737 elseif replace =~ ':rtrim:' 3738 let ltrim = '' 3739 let rtrim = '\s*' 3740 else 3741 let ltrim = '' 3742 let rtrim = '' 3743 endif 3744 let g:vst_encoding = "utf-8" 3745 " We need this interference - without that character would be 3746 " inserted improperly 3747 let origenc = &encoding 3748 set encoding=utf-8 3749 let key = substitute(key, '&', '\&', 'g') 3750 let key = substitute(key, '<', '\<', 'g') 3751 let key = substitute(key, '>', '\>', 'g') 3752 let replace = matchstr(replace, '^unicode::\s*\zs.\{-}\ze\s*\(\.\. \|:trim:\|:ltrim:\|:rtrim:\|$\)') 3753 let replace = substitute(replace, '\(0x\|x\|\\x\|U+\|u\|\\u\|&#x\)\([0-9a-fA-F]\+\)', '\=Unicode2Char(submatch(2))', 'g') 3754 let replace = substitute(replace, '\_s' , '', 'g') 3755 let replace = escape(VST_SpecCharacter(replace), '&~\') 3756 if par =~ '|_' 3757 let par = substitute(par, '|'.key.'|__', '`'.replace.'`__', 'g') 3758 let par = substitute(par, '|'.key.'|_', '`'.replace.'`_', 'g') 3759 if has_key(g:vst_hlinkdb, key) 3760 " replace can contain markup - in text it will be proceed, 3761 " in db no. Force 3762 let proceed = VST_Markup(replace) 3763 let proceed = VST_Roles(proceed) 3764 let proceed = VST_EscapingSlash(proceed) 3765 " And remove tags! 3766 let proceed = substitute(proceed, '<.\?vim:[^>]\{-}>', '', 'g') 3767 let g:vst_hlinkdb[tolower(proceed)] = g:vst_hlinkdb[key] 3768 endif 3769 endif 3770 "let par = substitute(par, ltrim.'|'.key.'|__'.rtrim, '`'.replace.'`__', 'g') 3771 "let par = substitute(par, ltrim.'|'.key.'|_'.rtrim, '`'.replace.'`_', 'g') 3772 let par = substitute(par, ltrim.'|'.key.'|'.rtrim, replace, 'g') 3773 let &encoding = origenc 3774 " }}} 3775 elseif replace =~ '^image::' 3776 " Image replacement {{{ 3777 let replace = VST_ImagePar(replace, 0) 3778 let replace = escape(replace, '&~\') 3779 let par = substitute(par, '|'.key.'|', replace, 'g') 3780 " }}} 3781 elseif replace =~ '^date::' 3782 " Date replacement {{{ 3783 let replace = matchstr(replace, 'date::\s*\zs.*$') 3784 let replace = substitute(replace, '\s*$', '', '') 3785 if exists("*strftime") 3786 if replace == '' 3787 let replace = strftime("%Y-%m-%d") 3788 else 3789 let replace = strftime(replace) 3790 endif 3791 else 3792 let replace = localtime() 3793 endif 3794 3795 let replace = escape(replace, '&~\') 3796 let par = substitute(par, '|'.key.'|', replace, 'g') 3797 " }}} 3798 elseif replace =~ '^\w\+::' 3799 " Don't perform replacement of reST style replacement directives. 3800 " This can cause big mess. 3801 continue 3802 endif 3803 endfor 3804 3805 3806 return par 3807 3807 endfunction 3808 3808 " }}} 3809 " VST_Roles: Change text :roles: into proper tags " {{{3809 " VST_Roles: Change text :roles: into proper tags " {{{ 3810 3810 function! VST_Roles(text) 3811 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g')3812 " Technical spaces3813 let par = ' '.par.' '3814 " :sub:`text` and `text`:sub:3815 let par = substitute(par, "[- `'\"([{</:>]\\@<=:sub:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g')3816 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:sub:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g')3817 let par = substitute(par, "[- `'\"([{</:>]\\@<=:subscript:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g')3818 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:subscript:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g')3819 " :sup:`text` and `text`:sup:3820 let par = substitute(par, "[- `'\"([{</:>]\\@<=:sup:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g')3821 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:sup:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g')3822 let par = substitute(par, "[- `'\"([{</:>]\\@<=:superscript:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g')3823 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:superscript:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g')3824 " :strong:`text` and `text`:strong:3825 let par = substitute(par, "[- `'\"([{</:>]\\@<=:strong:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:strong>\1</vim:strong>', 'g')3826 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:strong:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:strong>\1</vim:strong>', 'g')3827 " :emphasis:`text` and `text`:emphasis:3828 let par = substitute(par, "[- `'\"([{</:>]\\@<=:emphasis:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:em>\1</vim:em>', 'g')3829 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:emphasis:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:em>\1</vim:em>', 'g')3830 " :literal:`text` and `text`:literal:3831 let par = substitute(par, "[- `'\"([{</:>]\\@<=:literal:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:code>\1</vim:code>', 'g')3832 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:literal:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:code>\1</vim:code>', 'g')3833 " :big:`text` and `text`:big:3834 let par = substitute(par, "[- `'\"([{</:>]\\@<=:big:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="big">\1</vim:span>', 'g')3835 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:big:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="big">\1</vim:span>', 'g')3836 " :small:`text` and `text`:small:3837 let par = substitute(par, "[- `'\"([{</:>]\\@<=:small:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="small">\1</vim:span>', 'g')3838 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:small:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="small">\1</vim:span>', 'g')3839 " :title-reference:, :title:, :t:3840 let par = substitute(par, "[- `'\"([{</:>]\\@<=:title-reference:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g')3841 let par = substitute(par, "[- `'\"([{</:>]\\@<=:title:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g')3842 let par = substitute(par, "[- `'\"([{</:>]\\@<=:t:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g')3843 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:title-reference:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g')3844 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:title:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g')3845 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:t:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g')3846 " any other role3847 let par = substitute(par, "[- `'\"([{</:>]\\@<=:\\(\\S\\+\\):`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '\=VST_ExtraRoles(submatch(1), submatch(2))', 'g')3848 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:\\(\\S\\+\\):[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '\=VST_ExtraRoles(submatch(1), submatch(2))', 'g')3849 3850 let par = substitute(par, ' -vst-new-line- ', '\n', 'g')3851 " Remove technical spaces3852 let par = substitute(par, ' $', '', '')3853 let par = substitute(par, '^ ', '', '')3854 3855 return par3811 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g') 3812 " Technical spaces 3813 let par = ' '.par.' ' 3814 " :sub:`text` and `text`:sub: 3815 let par = substitute(par, "[- `'\"([{</:>]\\@<=:sub:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g') 3816 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:sub:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g') 3817 let par = substitute(par, "[- `'\"([{</:>]\\@<=:subscript:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g') 3818 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:subscript:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sub>\1</vim:sub>', 'g') 3819 " :sup:`text` and `text`:sup: 3820 let par = substitute(par, "[- `'\"([{</:>]\\@<=:sup:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g') 3821 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:sup:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g') 3822 let par = substitute(par, "[- `'\"([{</:>]\\@<=:superscript:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g') 3823 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:superscript:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:sup>\1</vim:sup>', 'g') 3824 " :strong:`text` and `text`:strong: 3825 let par = substitute(par, "[- `'\"([{</:>]\\@<=:strong:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:strong>\1</vim:strong>', 'g') 3826 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:strong:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:strong>\1</vim:strong>', 'g') 3827 " :emphasis:`text` and `text`:emphasis: 3828 let par = substitute(par, "[- `'\"([{</:>]\\@<=:emphasis:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:em>\1</vim:em>', 'g') 3829 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:emphasis:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:em>\1</vim:em>', 'g') 3830 " :literal:`text` and `text`:literal: 3831 let par = substitute(par, "[- `'\"([{</:>]\\@<=:literal:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:code>\1</vim:code>', 'g') 3832 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:literal:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:code>\1</vim:code>', 'g') 3833 " :big:`text` and `text`:big: 3834 let par = substitute(par, "[- `'\"([{</:>]\\@<=:big:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="big">\1</vim:span>', 'g') 3835 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:big:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="big">\1</vim:span>', 'g') 3836 " :small:`text` and `text`:small: 3837 let par = substitute(par, "[- `'\"([{</:>]\\@<=:small:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="small">\1</vim:span>', 'g') 3838 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:small:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:span class="small">\1</vim:span>', 'g') 3839 " :title-reference:, :title:, :t: 3840 let par = substitute(par, "[- `'\"([{</:>]\\@<=:title-reference:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g') 3841 let par = substitute(par, "[- `'\"([{</:>]\\@<=:title:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g') 3842 let par = substitute(par, "[- `'\"([{</:>]\\@<=:t:`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g') 3843 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:title-reference:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g') 3844 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:title:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g') 3845 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:t:[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '<vim:cite>\1</vim:cite>', 'g') 3846 " any other role 3847 let par = substitute(par, "[- `'\"([{</:>]\\@<=:\\(\\S\\+\\):`\\([^`]\\{-1,}\\)`[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '\=VST_ExtraRoles(submatch(1), submatch(2))', 'g') 3848 let par = substitute(par, "[- `'\"([{</:>]\\@<=`\\([^`]\\{-1,}\\)`:\\(\\S\\+\\):[\\]\\- '\")}<>/\\\:.,;!?]\\@=", '\=VST_ExtraRoles(submatch(1), submatch(2))', 'g') 3849 3850 let par = substitute(par, ' -vst-new-line- ', '\n', 'g') 3851 " Remove technical spaces 3852 let par = substitute(par, ' $', '', '') 3853 let par = substitute(par, '^ ', '', '') 3854 3855 return par 3856 3856 endfunction 3857 3857 " }}} 3858 " VST_DefaultRole: Change `default roles` into proper tags " {{{3858 " VST_DefaultRole: Change `default roles` into proper tags " {{{ 3859 3859 function! VST_DefaultRole(text) 3860 3860 3861 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g')3862 " Technical spaces3863 let par = ' '.par.' '3864 3865 " Take care about backticks inside of (), {}, [], '', ""3866 let par = substitute(par, "\\([['\"({<]\\)`\\([])}>\"']\\)", '\1\`\2', 'g')3867 3868 let split_file = split(par, '\(^\|-vst-new-line-\)\s*\.\. default-role::\s*')3869 3870 if len(split_file) == 13871 let roled = substitute(split_file[0], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\(.\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:cite>\1\2</vim:cite>', 'g')3872 else3873 for i in range(len(split_file))3874 3875 if i == 03876 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:]`]\\)\\(.\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:cite>\1\2</vim:cite>', 'g')3877 else3878 let role = matchstr(split_file[i], '^.\{-}\ze\s\+-vst-new-line- ')3879 let split_file[i] = substitute(split_file[i], '^.\{-}-vst-new-line- ', '', '')3880 if role =~ '^\(t\|title\|title-reference\)$'3881 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:cite>\1\2</vim:cite>', 'g')3882 elseif role =~ '^sup\(erscript\)\?$'3883 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:sup>\1\2</vim:sup>', 'g')3884 elseif role =~ '^sub\(script\)\?$'3885 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:sub>\1\2</vim:sub>', 'g')3886 elseif role =~ '^strong$'3887 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:strong>\1\2</vim:strong>', 'g')3888 elseif role =~ '^emphasis$'3889 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:em>\1\2</vim:em>', 'g')3890 elseif role =~ '^literal$'3891 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:code>\1\2</vim:code>', 'g')3892 elseif role =~ '^big$'3893 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span class="big">\1\2</vim:span>', 'g')3894 elseif role =~ '^small$'3895 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span class="small">\1\2</vim:span>', 'g')3896 else3897 let role = VST_IdMaker(role)3898 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span class="'.role.'">\1\2</vim:span>', 'g')3899 endif3900 endif3901 endfor3902 let roled = join(split_file, "\n")3903 endif3904 3905 let par = substitute(roled, ' -vst-new-line- ', '\n', 'g')3906 " Restore backticks3907 let par = substitute(par, '`', '`', 'g')3908 " Remove technical spaces3909 let par = substitute(par, ' $', '', '')3910 let par = substitute(par, '^ ', '', '')3911 3912 return par3861 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g') 3862 " Technical spaces 3863 let par = ' '.par.' ' 3864 3865 " Take care about backticks inside of (), {}, [], '', "" 3866 let par = substitute(par, "\\([['\"({<]\\)`\\([])}>\"']\\)", '\1\`\2', 'g') 3867 3868 let split_file = split(par, '\(^\|-vst-new-line-\)\s*\.\. default-role::\s*') 3869 3870 if len(split_file) == 1 3871 let roled = substitute(split_file[0], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\(.\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:cite>\1\2</vim:cite>', 'g') 3872 else 3873 for i in range(len(split_file)) 3874 3875 if i == 0 3876 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:]`]\\)\\(.\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:cite>\1\2</vim:cite>', 'g') 3877 else 3878 let role = matchstr(split_file[i], '^.\{-}\ze\s\+-vst-new-line- ') 3879 let split_file[i] = substitute(split_file[i], '^.\{-}-vst-new-line- ', '', '') 3880 if role =~ '^\(t\|title\|title-reference\)$' 3881 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:cite>\1\2</vim:cite>', 'g') 3882 elseif role =~ '^sup\(erscript\)\?$' 3883 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:sup>\1\2</vim:sup>', 'g') 3884 elseif role =~ '^sub\(script\)\?$' 3885 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:sub>\1\2</vim:sub>', 'g') 3886 elseif role =~ '^strong$' 3887 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:strong>\1\2</vim:strong>', 'g') 3888 elseif role =~ '^emphasis$' 3889 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:em>\1\2</vim:em>', 'g') 3890 elseif role =~ '^literal$' 3891 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:code>\1\2</vim:code>', 'g') 3892 elseif role =~ '^big$' 3893 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span class="big">\1\2</vim:span>', 'g') 3894 elseif role =~ '^small$' 3895 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span class="small">\1\2</vim:span>', 'g') 3896 else 3897 let role = VST_IdMaker(role) 3898 let split_file[i] = substitute(split_file[i], "[- '\"([{</:>;]\\@<=`\\([^[:space:] `]\\)\\([^`]\\{-}\\)`[`\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span class="'.role.'">\1\2</vim:span>', 'g') 3899 endif 3900 endif 3901 endfor 3902 let roled = join(split_file, "\n") 3903 endif 3904 3905 let par = substitute(roled, ' -vst-new-line- ', '\n', 'g') 3906 " Restore backticks 3907 let par = substitute(par, '`', '`', 'g') 3908 " Remove technical spaces 3909 let par = substitute(par, ' $', '', '') 3910 let par = substitute(par, '^ ', '', '') 3911 3912 return par 3913 3913 endfunction 3914 3914 " }}} … … 3919 3919 function! VST_SA_Hyperlink(text) 3920 3920 3921 function! VST_PunctTrap(link)3922 let punctless = a:link3923 if punctless =~ '[.?!;,]$'3924 let punctless = matchstr(punctless, '.*\ze.$')3925 endif3926 return VST_ProtectLiteral(punctless)3927 endfunction3928 3929 let par = a:text3930 " Handle standalone links in <> brackets.3931 let par = substitute(par, '<\(https\?://[a-zA-Z0-9./%&@#:;?=_-]\+\)>\(`_\)\@!', '\="\<<vim:a href=\"".VST_PunctTrap(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>\>"', 'g')3932 let par = substitute(par, '<\(s\?ftp://[a-zA-Z0-9./%&#@:;?=_-]\+\)>\(`_\)\@!', '\="\<<vim:a href=\"".VST_PunctTrap(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>\>"', 'g')3933 let par = substitute(par, '<mailto:\([a-zA-Z0-9@&#.;?=_-]\+\)>\(`_\)\@!', '\="\<<vim:a href=\"mailto:".VST_PunctTrap(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>\>"', 'g')3934 3935 let par = substitute(par, '\(href="\|<\)\@<!https\?://[a-zA-Z0-9./%&@#:;?=_-]\+', '\="<vim:a href=\"".VST_PunctTrap(submatch(0))."\">".VST_ProtectLiteral(submatch(0))."</vim:a>"', 'g')3936 let par = substitute(par, '\(href="\|<\)\@<!s\?ftp://[a-zA-Z0-9./%&#@:;?=_-]\+', '\="<vim:a href=\"".VST_PunctTrap(submatch(0))."\">".VST_ProtectLiteral(submatch(0))."</vim:a>"', 'g')3937 let par = substitute(par, '\(href="\|<\)\@<!mailto:\([a-zA-Z0-9@&#.;?=_-]\+\)', '\="<vim:a href=\"".VST_PunctTrap(submatch(0))."\">".VST_ProtectLiteral(submatch(2))."</vim:a>"', 'g')3938 3939 " Remove doubled links caused by http regexps.3940 let par = substitute(par, '\(<vim:a href=".\{-}">\)\1', '\1', 'g')3941 let par = substitute(par, '</vim:a></vim:a>', '</vim:a>', 'g')3942 " In 99% of causes some punct chars at the end of link (.?!;,) shouldn't be3943 " there and was already catched by VST_PunctTrap3944 let par = substitute(par, '\([.?!;,]\+\)</vim:a>', '</vim:a>\1', 'g')3945 3946 return par3921 function! VST_PunctTrap(link) 3922 let punctless = a:link 3923 if punctless =~ '[.?!;,]$' 3924 let punctless = matchstr(punctless, '.*\ze.$') 3925 endif 3926 return VST_ProtectLiteral(punctless) 3927 endfunction 3928 3929 let par = a:text 3930 " Handle standalone links in <> brackets. 3931 let par = substitute(par, '<\(https\?://[a-zA-Z0-9./%&@#:;?=_-]\+\)>\(`_\)\@!', '\="\<<vim:a href=\"".VST_PunctTrap(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>\>"', 'g') 3932 let par = substitute(par, '<\(s\?ftp://[a-zA-Z0-9./%&#@:;?=_-]\+\)>\(`_\)\@!', '\="\<<vim:a href=\"".VST_PunctTrap(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>\>"', 'g') 3933 let par = substitute(par, '<mailto:\([a-zA-Z0-9@&#.;?=_-]\+\)>\(`_\)\@!', '\="\<<vim:a href=\"mailto:".VST_PunctTrap(submatch(1))."\">".VST_ProtectLiteral(submatch(1))."</vim:a>\>"', 'g') 3934 3935 let par = substitute(par, '\(href="\|<\)\@<!https\?://[a-zA-Z0-9./%&@#:;?=_-]\+', '\="<vim:a href=\"".VST_PunctTrap(submatch(0))."\">".VST_ProtectLiteral(submatch(0))."</vim:a>"', 'g') 3936 let par = substitute(par, '\(href="\|<\)\@<!s\?ftp://[a-zA-Z0-9./%&#@:;?=_-]\+', '\="<vim:a href=\"".VST_PunctTrap(submatch(0))."\">".VST_ProtectLiteral(submatch(0))."</vim:a>"', 'g') 3937 let par = substitute(par, '\(href="\|<\)\@<!mailto:\([a-zA-Z0-9@&#.;?=_-]\+\)', '\="<vim:a href=\"".VST_PunctTrap(submatch(0))."\">".VST_ProtectLiteral(submatch(2))."</vim:a>"', 'g') 3938 3939 " Remove doubled links caused by http regexps. 3940 let par = substitute(par, '\(<vim:a href=".\{-}">\)\1', '\1', 'g') 3941 let par = substitute(par, '</vim:a></vim:a>', '</vim:a>', 'g') 3942 " In 99% of causes some punct chars at the end of link (.?!;,) shouldn't be 3943 " there and was already catched by VST_PunctTrap 3944 let par = substitute(par, '\([.?!;,]\+\)</vim:a>', '</vim:a>\1', 'g') 3945 3946 return par 3947 3947 endfunction 3948 3948 " }}} … … 3950 3950 " Supported: &, <, >, (c) 3951 3951 function! VST_SpecCharacter(text) 3952 " Escaping of special characters3953 let par = substitute(a:text, '&\([#a-z0-9]\+;\)\@!', '\&', 'g')3954 let par = substitute(par, '\\&[#a-z0-9]', '\&#', 'g')3955 let par = substitute(par, '(c)', '\©', 'g')3956 let par = substitute(par, '@', '\@', 'g')3957 let par = substitute(par, '<', '\<', 'g')3958 let par = substitute(par, '>', '\>', 'g')3959 return par3952 " Escaping of special characters 3953 let par = substitute(a:text, '&\([#a-z0-9]\+;\)\@!', '\&', 'g') 3954 let par = substitute(par, '\\&[#a-z0-9]', '\&#', 'g') 3955 let par = substitute(par, '(c)', '\©', 'g') 3956 let par = substitute(par, '@', '\@', 'g') 3957 let par = substitute(par, '<', '\<', 'g') 3958 let par = substitute(par, '>', '\>', 'g') 3959 return par 3960 3960 endfunction 3961 3961 " }}} 3962 " VST_Target: Create <span id> tags for _`inline targets` {{{3962 " VST_Target: Create <span id> tags for _`inline targets` {{{ 3963 3963 function! VST_Target(text) 3964 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g')3965 " Technical spaces3966 let par = ' '.par.' '3967 " _`Inline internal targets`3968 let par = substitute(par, "[- '\"([{</:>]\\@<=_`\\([^[:space:] `]\\)\\(.\\{-}\\)`[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span targetid="\1\2" title="\1\2" class="target">\1\2</vim:span>', 'g')3969 let par = substitute(par, "[- '\"([{</:>]\\@<=_\\([[:alnum:]._-]\\{-2,}\\)[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span targetid="\1" title="\1" class="target">\1</vim:span>', 'g')3970 let par = substitute(par, "[- '\"([{</:>]\\@<=_\\(\\k\\{-1,}\\)[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span targetid="\1" title="\1" class="target">\1</vim:span>', 'g')3971 " Strange splitting is necessary to be sure it will be unique and only one3972 " hyperlink per element.3973 let parlines = split(par, 'vim:span targeti')3974 let j = 03975 for parline in parlines3976 if parline =~ '^d='3977 let title = tolower(matchstr(parlines[j], '^d="\zs.\{-}\ze"'))3978 let href = VST_IdMaker(substitute(title, '\s\+-vst-new-line-\s\+', ' ', 'g'))3979 let parlines[j] = substitute(parlines[j], '^d=".\{-}"', 'd="l'.href.'"', 'g')3980 endif3981 let j += 13982 endfor3983 let par = join(parlines, 'vim:span i')3984 3985 let par = substitute(par, '^ ', '', '')3986 let par = substitute(par, ' $', '', '')3987 3988 let par = substitute(par, ' -vst-new-line- ', '\n', 'g')3989 3990 return par3964 let par = substitute(a:text, '\n', ' -vst-new-line- ', 'g') 3965 " Technical spaces 3966 let par = ' '.par.' ' 3967 " _`Inline internal targets` 3968 let par = substitute(par, "[- '\"([{</:>]\\@<=_`\\([^[:space:] `]\\)\\(.\\{-}\\)`[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span targetid="\1\2" title="\1\2" class="target">\1\2</vim:span>', 'g') 3969 let par = substitute(par, "[- '\"([{</:>]\\@<=_\\([[:alnum:]._-]\\{-2,}\\)[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span targetid="\1" title="\1" class="target">\1</vim:span>', 'g') 3970 let par = substitute(par, "[- '\"([{</:>]\\@<=_\\(\\k\\{-1,}\\)[\\]<\\- '\")}>/\\:\\.,;!?]\\@=", '<vim:span targetid="\1" title="\1" class="target">\1</vim:span>', 'g') 3971 " Strange splitting is necessary to be sure it will be unique and only one 3972 " hyperlink per element. 3973 let parlines = split(par, 'vim:span targeti') 3974 let j = 0 3975 for parline in parlines 3976 if parline =~ '^d=' 3977 let title = tolower(matchstr(parlines[j], '^d="\zs.\{-}\ze"')) 3978 let href = VST_IdMaker(substitute(title, '\s\+-vst-new-line-\s\+', ' ', 'g')) 3979 let parlines[j] = substitute(parlines[j], '^d=".\{-}"', 'd="l'.href.'"', 'g') 3980 endif 3981 let j += 1 3982 endfor 3983 let par = join(parlines, 'vim:span i') 3984 3985 let par = substitute(par, '^ ', '', '') 3986 let par = substitute(par, ' $', '', '') 3987 3988 let par = substitute(par, ' -vst-new-line- ', '\n', 'g') 3989 3990 return par 3991 3991 endfunction 3992 3992 " }}} … … 3994 3994 " lnum - current line to evaluate fold level 3995 3995 function! VST_FoldExpr(lnum) 3996 if getline(a:lnum) =~ "'"3997 let line = substitute(getline(a:lnum), "'", "''", 'g')3998 else3999 let line = getline(a:lnum)4000 endif4001 if b:vst_fold_lvl =~ 'r'4002 if string(b:vst_flvl_1) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4003 return '>1'4004 elseif string(b:vst_flvl_2) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4005 return '>2'4006 elseif string(b:vst_flvl_3) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4007 return '>3'4008 elseif string(b:vst_flvl_4) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4009 return '>4'4010 elseif string(b:vst_flvl_5) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4011 return '>5'4012 elseif string(b:vst_flvl_6) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4013 return '>6'4014 else4015 return '='4016 endif4017 endif4018 "let list = keys(b:vst_fold)4019 let list = keys(b:vst_fold_list)4020 if string(list) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]"4021 return '>1'4022 else4023 return '1'4024 endif3996 if getline(a:lnum) =~ "'" 3997 let line = substitute(getline(a:lnum), "'", "''", 'g') 3998 else 3999 let line = getline(a:lnum) 4000 endif 4001 if b:vst_fold_lvl =~ 'r' 4002 if string(b:vst_flvl_1) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4003 return '>1' 4004 elseif string(b:vst_flvl_2) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4005 return '>2' 4006 elseif string(b:vst_flvl_3) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4007 return '>3' 4008 elseif string(b:vst_flvl_4) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4009 return '>4' 4010 elseif string(b:vst_flvl_5) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4011 return '>5' 4012 elseif string(b:vst_flvl_6) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4013 return '>6' 4014 else 4015 return '=' 4016 endif 4017 endif 4018 "let list = keys(b:vst_fold) 4019 let list = keys(b:vst_fold_list) 4020 if string(list) =~? "[[ ]'".escape(line, '.*\[~&^$')."'[],]" 4021 return '>1' 4022 else 4023 return '1' 4024 endif 4025 4025 endfunction 4026 4026 " }}} … … 4029 4029 " <par number>) <par indentation> <par type> 4030 4030 function! VD() 4031 for i in range(len(g:paras))4032 "echo i.') '.g:pindent[i].' '.g:ptype[i].' '.split(g:paras[i], "\n")[0]."\n"4033 echo i.') '.g:pindent[i].' '.g:ptype[i].' '."\n"4034 endfor4031 for i in range(len(g:paras)) 4032 "echo i.') '.g:pindent[i].' '.g:ptype[i].' '.split(g:paras[i], "\n")[0]."\n" 4033 echo i.') '.g:pindent[i].' '.g:ptype[i].' '."\n" 4034 endfor 4035 4035 endfunction 4036 4036 " }}} … … 4039 4039 " functions 4040 4040 function! VST_End() 4041 unlet! g:paras g:paras_rez4042 unlet! g:pindent g:pindent_rez4043 "unlet! g:ptype g:ptype_rez4044 unlet! g:plinen g:plinen_rez4045 unlet! g:vst_recursion4046 unlet! g:vst_doc_title4041 unlet! g:paras g:paras_rez 4042 unlet! g:pindent g:pindent_rez 4043 "unlet! g:ptype g:ptype_rez 4044 unlet! g:plinen g:plinen_rez 4045 unlet! g:vst_recursion 4046 unlet! g:vst_doc_title 4047 4047 endfunction 4048 4048 " }}} 4049 4049 " }}} 4050 4050 4051 " Initialize error message4052 let g:vst_error = ''4053 4054 " Source project file4055 if filereadable("vstrc.vim")4056 source vstrc.vim4057 endif4058 4059 " We don't need freaking tabs!4060 setlocal expandtab4061 retab4062 4063 " For proper working of script nocompatible has to be set but setting it4064 " explicitly may break other settings which usually don't disturb4065 if &compatible == 14066 set nocompatible4067 endif4068 4069 let format = tolower(a:format)4070 4071 if format == ''4072 let format = 'html'4073 endif4074 4075 let text = getline(a:line1, a:line2)4076 4077 " Include external files before anything else will be done {{{4078 " But only for "real" export4079 if ',pdf,xml,html,s5,latex,tex,preproc,' =~ ','.format.','4080 let rec_counter = 04081 while rec_counter < &maxfuncdepth/24082 " if len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. \\(header\\|include\\|footer\\)::"')) > 04083 " Tried to do in one regexp, but its alternative was sometimes working, sometimes not4084 " Note: it always works... even inside of preformatted text4085 let isinclude = len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. include::"'))4086 let isheader = len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. header::"'))4087 let isfooter = len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. footer::"'))4088 " End loop when there are no including commands, save up to 1004089 " filtering4090 if isinclude == 0 && isheader == 0 && isfooter == 04091 break4092 endif4093 if isinclude > 0 || isheader > 0 || isfooter > 04094 let i = 04095 while i < len(text)4096 if text[i] =~ '^\s*\.\. \(header\|include\|footer\)::'4097 let include = matchlist(text[i], '^\(\s*\)\.\. \(header\|include\|footer\)::\s*\(.*\)\s*$')4098 " Do nothing if file isn't readable, general VST policy:4099 " silently ignore all author errors.4100 4101 if include[3] =~ '^<' && include[3] =~ '>$'4102 let include[3] = matchstr(include[3], '^.\zs.*\ze.$')4103 let include[3] = g:vst_included.'/'.include[3]4104 endif4105 " let inc_indent = len(include[1])4106 " EXPERIMENTAL: change \ into / - windows separator into4107 " unix separator and vice versa depending on running4108 " system4109 if has("win16") || has("win32") || has("win64") || has("win95") || has("dos16") || has("dos32")4110 let include[3] = substitute(include[3], '/', '\\', 'g')4111 else4112 let include[3] = substitute(include[3], '\\', '/', 'g')4113 endif4114 if filereadable(include[3])4115 let included = readfile(include[3])4116 call map(included, 'include[1].v:val')4117 if include[2] == 'header'4118 let text[i] = ''4119 let included += ['']4120 call extend(text, included, 0)4121 elseif include[2] == 'footer'4122 let text[i] = ''4123 let included = [''] + included4124 call extend(text, included)4125 else4126 let text[i] = ''4127 call extend(text, included, i+1)4128 endif4129 elseif include[3] == 'vstfooter' || include[3] == ''4130 if exists("*strftime")4131 let date = strftime("%c")4132 else4133 let date = "Unknown"4134 endif4135 let included = ['.. block:: vstfooter', '', ' -----------------------',4136 \ '', ' Vim reStructured Text document. Generated: '.date4137 \.'. `View VST source`_', '',4138 \ ' .. _view VST source: '.expand("%"),'']4139 call extend(text, included)4140 let text[i] = ''4141 elseif include[2] =~ 'header\|footer' && text[i-2] !~ '::\s*$'4142 " Second part of above condition is hack to allow for4143 " proper compilation of f/h examples. Simple test should4144 " cover most of them.4145 if include[2] == 'footer'4146 let text[i] = ''4147 if format !~ 's5'4148 let included = ['.. block:: vstfooter','', ' ------------------------',4149 \ '', ' '.VST_ProtectLiteral(include[3]), '']4150 call extend(text, included)4151 else4152 let s5footer = VST_ProtectLiteral(include[3])4153 endif4154 elseif include[2] == 'header'4155 let text[i] = ''4156 let included = ['.. block:: vstfooter','', ' '.VST_ProtectLiteral(include[3]),4157 \ '', ' ------------------------', '']4158 call extend(text, included, 0)4159 endif4160 else4161 if include[3] !~ '^{.*}$'4162 let text[i] = ''4163 let included = [include[1].'.. Unknown file: '.VST_ProtectLiteral(include[3]),4164 \ '', include[1].'..']4165 call extend(text, included, i+1)4166 endif4167 endif4168 if exists('included')4169 let i += len(included)4170 endif4171 endif4172 let i += 14173 endwhile4174 endif4175 let rec_counter += 14176 endwhile4177 unlet! rec_counter4178 endif4179 " }}}4180 " Preprocess text to ...{{{4181 " But not for preproc export:4182 if format !~ '^pre'4183 " Separate preprocessing for modeline correction4184 " Not elegant but prevents from messing with last element in main loop4185 " This take care about modeline in last line4186 " Remove filetype setting from modeline to not confuse Vim in exported4187 " files4188 for i in range(&modelines+1) + range(len(text)-&modelines, len(text)-1)4189 if get(text, i) != ''4190 if text[i] =~ '^\s*\.\. vim:.*re\?st'4191 let text[i] = substitute(text[i], '\s\?\%(filetype\|ft\)=re\?st', '', 'g')4192 if text[i] =~ 'vim:\s*\(set\)\?\s*:\?\s*$'4193 let text[i] = ''4194 endif4195 endif4196 endif4197 endfor4198 " We need to keep track of real lines. Create hash with keys of virtual4199 " lines created by preprocessing and real lines4200 let i = 04201 let g:vst_reallines = {}4202 let rl_correction = 04203 while i < len(text)-14204 " Remove control characters, some Emacs deviation4205 if text[i] =~ '[[:cntrl:]]'4206 let text[i] = substitute(text[i], '[[:cntrl:]]', '', 'g')4207 endif4208 " If comment directive is empty and following line is blank change4209 " it to .. comment:: directive. In this way indentation still will be4210 " taken into account4211 if text[i] =~ '^\s*\.\.\s*$' && text[i+1] =~ '^\s*$'4212 let text[i] = substitute(text[i], '^\(\s*\.\.\)', '\1 comment::', '')4213 endif4214 " Insert blank line between one line directives4215 if text[i] =~ '^\s*\(\.\.\|__\) ' && text[i+1] =~ '^\s*\(\.\.\|__\) '4216 let findent = strlen(matchstr(text[i], '^\s*'))4217 let sindent = strlen(matchstr(text[i+1], '^\s*'))4218 " But only if those .. are on the same level of indentation4219 if findent == sindent4220 call insert(text, '', i+1)4221 let rl_correction -= 14222 endif4223 endif4224 " Insert blank line between option of directive and directive in next4225 " line4226 if text[i] =~ '^\s\+:\w\+:' && text[i+1] =~ '^\s*\.\. '4227 let findent = strlen(matchstr(text[i], '^\s*'))4228 let sindent = strlen(matchstr(text[i+1], '^\s*'))4229 " But only if option has bigger indentation than directive4230 if (sindent + 3) <= findent4231 call insert(text, '', i+1)4232 let rl_correction -= 14233 endif4234 endif4235 " Insert blank line between named admonition and unordered|ordered4236 " list in next line Have to be splitted in two if's because || is4237 " horrible ineffective.4238 " LISTDEF: here is list definition which may require adjustment4239 if text[i] =~? '^\s*\.\. \(note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)::\s*$' && text[i+1] =~ '^\s*'.s:vst_bulletdef.'\s'4240 let findent = strlen(matchstr(text[i], '^\s*'))4241 let sindent = strlen(matchstr(text[i+1], '^\s*'))4242 " But only if list has bigger indentation than directive4243 if (findent + 3) <= sindent4244 call insert(text, '', i+1)4245 let rl_correction -= 14246 endif4247 endif4248 if text[i] =~? '^\s*\.\. \(note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)::\s*$' && text[i+1] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s'4249 let findent = strlen(matchstr(text[i], '^\s*'))4250 let sindent = strlen(matchstr(text[i+1], '^\s*'))4251 " But only if list has bigger indentation than directive4252 if (findent + 3) <= sindent4253 call insert(text, '', i+1)4254 let rl_correction -= 14255 endif4256 endif4257 let i += 14258 let g:vst_reallines[i] = i + rl_correction4259 endwhile4260 " In main loop we are not interested in last item, here add correction for4261 " this4262 let g:vst_reallines[i+1] = i + 1 + rl_correction4263 endif4264 " }}}4265 " Initiate variables for non export specific databases: {{{4266 let g:vst_headers = {}4267 let g:vst_hlinkdb = {}4268 let g:vst_replacedb = {}4269 let g:vst_roledb = {}4270 4271 " }}}4272 4273 let g:vst_anonhlinkdb = filter(copy(text), 'v:val =~ "^\\s*\\(\\.\\. __:\\|__ \\)"')4274 if ',pdf,xml,html,s5,latex,tex,' =~ ','.format.','4275 let g:vst_footnotedb = {}4276 let g:vst_citationdb = {}4277 let g:vst_fielddb = {}4278 let g:vst_metadb = {}4279 4280 unlet! g:vst_encoding4281 4282 " Necessary for working of labels4283 if '-' !~ '\k'4284 let b:vst_hyphenisk = 14285 set isk+=-4286 else4287 let b:vst_hyphenisk = 04288 endif4289 4290 " Main function4291 let file = VST_Structure(text)4292 4293 unlet! b:vst_afs4294 unlet! b:vst_first_parsing4295 4296 if file =~ '\[#\]_'4297 let file = VST_AutoFootnote(file)4298 endif4299 4300 " Process hyperlinks {{{4301 let lines = split(file, '<vim:p')4302 let i = 04303 while i < len(lines)4304 if lines[i] =~ '_'4305 " Take care about \`4306 let lines[i] = substitute(lines[i], '\\\@<!\\`__', '-vst-escape-backtick-ddash-', 'g')4307 let lines[i] = substitute(lines[i], '\\\@<!\\`_', '-vst-escape-backtick-dash-', 'g')4308 let lines[i] = substitute(lines[i], '\\\@<!\\`', '-vst-escape-backtick-', 'g')4309 " Take care about quoted backtick quoted backtics4310 let lines[i] = substitute(lines[i], "\\([['\"({<]\\)`\\([])}>\"' ]\\)", '\1\`\2', 'g')4311 let lines[i] = substitute(lines[i], "\\([['\"({<]\\)_`\\([])}>\"' ]\\)", '\1_\`\2', 'g')4312 " Take care about "``"4313 let lines[i] = substitute(lines[i], '"``"', '-vst-quot-dbacktick-', 'g')4314 " Take care about alone _ and __4315 let lines[i] = substitute(lines[i], ' _ ', ' \_ ', 'g')4316 let lines[i] = substitute(lines[i], ' __ ', ' \_\_ ', 'g')4317 " Take care about __ in programmer expressions __init__ like (shaky)4318 let lines[i] = substitute(lines[i], '\([[:punct:][:space:] ]\)__\(\k*\)__\([[:punct:][:space:] ]\?\)', '\1\_\_\2\_\_\3', 'g')4319 " Ugly, ugly, prevent from linkination of ".. __:" in text4320 let lines[i] = substitute(lines[i], ' __\(\S\)', ' \_\_\1', 'g')4321 " Take care about anonymous references4322 let lines[i] = substitute(lines[i], "\\([['\"({<]\\)__\\([])}>\"' ]\\)", '\1\_\_\2', 'g')4323 " Take care about "``"4324 4325 " Main hyperlink processing4326 let lines[i] = VST_Hyperlink(lines[i])4327 let lines[i] = VST_Target(lines[i])4328 4329 " Restore \`4330 let lines[i] = substitute(lines[i], '-vst-escape-backtick-ddash-', '\\`__', 'g')4331 let lines[i] = substitute(lines[i], '-vst-escape-backtick-dash-', '\\`_', 'g')4332 let lines[i] = substitute(lines[i], '-vst-escape-backtick-', '\\`', 'g')4333 " Take care about "``"4334 let lines[i] = substitute(lines[i], '-vst-quot-dbacktick-', '"``"', 'g')4335 " Restore ` and _4336 let lines[i] = substitute(lines[i], '`', '`', 'g')4337 let lines[i] = substitute(lines[i], '_', '_', 'g')4338 4339 endif4340 "if lines[i] =~ '\\'4341 "let lines[i] = VST_EscapingSlash(lines[i])4342 "endif4343 let i += 14344 endwhile4345 let file = join(lines, '<vim:p')4346 " Sometimes regexps are catching single _ as link. Remove such glitches4347 let file = substitute(file, '<vim:a href="#l_" title="_">_</vim:a>', '_', 'g')4348 " Sometimes regexps are catching \` as link. Remove such glitches4349 let file = substitute(file, '<vim:a href="#l\\`" title="\\`">\\`</vim:a>', '\\`', 'g')4350 " }}}4351 " Create footnote and citation dbs: {{{4352 " Go with stridx and strpart cutting file and retrieve information.4353 " Necessary for LaTeX export.4354 let fn = file4355 while stridx(fn, '<vim:footnote') != -14356 let index = stridx(fn, '<vim:footnote')4357 let fn = strpart(fn, index)4358 let number = matchstr(fn, '<vim:div class="fnumber"><vim:a href="#target-\d\+" name="footnote-\d\+">\[\zs\d\+\ze\]</vim:a></vim:div>')4359 let content = matchstr(fn, '<vim:div class="ftext">\zs.\{-}\ze\_s*</vim:div>')4360 let g:vst_footnotedb[number] = content4361 let fn = strpart(fn, 2)4362 endwhile4363 let fn = file4364 while stridx(fn, '<vim:citation') != -14365 let index = stridx(fn, '<vim:citation')4366 let fn = strpart(fn, index)4367 let label = matchstr(fn, '<vim:div class="cnumber"><vim:a href="#ctarget-\k\+" name="citation-\k\+">\[\zs\k\+\ze\]</vim:a></vim:div>')4368 let content = matchstr(fn, '<vim:div class="ctext">\zs.\{-}\ze\_s*</vim:div>')4369 let g:vst_citationdb[label] = '['.label.'] '.content4370 let fn = strpart(fn, 2)4371 endwhile4372 " }}}4373 4374 if len(g:vst_anonhlinkdb) > 04375 let file = VST_AnonHyperlink(file)4376 endif4377 4378 " Process default roles4379 let file = VST_DefaultRole(file)4380 " Remove escaping slashes.4381 let file = VST_EscapingSlash(file)4382 4383 " Removing - from 'isk'4384 if b:vst_hyphenisk == 14385 set isk-=-4386 endif4387 unlet! b:vst_hyphenisk4388 4389 " Replace ` with `4390 let file = substitute(file, '`', '`', 'g')4391 " Replace [ with [4392 let file = substitute(file, '[', '[', 'g')4393 " Replace \ with \4394 let file = substitute(file, '\', '\\', 'g')4395 " Replace _ with _4396 let file = substitute(file, '_', '_', 'g')4397 " Replace . with .4398 let file = substitute(file, '.', '.', 'g')4399 " Replace | with |4400 let file = substitute(file, '|', '|', 'g')4401 " Replace : with :4402 let file = substitute(file, ':', ':', 'g')4403 4404 " VST_URIMaker: Create real, properly encrypted URIs. {{{4405 function! VST_URIMaker(uri)4406 " Auxiliary functions lifted from eval.txt {{{4407 " The function Nr2Hex() returns the Hex string of a number.4408 func! Nr2Hex(nr)4409 let n = a:nr4410 let r = ""4411 while n4412 let r = '0123456789ABCDEF'[n % 16] . r4413 let n = n / 164414 endwhile4415 return r4416 endfunc4417 " The function String2Hex() converts each character in a string to a two4418 " character Hex string.4419 func! String2Hex(str)4420 let out = ''4421 let ix = 04422 while ix < strlen(a:str)4423 let out = out . Nr2Hex(char2nr(a:str[ix]))4424 let ix = ix + 14425 endwhile4426 return out4427 endfunc " }}}4428 let uri = a:uri4429 if uri =~ '^#'4430 return uri4431 endif4432 " URI:4433 if uri =~ '^[-_!~*():?;@&=+$.,/a-zA-Z0-9#]*$'4434 return uri4435 else4436 let elements = split(uri, '#')4437 let first = elements[0]4438 if len(elements) > 14439 let rest = '#'.join(elements[1:-1], '#')4440 else4441 let rest = ''4442 endif4443 let link = split(first, '.\zs')4444 let out = ''4445 let ix = 04446 while ix < len(link)4447 if link[ix] =~ '[-_!~*():?;@&=+$.,/a-zA-Z0-9#]'4448 let out .= link[ix]4449 elseif link[ix] =~ '%'4450 " Bold assumption: all escape sequences I saw on the net4451 " were uppercased4452 if link[ix+1] =~ '[A-F0-9]' && link[ix+2] =~ '[A-F0-9]'4453 let out .= link[ix] . link[ix+1] . link[ix+2]4454 let ix = ix + 24455 else4456 let out .= '%'.String2Hex('%')4457 endif4458 else4459 let out .= '%'.String2Hex(link[ix])4460 endif4461 let ix += 14462 endwhile4463 endif4464 return out.rest4465 endfunction4466 " }}}4467 let file = substitute(file, 'vim:\(img src="\|a href="\)\(.\{-}\)"', '\="vim:".submatch(1).VST_URIMaker(submatch(2))."\""', 'g')4468 4469 " Figure out proper MIME charset from the 'encoding' option. {{{4470 if exists("g:vst_encoding")4471 let encoding = g:vst_encoding4472 else4473 if &fileencoding != ''4474 let encoding = &fileencoding4475 else4476 let encoding = &encoding4477 endif4478 endif4479 if encoding =~ '^8bit\|^2byte'4480 let encoding = substitute(s:vim_encoding, '^8bit-\|^2byte-', '', '')4481 endif4482 if encoding == 'latin1'4483 let encoding = 'iso-8859-1'4484 elseif encoding =~ "^cp12"4485 let encoding = substitute(encoding, 'cp', 'windows-', '')4486 elseif encoding == 'sjis'4487 let encoding = 'Shift_JIS'4488 elseif encoding == 'euc-cn'4489 let encoding = 'GB_2312-80'4490 elseif encoding == 'euc-tw'4491 let encoding = ""4492 elseif encoding == 'big5'4493 let encoding = "Big5"4494 elseif encoding =~ '^euc\|^iso\|^koi'4495 let encoding = substitute(encoding, '.*', '\U\0', '')4496 elseif encoding == 'cp949'4497 let encoding = 'KS_C_5601-1987'4498 elseif encoding == 'cp936'4499 let encoding = 'GBK'4500 elseif encoding =~ '^ucs\|^utf'4501 let encoding = 'UTF-8'4502 else4503 let encoding = ""4504 endif4505 " }}}4506 let filename = expand("%:r")4507 endif4508 4509 if format =~ '^\(html\|s5\)$'4510 " HTML export {{{4511 4512 let language = matchstr(v:lang, '.*\ze_')4513 4514 " CSS: {{{4515 let rtp = split(&rtp, ',')4516 for i in range(len(rtp))4517 if filereadable(rtp[i].'/autoload/vst/default.css')4518 let defcssfile = rtp[i].'/autoload/vst/default.css'4519 break4520 endif4521 endfor4522 4523 let default_css = join(readfile(defcssfile), "\n")4524 4525 " g:vst_css_default g:vst_css_user4526 if g:vst_css_default == '' && g:vst_css_user == ''4527 let css = '<style type="text/css">'."\n".'/*<![CDATA[*/'."\n"4528 \ .default_css."\n".'/*]]>*/'."\n".'</style>'4529 endif4530 4531 if g:vst_css_default == '' && g:vst_css_user != ''4532 let css = '<style type="text/css">'."\n".'/*<![CDATA[*/'."\n"4533 \ .default_css."\n".'/*]]>*/'."\n".'</style>'4534 let css .= '<link rel="stylesheet" href="'.g:vst_css_user.'" type="text/css" />'."\n"4535 endif4536 4537 if g:vst_css_default != '' && g:vst_user_css == ''4538 if g:vst_css_default !~ 'NONE'4539 let completecss = ['/* Vim reStructured Text CSS */', ''] + split(default_css, '\n')4540 call writefile(completecss, g:vst_css_default)4541 let css = '<link rel="stylesheet" href="'.g:vst_css_default.'" type="text/css" />'."\n"4542 else4543 let css = "\n"4544 endif4545 endif4546 4547 if g:vst_css_default != '' && g:vst_css_user != ''4548 if g:vst_css_default !~ 'NONE'4549 let completecss = ['/* Vim reStructured Text CSS */', ''] + split(default_css, '\n')4550 call writefile(completecss, g:vst_css_default)4551 let css = '<link rel="stylesheet" href="'.g:vst_css_default.'" type="text/css" />'."\n"4552 else4553 let css = "\n"4554 endif4555 let css .= '<link rel="stylesheet" href="'.g:vst_css_user.'" type="text/css" />'."\n"4556 endif4557 " }}}4558 4559 " META Info {{{4560 let metainfo = ''4561 let metaauthor = ''4562 let metatitle = ''4563 let metasubject = ''4564 let metakeywords = ''4565 let metadate = ''4566 if has_key(g:vst_fielddb, 'author')4567 let metaauthor = '<meta name="Author" content="'.g:vst_fielddb['author']."\" />\n"4568 endif4569 if has_key(g:vst_fielddb, 'title')4570 let metatitle = '<meta name="Title" content="'.g:vst_fielddb['title']."\" />\n"4571 endif4572 if has_key(g:vst_fielddb, 'keywords')4573 let metakeywords = '<meta name="Keywords" content="'.g:vst_fielddb['keywords']."\" />\n"4574 endif4575 if has_key(g:vst_fielddb, 'subject')4576 let metasubject = '<meta name="Subject" content="'.g:vst_fielddb['subject']."\" />\n"4577 endif4578 if has_key(g:vst_fielddb, 'date')4579 if g:vst_fielddb['date'] != 'NONE'4580 let metadate = '<meta name="Date" content="'.g:vst_fielddb['date']."\" />\n"4581 endif4582 endif4583 let metainfo = metaauthor.metatitle.metakeywords.metasubject.metadate4584 4585 let metadata = ''4586 for key in keys(g:vst_metadb)4587 if key =~ '^http-equiv='4588 let item = substitute(key, 'http-equiv=\(.*\)', 'http-equiv="\1"', '')4589 let element = '<meta '.item.' content="'.g:vst_metadb[key].'" />'."\n"4590 elseif key =~ '^description \(lang\|scheme\|dir\)'4591 let item = substitute(key, 'description \(lang\|scheme\|dir\)=\(.*\)', 'name="description" \1="\2", '')4592 let element = '<meta '.item.' content="'.g:vst_metadb[key].'" />'."\n"4593 else4594 let element = '<meta name="'.key.'" content="'.g:vst_metadb[key].'" />'."\n"4595 endif4596 let metadata .= element4597 endfor4598 4599 if exists("g:vst_doc_title")4600 let htmltitle = substitute(g:vst_doc_title, '^\s*', '', '')4051 " Initialize error message 4052 let g:vst_error = '' 4053 4054 " Source project file 4055 if filereadable("vstrc.vim") 4056 source vstrc.vim 4057 endif 4058 4059 " We don't need freaking tabs! 4060 setlocal expandtab 4061 retab 4062 4063 " For proper working of script nocompatible has to be set but setting it 4064 " explicitly may break other settings which usually don't disturb 4065 if &compatible == 1 4066 set nocompatible 4067 endif 4068 4069 let format = tolower(a:format) 4070 4071 if format == '' 4072 let format = 'html' 4073 endif 4074 4075 let text = getline(a:line1, a:line2) 4076 4077 " Include external files before anything else will be done {{{ 4078 " But only for "real" export 4079 if ',pdf,xml,html,s5,latex,tex,preproc,' =~ ','.format.',' 4080 let rec_counter = 0 4081 while rec_counter < &maxfuncdepth/2 4082 " if len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. \\(header\\|include\\|footer\\)::"')) > 0 4083 " Tried to do in one regexp, but its alternative was sometimes working, sometimes not 4084 " Note: it always works... even inside of preformatted text 4085 let isinclude = len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. include::"')) 4086 let isheader = len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. header::"')) 4087 let isfooter = len(filter(copy(text), 'v:val =~ "^\\s*\\.\\. footer::"')) 4088 " End loop when there are no including commands, save up to 100 4089 " filtering 4090 if isinclude == 0 && isheader == 0 && isfooter == 0 4091 break 4092 endif 4093 if isinclude > 0 || isheader > 0 || isfooter > 0 4094 let i = 0 4095 while i < len(text) 4096 if text[i] =~ '^\s*\.\. \(header\|include\|footer\)::' 4097 let include = matchlist(text[i], '^\(\s*\)\.\. \(header\|include\|footer\)::\s*\(.*\)\s*$') 4098 " Do nothing if file isn't readable, general VST policy: 4099 " silently ignore all author errors. 4100 4101 if include[3] =~ '^<' && include[3] =~ '>$' 4102 let include[3] = matchstr(include[3], '^.\zs.*\ze.$') 4103 let include[3] = g:vst_included.'/'.include[3] 4104 endif 4105 " let inc_indent = len(include[1]) 4106 " EXPERIMENTAL: change \ into / - windows separator into 4107 " unix separator and vice versa depending on running 4108 " system 4109 if has("win16") || has("win32") || has("win64") || has("win95") || has("dos16") || has("dos32") 4110 let include[3] = substitute(include[3], '/', '\\', 'g') 4111 else 4112 let include[3] = substitute(include[3], '\\', '/', 'g') 4113 endif 4114 if filereadable(include[3]) 4115 let included = readfile(include[3]) 4116 call map(included, 'include[1].v:val') 4117 if include[2] == 'header' 4118 let text[i] = '' 4119 let included += [''] 4120 call extend(text, included, 0) 4121 elseif include[2] == 'footer' 4122 let text[i] = '' 4123 let included = [''] + included 4124 call extend(text, included) 4125 else 4126 let text[i] = '' 4127 call extend(text, included, i+1) 4128 endif 4129 elseif include[3] == 'vstfooter' || include[3] == '' 4130 if exists("*strftime") 4131 let date = strftime("%c") 4132 else 4133 let date = "Unknown" 4134 endif 4135 let included = ['.. block:: vstfooter', '', ' -----------------------', 4136 \ '', ' Vim reStructured Text document. Generated: '.date 4137 \.'. `View VST source`_', '', 4138 \ ' .. _view VST source: '.expand("%"),''] 4139 call extend(text, included) 4140 let text[i] = '' 4141 elseif include[2] =~ 'header\|footer' && text[i-2] !~ '::\s*$' 4142 " Second part of above condition is hack to allow for 4143 " proper compilation of f/h examples. Simple test should 4144 " cover most of them. 4145 if include[2] == 'footer' 4146 let text[i] = '' 4147 if format !~ 's5' 4148 let included = ['.. block:: vstfooter','', ' ------------------------', 4149 \ '', ' '.VST_ProtectLiteral(include[3]), ''] 4150 call extend(text, included) 4151 else 4152 let s5footer = VST_ProtectLiteral(include[3]) 4153 endif 4154 elseif include[2] == 'header' 4155 let text[i] = '' 4156 let included = ['.. block:: vstfooter','', ' '.VST_ProtectLiteral(include[3]), 4157 \ '', ' ------------------------', ''] 4158 call extend(text, included, 0) 4159 endif 4160 else 4161 if include[3] !~ '^{.*}$' 4162 let text[i] = '' 4163 let included = [include[1].'.. Unknown file: '.VST_ProtectLiteral(include[3]), 4164 \ '', include[1].'..'] 4165 call extend(text, included, i+1) 4166 endif 4167 endif 4168 if exists('included') 4169 let i += len(included) 4170 endif 4171 endif 4172 let i += 1 4173 endwhile 4174 endif 4175 let rec_counter += 1 4176 endwhile 4177 unlet! rec_counter 4178 endif 4179 " }}} 4180 " Preprocess text to ... {{{ 4181 " But not for preproc export: 4182 if format !~ '^pre' 4183 " Separate preprocessing for modeline correction 4184 " Not elegant but prevents from messing with last element in main loop 4185 " This take care about modeline in last line 4186 " Remove filetype setting from modeline to not confuse Vim in exported 4187 " files 4188 for i in range(&modelines+1) + range(len(text)-&modelines, len(text)-1) 4189 if get(text, i) != '' 4190 if text[i] =~ '^\s*\.\. vim:.*re\?st' 4191 let text[i] = substitute(text[i], '\s\?\%(filetype\|ft\)=re\?st', '', 'g') 4192 if text[i] =~ 'vim:\s*\(set\)\?\s*:\?\s*$' 4193 let text[i] = '' 4194 endif 4195 endif 4196 endif 4197 endfor 4198 " We need to keep track of real lines. Create hash with keys of virtual 4199 " lines created by preprocessing and real lines 4200 let i = 0 4201 let g:vst_reallines = {} 4202 let rl_correction = 0 4203 while i < len(text)-1 4204 " Remove control characters, some Emacs deviation 4205 if text[i] =~ '[[:cntrl:]]' 4206 let text[i] = substitute(text[i], '[[:cntrl:]]', '', 'g') 4207 endif 4208 " If comment directive is empty and following line is blank change 4209 " it to .. comment:: directive. In this way indentation still will be 4210 " taken into account 4211 if text[i] =~ '^\s*\.\.\s*$' && text[i+1] =~ '^\s*$' 4212 let text[i] = substitute(text[i], '^\(\s*\.\.\)', '\1 comment::', '') 4213 endif 4214 " Insert blank line between one line directives 4215 if text[i] =~ '^\s*\(\.\.\|__\) ' && text[i+1] =~ '^\s*\(\.\.\|__\) ' 4216 let findent = strlen(matchstr(text[i], '^\s*')) 4217 let sindent = strlen(matchstr(text[i+1], '^\s*')) 4218 " But only if those .. are on the same level of indentation 4219 if findent == sindent 4220 call insert(text, '', i+1) 4221 let rl_correction -= 1 4222 endif 4223 endif 4224 " Insert blank line between option of directive and directive in next 4225 " line 4226 if text[i] =~ '^\s\+:\w\+:' && text[i+1] =~ '^\s*\.\. ' 4227 let findent = strlen(matchstr(text[i], '^\s*')) 4228 let sindent = strlen(matchstr(text[i+1], '^\s*')) 4229 " But only if option has bigger indentation than directive 4230 if (sindent + 3) <= findent 4231 call insert(text, '', i+1) 4232 let rl_correction -= 1 4233 endif 4234 endif 4235 " Insert blank line between named admonition and unordered|ordered 4236 " list in next line Have to be splitted in two if's because || is 4237 " horrible ineffective. 4238 " LISTDEF: here is list definition which may require adjustment 4239 if text[i] =~? '^\s*\.\. \(note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)::\s*$' && text[i+1] =~ '^\s*'.s:vst_bulletdef.'\s' 4240 let findent = strlen(matchstr(text[i], '^\s*')) 4241 let sindent = strlen(matchstr(text[i+1], '^\s*')) 4242 " But only if list has bigger indentation than directive 4243 if (findent + 3) <= sindent 4244 call insert(text, '', i+1) 4245 let rl_correction -= 1 4246 endif 4247 endif 4248 if text[i] =~? '^\s*\.\. \(note\|tip\|warning\|attention\|caution\|danger\|error\|hint\|important\|admonition\)::\s*$' && text[i+1] =~ '^\s*\(\d\+\|[a-zA-Z]\|[icdvlmxICDVLMX]\+\|#\)[\]:.)}]\s' 4249 let findent = strlen(matchstr(text[i], '^\s*')) 4250 let sindent = strlen(matchstr(text[i+1], '^\s*')) 4251 " But only if list has bigger indentation than directive 4252 if (findent + 3) <= sindent 4253 call insert(text, '', i+1) 4254 let rl_correction -= 1 4255 endif 4256 endif 4257 let i += 1 4258 let g:vst_reallines[i] = i + rl_correction 4259 endwhile 4260 " In main loop we are not interested in last item, here add correction for 4261 " this 4262 let g:vst_reallines[i+1] = i + 1 + rl_correction 4263 endif 4264 " }}} 4265 " Initiate variables for non export specific databases: {{{ 4266 let g:vst_headers = {} 4267 let g:vst_hlinkdb = {} 4268 let g:vst_replacedb = {} 4269 let g:vst_roledb = {} 4270 4271 " }}} 4272 4273 let g:vst_anonhlinkdb = filter(copy(text), 'v:val =~ "^\\s*\\(\\.\\. __:\\|__ \\)"') 4274 if ',pdf,xml,html,s5,latex,tex,' =~ ','.format.',' 4275 let g:vst_footnotedb = {} 4276 let g:vst_citationdb = {} 4277 let g:vst_fielddb = {} 4278 let g:vst_metadb = {} 4279 4280 unlet! g:vst_encoding 4281 4282 " Necessary for working of labels 4283 if '-' !~ '\k' 4284 let b:vst_hyphenisk = 1 4285 set isk+=- 4286 else 4287 let b:vst_hyphenisk = 0 4288 endif 4289 4290 " Main function 4291 let file = VST_Structure(text) 4292 4293 unlet! b:vst_afs 4294 unlet! b:vst_first_parsing 4295 4296 if file =~ '\[#\]_' 4297 let file = VST_AutoFootnote(file) 4298 endif 4299 4300 " Process hyperlinks {{{ 4301 let lines = split(file, '<vim:p') 4302 let i = 0 4303 while i < len(lines) 4304 if lines[i] =~ '_' 4305 " Take care about \` 4306 let lines[i] = substitute(lines[i], '\\\@<!\\`__', '-vst-escape-backtick-ddash-', 'g') 4307 let lines[i] = substitute(lines[i], '\\\@<!\\`_', '-vst-escape-backtick-dash-', 'g') 4308 let lines[i] = substitute(lines[i], '\\\@<!\\`', '-vst-escape-backtick-', 'g') 4309 " Take care about quoted backtick quoted backtics 4310 let lines[i] = substitute(lines[i], "\\([['\"({<]\\)`\\([])}>\"' ]\\)", '\1\`\2', 'g') 4311 let lines[i] = substitute(lines[i], "\\([['\"({<]\\)_`\\([])}>\"' ]\\)", '\1_\`\2', 'g') 4312 " Take care about "``" 4313 let lines[i] = substitute(lines[i], '"``"', '-vst-quot-dbacktick-', 'g') 4314 " Take care about alone _ and __ 4315 let lines[i] = substitute(lines[i], ' _ ', ' \_ ', 'g') 4316 let lines[i] = substitute(lines[i], ' __ ', ' \_\_ ', 'g') 4317 " Take care about __ in programmer expressions __init__ like (shaky) 4318 let lines[i] = substitute(lines[i], '\([[:punct:][:space:] ]\)__\(\k*\)__\([[:punct:][:space:] ]\?\)', '\1\_\_\2\_\_\3', 'g') 4319 " Ugly, ugly, prevent from linkination of ".. __:" in text 4320 let lines[i] = substitute(lines[i], ' __\(\S\)', ' \_\_\1', 'g') 4321 " Take care about anonymous references 4322 let lines[i] = substitute(lines[i], "\\([['\"({<]\\)__\\([])}>\"' ]\\)", '\1\_\_\2', 'g') 4323 " Take care about "``" 4324 4325 " Main hyperlink processing 4326 let lines[i] = VST_Hyperlink(lines[i]) 4327 let lines[i] = VST_Target(lines[i]) 4328 4329 " Restore \` 4330 let lines[i] = substitute(lines[i], '-vst-escape-backtick-ddash-', '\\`__', 'g') 4331 let lines[i] = substitute(lines[i], '-vst-escape-backtick-dash-', '\\`_', 'g') 4332 let lines[i] = substitute(lines[i], '-vst-escape-backtick-', '\\`', 'g') 4333 " Take care about "``" 4334 let lines[i] = substitute(lines[i], '-vst-quot-dbacktick-', '"``"', 'g') 4335 " Restore ` and _ 4336 let lines[i] = substitute(lines[i], '`', '`', 'g') 4337 let lines[i] = substitute(lines[i], '_', '_', 'g') 4338 4339 endif 4340 "if lines[i] =~ '\\' 4341 " let lines[i] = VST_EscapingSlash(lines[i]) 4342 "endif 4343 let i += 1 4344 endwhile 4345 let file = join(lines, '<vim:p') 4346 " Sometimes regexps are catching single _ as link. Remove such glitches 4347 let file = substitute(file, '<vim:a href="#l_" title="_">_</vim:a>', '_', 'g') 4348 " Sometimes regexps are catching \` as link. Remove such glitches 4349 let file = substitute(file, '<vim:a href="#l\\`" title="\\`">\\`</vim:a>', '\\`', 'g') 4350 " }}} 4351 " Create footnote and citation dbs: {{{ 4352 " Go with stridx and strpart cutting file and retrieve information. 4353 " Necessary for LaTeX export. 4354 let fn = file 4355 while stridx(fn, '<vim:footnote') != -1 4356 let index = stridx(fn, '<vim:footnote') 4357 let fn = strpart(fn, index) 4358 let number = matchstr(fn, '<vim:div class="fnumber"><vim:a href="#target-\d\+" name="footnote-\d\+">\[\zs\d\+\ze\]</vim:a></vim:div>') 4359 let content = matchstr(fn, '<vim:div class="ftext">\zs.\{-}\ze\_s*</vim:div>') 4360 let g:vst_footnotedb[number] = content 4361 let fn = strpart(fn, 2) 4362 endwhile 4363 let fn = file 4364 while stridx(fn, '<vim:citation') != -1 4365 let index = stridx(fn, '<vim:citation') 4366 let fn = strpart(fn, index) 4367 let label = matchstr(fn, '<vim:div class="cnumber"><vim:a href="#ctarget-\k\+" name="citation-\k\+">\[\zs\k\+\ze\]</vim:a></vim:div>') 4368 let content = matchstr(fn, '<vim:div class="ctext">\zs.\{-}\ze\_s*</vim:div>') 4369 let g:vst_citationdb[label] = '['.label.'] '.content 4370 let fn = strpart(fn, 2) 4371 endwhile 4372 " }}} 4373 4374 if len(g:vst_anonhlinkdb) > 0 4375 let file = VST_AnonHyperlink(file) 4376 endif 4377 4378 " Process default roles 4379 let file = VST_DefaultRole(file) 4380 " Remove escaping slashes. 4381 let file = VST_EscapingSlash(file) 4382 4383 " Removing - from 'isk' 4384 if b:vst_hyphenisk == 1 4385 set isk-=- 4386 endif 4387 unlet! b:vst_hyphenisk 4388 4389 " Replace ` with ` 4390 let file = substitute(file, '`', '`', 'g') 4391 " Replace [ with [ 4392 let file = substitute(file, '[', '[', 'g') 4393 " Replace \ with \ 4394 let file = substitute(file, '\', '\\', 'g') 4395 " Replace _ with _ 4396 let file = substitute(file, '_', '_', 'g') 4397 " Replace . with . 4398 let file = substitute(file, '.', '.', 'g') 4399 " Replace | with | 4400 let file = substitute(file, '|', '|', 'g') 4401 " Replace : with : 4402 let file = substitute(file, ':', ':', 'g') 4403 4404 " VST_URIMaker: Create real, properly encrypted URIs. {{{ 4405 function! VST_URIMaker(uri) 4406 " Auxiliary functions lifted from eval.txt {{{ 4407 " The function Nr2Hex() returns the Hex string of a number. 4408 func! Nr2Hex(nr) 4409 let n = a:nr 4410 let r = "" 4411 while n 4412 let r = '0123456789ABCDEF'[n % 16] . r 4413 let n = n / 16 4414 endwhile 4415 return r 4416 endfunc 4417 " The function String2Hex() converts each character in a string to a two 4418 " character Hex string. 4419 func! String2Hex(str) 4420 let out = '' 4421 let ix = 0 4422 while ix < strlen(a:str) 4423 let out = out . Nr2Hex(char2nr(a:str[ix])) 4424 let ix = ix + 1 4425 endwhile 4426 return out 4427 endfunc " }}} 4428 let uri = a:uri 4429 if uri =~ '^#' 4430 return uri 4431 endif 4432 " URI: 4433 if uri =~ '^[-_!~*():?;@&=+$.,/a-zA-Z0-9#]*$' 4434 return uri 4435 else 4436 let elements = split(uri, '#') 4437 let first = elements[0] 4438 if len(elements) > 1 4439 let rest = '#'.join(elements[1:-1], '#') 4440 else 4441 let rest = '' 4442 endif 4443 let link = split(first, '.\zs') 4444 let out = '' 4445 let ix = 0 4446 while ix < len(link) 4447 if link[ix] =~ '[-_!~*():?;@&=+$.,/a-zA-Z0-9#]' 4448 let out .= link[ix] 4449 elseif link[ix] =~ '%' 4450 " Bold assumption: all escape sequences I saw on the net 4451 " were uppercased 4452 if link[ix+1] =~ '[A-F0-9]' && link[ix+2] =~ '[A-F0-9]' 4453 let out .= link[ix] . link[ix+1] . link[ix+2] 4454 let ix = ix + 2 4455 else 4456 let out .= '%'.String2Hex('%') 4457 endif 4458 else 4459 let out .= '%'.String2Hex(link[ix]) 4460 endif 4461 let ix += 1 4462 endwhile 4463 endif 4464 return out.rest 4465 endfunction 4466 " }}} 4467 let file = substitute(file, 'vim:\(img src="\|a href="\)\(.\{-}\)"', '\="vim:".submatch(1).VST_URIMaker(submatch(2))."\""', 'g') 4468 4469 " Figure out proper MIME charset from the 'encoding' option. {{{ 4470 if exists("g:vst_encoding") 4471 let encoding = g:vst_encoding 4472 else 4473 if &fileencoding != '' 4474 let encoding = &fileencoding 4475 else 4476 let encoding = &encoding 4477 endif 4478 endif 4479 if encoding =~ '^8bit\|^2byte' 4480 let encoding = substitute(s:vim_encoding, '^8bit-\|^2byte-', '', '') 4481 endif 4482 if encoding == 'latin1' 4483 let encoding = 'iso-8859-1' 4484 elseif encoding =~ "^cp12" 4485 let encoding = substitute(encoding, 'cp', 'windows-', '') 4486 elseif encoding == 'sjis' 4487 let encoding = 'Shift_JIS' 4488 elseif encoding == 'euc-cn' 4489 let encoding = 'GB_2312-80' 4490 elseif encoding == 'euc-tw' 4491 let encoding = "" 4492 elseif encoding == 'big5' 4493 let encoding = "Big5" 4494 elseif encoding =~ '^euc\|^iso\|^koi' 4495 let encoding = substitute(encoding, '.*', '\U\0', '') 4496 elseif encoding == 'cp949' 4497 let encoding = 'KS_C_5601-1987' 4498 elseif encoding == 'cp936' 4499 let encoding = 'GBK' 4500 elseif encoding =~ '^ucs\|^utf' 4501 let encoding = 'UTF-8' 4502 else 4503 let encoding = "" 4504 endif 4505 " }}} 4506 let filename = expand("%:r") 4507 endif 4508 4509 if format =~ '^\(html\|s5\)$' 4510 " HTML export {{{ 4511 4512 let language = matchstr(v:lang, '.*\ze_') 4513 4514 " CSS: {{{ 4515 let rtp = split(&rtp, ',') 4516 for i in range(len(rtp)) 4517 if filereadable(rtp[i].'/autoload/vst/default.css') 4518 let defcssfile = rtp[i].'/autoload/vst/default.css' 4519 break 4520 endif 4521 endfor 4522 4523 let default_css = join(readfile(defcssfile), "\n") 4524 4525 " g:vst_css_default g:vst_css_user 4526 if g:vst_css_default == '' && g:vst_css_user == '' 4527 let css = '<style type="text/css">'."\n".'/*<![CDATA[*/'."\n" 4528 \ .default_css."\n".'/*]]>*/'."\n".'</style>' 4529 endif 4530 4531 if g:vst_css_default == '' && g:vst_css_user != '' 4532 let css = '<style type="text/css">'."\n".'/*<![CDATA[*/'."\n" 4533 \ .default_css."\n".'/*]]>*/'."\n".'</style>' 4534 let css .= '<link rel="stylesheet" href="'.g:vst_css_user.'" type="text/css" />'."\n" 4535 endif 4536 4537 if g:vst_css_default != '' && g:vst_user_css == '' 4538 if g:vst_css_default !~ 'NONE' 4539 let completecss = ['/* Vim reStructured Text CSS */', ''] + split(default_css, '\n') 4540 call writefile(completecss, g:vst_css_default) 4541 let css = '<link rel="stylesheet" href="'.g:vst_css_default.'" type="text/css" />'."\n" 4542 else 4543 let css = "\n" 4544 endif 4545 endif 4546 4547 if g:vst_css_default != '' && g:vst_css_user != '' 4548 if g:vst_css_default !~ 'NONE' 4549 let completecss = ['/* Vim reStructured Text CSS */', ''] + split(default_css, '\n') 4550 call writefile(completecss, g:vst_css_default) 4551 let css = '<link rel="stylesheet" href="'.g:vst_css_default.'" type="text/css" />'."\n" 4552 else 4553 let css = "\n" 4554 endif 4555 let css .= '<link rel="stylesheet" href="'.g:vst_css_user.'" type="text/css" />'."\n" 4556 endif 4557 " }}} 4558 4559 " META Info {{{ 4560 let metainfo = '' 4561 let metaauthor = '' 4562 let metatitle = '' 4563 let metasubject = '' 4564 let metakeywords = '' 4565 let metadate = '' 4566 if has_key(g:vst_fielddb, 'author') 4567 let metaauthor = '<meta name="Author" content="'.g:vst_fielddb['author']."\" />\n" 4568 endif 4569 if has_key(g:vst_fielddb, 'title') 4570 let metatitle = '<meta name="Title" content="'.g:vst_fielddb['title']."\" />\n" 4571 endif 4572 if has_key(g:vst_fielddb, 'keywords') 4573 let metakeywords = '<meta name="Keywords" content="'.g:vst_fielddb['keywords']."\" />\n" 4574 endif 4575 if has_key(g:vst_fielddb, 'subject') 4576 let metasubject = '<meta name="Subject" content="'.g:vst_fielddb['subject']."\" />\n" 4577 endif 4578 if has_key(g:vst_fielddb, 'date') 4579 if g:vst_fielddb['date'] != 'NONE' 4580 let metadate = '<meta name="Date" content="'.g:vst_fielddb['date']."\" />\n" 4581 endif 4582 endif 4583 let metainfo = metaauthor.metatitle.metakeywords.metasubject.metadate 4584 4585 let metadata = '' 4586 for key in keys(g:vst_metadb) 4587 if key =~ '^http-equiv=' 4588 let item = substitute(key, 'http-equiv=\(.*\)', 'http-equiv="\1"', '') 4589 let element = '<meta '.item.' content="'.g:vst_metadb[key].'" />'."\n" 4590 elseif key =~ '^description \(lang\|scheme\|dir\)' 4591 let item = substitute(key, 'description \(lang\|scheme\|dir\)=\(.*\)', 'name="description" \1="\2", '') 4592 let element = '<meta '.item.' content="'.g:vst_metadb[key].'" />'."\n" 4593 else 4594 let element = '<meta name="'.key.'" content="'.g:vst_metadb[key].'" />'."\n" 4595 endif 4596 let metadata .= element 4597 endfor 4598 4599 if exists("g:vst_doc_title") 4600 let htmltitle = substitute(g:vst_doc_title, '^\s*', '', '') 4601 4601 let htmltitle = VST_SpecCharacter(htmltitle) 4602 elseif metasubject != ''4603 let htmltitle = g:vst_fielddb['subject']4604 else4605 let htmltitle = expand("%")4606 endif4607 " }}}4608 4609 " S5 special content {{{4610 if format == 's5'4611 if exists('s5footer')4612 let s5foot = VST_Structure(split(s5footer, '0000000000000000000'))4613 let s5foot = substitute(s5foot, '^\_s*<vim:p>\_s*', '', '')4614 let s5foot = substitute(s5foot, '\_s*</vim:p>\_s*$', '', '')4615 unlet! s5footer4616 else4617 if has_key(g:vst_fielddb, 'author')4618 let s5author = g:vst_fielddb['author']4619 else4620 let s5author = 'Author'4621 endif4622 if has_key(g:vst_fielddb, 'date') && g:vst_fielddb['date'] != 'NONE'4623 let s5date = g:vst_fielddb['date']4624 else4625 let s5date = 'Date'4626 endif4627 let s5foot = s5author.' • '.s5date4628 endif4629 let s5head = ''4630 \.'<!-- configuration parameters -->'."\n"4631 \.'<meta name="defaultView" content="slideshow" />'."\n"4632 \.'<meta name="controlVis" content="hidden" />'."\n"4633 \.'<meta name="version" content="S5 1.1" />'."\n"4634 \.'<!-- style sheet links -->'."\n"4635 \.'<link rel="stylesheet" href="s5ui/slides.css" type="text/css" media="projection" id="slideProj" />'."\n"4636 \.'<link rel="stylesheet" href="s5ui/outline.css" type="text/css" media="screen" id="outlineStyle" />'."\n"4637 \.'<link rel="stylesheet" href="s5ui/print.css" type="text/css" media="print" id="slidePrint" />'."\n"4638 \.'<link rel="stylesheet" href="s5ui/opera.css" type="text/css" media="projection" id="operaFix" />'."\n"4639 \.'<!-- S5 JS -->'."\n"4640 \.'<script src="s5ui/slides.js" type="text/javascript"></script>'."\n"4641 \.'<!-- VST-S5 -->'."\n"4642 \.'<style type="text/css">'."\n"4643 \.'/*<![CDATA[*/'."\n"4644 \.'h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { content: "" }'."\n"4645 \.'/*]]>*/'."\n"4646 \.'</style>'."\n"4647 let s5body = ''4648 \.'<div class="layout">'."\n"4649 \.'<div id="controls"><!-- DO NOT EDIT --></div>'."\n"4650 \.'<div id="currentSlide"><!-- DO NOT EDIT --></div>'."\n"4651 \.'<div id="header"></div>'."\n"4652 \.'<div id="footer">'."\n"4653 \.'<h1>'.htmltitle.'</h1>'."\n"4654 \.'<h2>'.s5foot.'</h2>'."\n"4655 \.'</div>'."\n"4602 elseif metasubject != '' 4603 let htmltitle = g:vst_fielddb['subject'] 4604 else 4605 let htmltitle = expand("%") 4606 endif 4607 " }}} 4608 4609 " S5 special content {{{ 4610 if format == 's5' 4611 if exists('s5footer') 4612 let s5foot = VST_Structure(split(s5footer, '0000000000000000000')) 4613 let s5foot = substitute(s5foot, '^\_s*<vim:p>\_s*', '', '') 4614 let s5foot = substitute(s5foot, '\_s*</vim:p>\_s*$', '', '') 4615 unlet! s5footer 4616 else 4617 if has_key(g:vst_fielddb, 'author') 4618 let s5author = g:vst_fielddb['author'] 4619 else 4620 let s5author = 'Author' 4621 endif 4622 if has_key(g:vst_fielddb, 'date') && g:vst_fielddb['date'] != 'NONE' 4623 let s5date = g:vst_fielddb['date'] 4624 else 4625 let s5date = 'Date' 4626 endif 4627 let s5foot = s5author.' • '.s5date 4628 endif 4629 let s5head = '' 4630 \.'<!-- configuration parameters -->'."\n" 4631 \.'<meta name="defaultView" content="slideshow" />'."\n" 4632 \.'<meta name="controlVis" content="hidden" />'."\n" 4633 \.'<meta name="version" content="S5 1.1" />'."\n" 4634 \.'<!-- style sheet links -->'."\n" 4635 \.'<link rel="stylesheet" href="s5ui/slides.css" type="text/css" media="projection" id="slideProj" />'."\n" 4636 \.'<link rel="stylesheet" href="s5ui/outline.css" type="text/css" media="screen" id="outlineStyle" />'."\n" 4637 \.'<link rel="stylesheet" href="s5ui/print.css" type="text/css" media="print" id="slidePrint" />'."\n" 4638 \.'<link rel="stylesheet" href="s5ui/opera.css" type="text/css" media="projection" id="operaFix" />'."\n" 4639 \.'<!-- S5 JS -->'."\n" 4640 \.'<script src="s5ui/slides.js" type="text/javascript"></script>'."\n" 4641 \.'<!-- VST-S5 -->'."\n" 4642 \.'<style type="text/css">'."\n" 4643 \.'/*<![CDATA[*/'."\n" 4644 \.'h1:before, h2:before, h3:before, h4:before, h5:before, h6:before { content: "" }'."\n" 4645 \.'/*]]>*/'."\n" 4646 \.'</style>'."\n" 4647 let s5body = '' 4648 \.'<div class="layout">'."\n" 4649 \.'<div id="controls"><!-- DO NOT EDIT --></div>'."\n" 4650 \.'<div id="currentSlide"><!-- DO NOT EDIT --></div>'."\n" 4651 \.'<div id="header"></div>'."\n" 4652 \.'<div id="footer">'."\n" 4653 \.'<h1>'.htmltitle.'</h1>'."\n" 4654 \.'<h2>'.s5foot.'</h2>'."\n" 4655 \.'</div>'."\n" 4656 4656 \.'</div>'."\n" 4657 4657 \.'<div class="presentation">' 4658 let s5body2 = "</div>\n</div>"4659 else4660 let s5body = ''4661 let s5head = ''4662 let s5body2 = ''4663 endif4664 " }}}4665 4666 let metainfo .= metadata4667 4668 if file =~ '<vim:ol[^>]*start="'4669 let g:zzz = 14670 let doctype =4671 \ '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"4672 \.' "http://www.w3.org/TR/html4/loose.dtd">'."\n"4673 "\ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '."\n"4674 "\.'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> '."\n"4675 else4676 let doctype =4677 \ '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n"4678 \.' "http://www.w3.org/TR/html4/strict.dtd">'."\n"4679 "\ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '."\n"4680 "\.' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n"4681 endif4682 4683 let header =4684 \ doctype4685 \.'<html xmlns="http://www.w3.org/1999/xhtml" lang="'.language.'" '4686 \.'xml:lang="'.language.'">'."\n"4687 \.'<head>'."\n"4688 \.'<meta http-equiv="Content-Type" content="text/html; charset='.encoding.'" />'."\n"4689 \.'<title>'.htmltitle.'</title>'."\n"4690 \.'<meta name="Generator" content="Vim reStructured Text '.s:vst_ver.' - Vim '.v:version/100.".".v:version % 100.'" />'."\n"4691 \.metainfo."\n"4692 \.css."\n"4693 \.s5head."\n"4694 \.'</head>'."\n"4695 \.'<body>'."\n"4696 4697 let closing = '</body>'."\n".'</html>'4698 4699 let file = header."\n".s5body."\n".file."\n".s5body2."\n".closing4700 let file = substitute(file, '</vim:', '</', 'g')4701 let file = substitute(file, '<vim:', '<', 'g')4702 " let file = substitute(file, '\(\[\d\+\]</a>\)_', '\1', 'g')4703 " let file = substitute(file, '\(\[#\]</a>\)_', '\1', 'g')4704 4705 " Create comment tags4706 let file = substitute(file, '</comment>', ' -->', 'g')4707 let file = substitute(file, '<comment.\{-}>', '<!-- ', 'g')4708 4709 " Replace rawlatex with pre tags4710 "let file = substitute(file, '</rawlatex', '</pre', 'g')4711 "let file = substitute(file, '<rawlatex>', '<pre class="rawlatex"', 'g')4712 "let file = substitute(file, '<rawlatex class="\(.\{-}\)">', '<pre class="rawlatex \1">', 'g')4713 " Remove rawlatex content4714 let file = substitute(file, '<rawlatex.\{-}</rawlatex>', '', 'g')4715 4716 " Remove latexonly tags and contents4717 let file = substitute(file, '<latexonly\.{-}>.\{-}</latexonly>', '', 'g')4718 4719 " Replace footnote and citation with div class="footnote"4720 let file = substitute(file, '</footnote', '</div', 'g')4721 let file = substitute(file, '<footnote>', '<div class="footnote">', 'g')4722 let file = substitute(file, '<footnote class="\(.\{-}\)">', '<div class="footnote \1">', 'g')4723 let file = substitute(file, '</citation', '</div', 'g')4724 let file = substitute(file, '<citation>', '<div class="footnote">', 'g')4725 let file = substitute(file, '<citation class="\(.\{-}\)">', '<div class="footnote \1">', 'g')4726 4727 " Replace topic with div4728 let file = substitute(file, '</topic', '</div', 'g')4729 let file = substitute(file, '<topic', '<div ', 'g')4730 4731 " Replace sidebar with div4732 let file = substitute(file, '</sidebar', '</div', 'g')4733 let file = substitute(file, '<sidebar', '<div ', 'g')4734 4735 " Replace figure with div4736 let file = substitute(file, '</figure', '</div', 'g')4737 let file = substitute(file, '<figure', '<div', 'g')4738 4739 " Replace block with div4740 let file = substitute(file, '</block\>', '</div', 'g')4741 let file = substitute(file, '<block\>', '<div', 'g')4742 4743 " Replace container with div4744 let file = substitute(file, '</container\>', '</div', 'g')4745 let file = substitute(file, '<container\>', '<div', 'g')4746 4747 " Replace unknown with div and header4748 let file = substitute(file, '</unknown\>', '</div', 'g')4749 let file = substitute(file, '<unknown>', '<div class="unknown"><strong>Unknown element:</strong><br />', 'g')4750 4751 " Replace pullquote with blockquote class4752 let file = substitute(file, '</pullquote', '</blockquote', 'g')4753 let file = substitute(file, '<pullquote>', '<blockquote class="pull">', 'g')4754 let file = substitute(file, '<pullquote class="\(.\{-}\)">', '<blockquote class="pull \1">', 'g')4755 4756 " Replace rubric with span class4757 let file = substitute(file, '</rubric', '</p', 'g')4758 let file = substitute(file, '<rubric>', '<p class="rubric">', 'g')4759 let file = substitute(file, '<rubric class="\(.\{-}\)">', '<p class="rubric \1">', 'g')4760 4761 " Turn field list (dl) into table.4762 " This can be expensive set of regexps so check if this element exists4763 " at all4764 if file =~ 'dt class="field'4765 let file = substitute(file, '<dl class="field\(.\{-}\)">', '<table class="field\1" summary="Field list">', 'g')4766 let file = substitute(file, '\(<dd class="field.\{-}\n\)</dl>', '\1</table>', 'g')4767 let file = substitute(file, '<dt class="field fabstract">Abstract<.dt><dd class="field fabstract">\(.\{-}\)<.dd>', '<tr><td class="fkey fakey" colspan="2">Abstract</td></tr><tr><td class="fval faval" colspan="2">\1</td></tr>', 'g')4768 let file = substitute(file, '<dt class="field fdedication">Dedication<.dt><dd class="field fdedication">\(.\{-}\)<.dd>', '<tr><td class="fkey fdkey" colspan="2">Dedication</td></tr><tr><td class="fval fdval" colspan="2">\1</td></tr>', 'g')4769 let file = substitute(file, '<dt class="field.\{-}>\(.\{-}\)<.dt><dd class="field.\{-}>\(.\{-}\)<.dd>', '<tr><td class="fkey">\1</td><td class="fval">\2</td></tr>', 'g')4770 endif4771 4772 " Replace weird table summary value with proper <col /> tags4773 let file = substitute(file, '<table\( class="vst.\{-}summary="\).\{-}coln\(.\{-}\)">', '\="<table".submatch(1)."\">".VST_ColNumbers(submatch(2))', 'g')4774 " Remove class attribute from closing of dl list4775 let file = substitute(file, '\(</dl\) class=".\{-}"', '\1', 'g')4776 4777 " Remove summary from td tags4778 let file = substitute(file, '\(<td[^>]*\) summary=".\{-}"', '\1', 'g')4779 4780 " Remove rawhtml tags4781 let file = substitute(file, '</rawhtml>', '', 'g')4782 let file = substitute(file, '<rawhtml.\{-}>', '', 'g')4783 4784 " Remove rawboth tags4785 let file = substitute(file, '</rawboth>', '', 'g')4786 let file = substitute(file, '<rawboth.\{-}>', '', 'g')4787 4788 " Remove htmlonly tags4789 let file = substitute(file, '</htmlonly>', '', 'g')4790 let file = substitute(file, '<htmlonly.\{-}>', '', 'g')4791 4792 " Remove consecutive empty lines4793 let file = substitute(file, '\n\n\{3,}', '\n\n', 'g')4794 4795 " Replace --(-) with emdash entity in attributions4796 let file = substitute(file, '\(<p class="attribution.\{-}>\_s\{-}\)---\?', '\1\—', 'g')4797 4798 " Add backlinks from section headers4799 if exists("b:IsTOC") && b:IsTOC == 14800 let file = substitute(file, '\(<h\d id="\)\(.\{-}\)"\(.\{-}>\)', '\1\2"\3<a href="#toc-\2">', 'g')4801 let file = substitute(file, '<\/h\d>', '<\/a>\0', 'g')4802 unlet! b:IsTOC4803 endif4804 4805 new4806 if &compatible == 14807 set nocompatible4808 endif4809 silent! 0put =file4810 " Beautify HTML a bit:4811 " Reduce indentation inside of <pre> tags to minimum of 1 space {{{4812 silent call cursor(1,1)4813 while search('^\s*<pre', 'W')4814 let rawlatex = (getline('.') =~ 'class="rawlatex' ? 1 : 0)4815 silent normal! j4816 let line1 = line('.')4817 let indlist = []4818 while getline('.') !~ '</pre'4819 if getline('.') =~ '^\s*$'4820 silent normal! j4821 continue4822 endif4823 let preind = strlen(matchstr(getline('.'), '^\s*'))4824 let indlist += [preind]4825 silent normal! j4826 endwhile4827 let line2 = line('.')-14828 " When pre is empty (closing tag is in next line after opening4829 " tag) don't continue4830 if line1 == line2 + 14831 continue4832 endif4833 let lineend = line('.')4834 let ind = min(indlist) <= 0 ? 0 : min(indlist)4835 silent exe line1.','.line2.'s/^ \{'.ind.'}/ /e'4836 " Previously doubled \ was treated as escaped and reduced to one.4837 " Now it is highly probable that one \ at the end of line was4838 " supposed to be new line symbol.4839 if rawlatex == 14840 silent exe line1.','.line2.'s/\\$/\\\\/e'4841 endif4842 endwhile4843 " }}}4844 " Put 2html CSS styles into head {{{4845 silent call cursor(1,1)4846 if search('<pre class="tohtml-[^"]\+">')4847 call VST_2html()4848 if exists('g:vst_2html_css')4849 silent call cursor(1,1)4850 let tohtml_css = '<style type="text/css">'."\n".'/*<![CDATA[*/'."\n"4851 \ .join(g:vst_2html_css, "\n")."\n".'/*]]>*/'."\n".'</style>'4852 call search('<\/head>')4853 put! =tohtml_css4854 unlet! g:vst_2html_css4855 endif4856 endif4857 redraw!4858 " }}}4859 " Insert raw files {{{4860 silent call cursor(1,1)4861 while search('-vst-raw-file-placeholder:', 'W')4862 let rawfile = matchstr(getline('.'), '-vst-raw-file-placeholder:\zs.*')4863 let g:rf = rawfile4864 silent s/.*//ge4865 if filereadable(rawfile)4866 exe 'silent read '.escape(rawfile, ' \#%')4867 endif4868 endwhile4869 " }}}4870 setlocal ft=html4871 4872 " S5 postprocessing {{{4873 if format == 's5'4874 silent call cursor(1,1)4875 silent call search('<div class="presentation">')4876 let line = line('.')4877 silent exe line.',$ s/<h1/<div class="slide">\r<h1/ge'4878 silent exe line.',$ s/<h2/<div class="slide">\r<h1/ge'4879 silent exe line.',$ s/<div class="slide">/<\/div>\r\0/ge'4880 silent exe line.',$ s/<\/h2>/<\/h1>/ge'4881 "silent g/<a href="http/s/<a href=".\{-}"/\0 class="external"/ge4882 silent exe line4883 silent exe line.',$ s/\(<div class="presentation">\)\_s*<\/div>/\1/ge'4884 " Create s5ui directory and file structure4885 if !isdirectory('s5ui')4886 call mkdir('s5ui')4887 endif4888 let s5files = [4889 \ 'blank.gif',4890 \ 'framing.css',4891 \ 'iepngfix.htc',4892 \ 'opera.css',4893 \ 'outline.css',4894 \ 'pretty.css',4895 \ 'print.css',4896 \ 's5-core.css',4897 \ 'slides.css',4898 \ 'slides.js']4899 let workingdir = expand('%:p:h').'/'4900 for file in s5files4901 if !filereadable('s5ui/'.file)4902 let rtp = split(&rtp, ',')4903 for i in range(len(rtp))4904 if filereadable(rtp[i].'/autoload/vst/s5ui/'.file)4905 let s5file = rtp[i].'/autoload/vst/s5ui/'.file4906 break4907 endif4908 endfor4909 silent exe 'below 1split '.escape(s5file, ' \#%')4910 silent exe 'write! '.escape(workingdir' \#%').'s5ui/'.escape(file, ' \#%')4911 silent exe 'bw! '.escape(s5file, ' \#%')4912 endif4913 endfor4914 " Write file after changes4915 silent exe 'cd '.escape(workingdir, ' \#%')4916 4917 endif4918 " }}}4919 if exists("g:vst_write_export") && g:vst_write_export != 04920 silent exe 'write! '.escape(filename, ' \#%').'.html'4921 endif4922 " User postprocessing4923 if g:vst_html_post != '' && filereadable(g:vst_html_post)4924 exe 'silent! source '.escape(g:vst_html_post, ' \#%')4925 endif4926 silent call cursor(1,1)4927 call VST_End()4928 " }}}4929 elseif format == 'xml'4930 " XML export {{{4931 new4932 silent 0put =file4933 setlocal ft=xml4934 if exists("g:vst_write_export") && g:vst_write_export != 04935 silent exe 'write! '.escape(filename, ' \#%').'.xml'4936 endif4937 silent call cursor(1,1)4938 call VST_End()4939 " }}}4940 elseif format =~? '^re\?st$'4941 " reST export {{{4942 let rest_file = getline(1, '$')4943 " Potential problems when size of register has limits. :help 'viminfo'4944 new4945 silent! 0put =rest_file4946 unlet! rest_file4947 silent! %s/\(^\s*\.\. \)block::/\1admonition::/ge4948 silent! g/^\s*:identify:/d4949 silent! %s/\(^\s*\)\(:\S.\{-} \)/\1--VIM, \2/ge4950 " <c-v>160 - non breaking space4951 silent! %s/\\\@<!\\-/ /ge4952 silent! %s/\(^\s*\)\.\. 2html::.*/\1::4953 silent call cursor(1,1)4954 " }}}4955 elseif format =~ '^\(tex\|pdf\)$'4956 " LaTeX export {{{4957 "4958 function! VST_CreateTexComment(text)4959 let scomm = split(a:text, '\n')4960 let i = 04961 while i < len(scomm)4962 let scomm[i] = substitute(scomm[i], '^', '%%', '')4963 let i += 14964 endwhile4965 let par = join(scomm, '\n')4966 return par4967 endfunction4968 4969 " Handle encoding and country options. {{{4970 let encoding = tolower(encoding)4971 if encoding =~ 'iso-8859-1\|iso-8859-15'4972 let encoding = 'latin1'4973 elseif encoding =~ "windows-"4974 let encoding = substitute(encoding, 'windows-', , 'cp', '')4975 elseif encoding == 'iso-8859-2'4976 let encoding = 'latin2'4977 elseif encoding == 'sjis'4978 let encoding = 'Shift_JIS'4979 elseif encoding == 'euc-cn'4980 let encoding = 'GB_2312-80'4981 elseif encoding == 'euc-tw'4982 let encoding = ""4983 elseif encoding =~ '^euc\|^iso\|^koi'4984 let encoding = substitute(encoding, '.*', '\U\0', '')4985 elseif encoding == 'cp949'4986 let encoding = 'KS_C_5601-1987'4987 elseif encoding == 'cp936'4988 let encoding = 'GBK'4989 elseif encoding =~ '^ucs\|^utf'4990 let encoding = 'UTF-8'4991 else4992 let encoding = ""4993 endif4994 4995 " Country specific settings4996 " Automatically add polski when iso-8859-2 is used.4997 if encoding =~ 'latin2\|cp1250'4998 let countrysettings = '\usepackage{polski}'4999 else5000 let countrysettings = ''5001 endif5002 " }}}5003 5004 " TOC depth5005 if exists("s:vst_tocdepth")5006 let tocdepth = '\setcounter{tocdepth}{'.s:vst_tocdepth.'}'5007 else5008 let tocdepth = ''5009 endif5010 5011 " User defined preamble5012 if exists("g:vst_tex_preamble") && filereadable(g:vst_tex_preamble)5013 let userpreamble = "\\input{".g:vst_tex_preamble."}"5014 else5015 let userpreamble = ''5016 endif5017 5018 let footer = '\end{document}'5019 5020 "let file = substitute(file, "><", ">\n<", "g")5021 " Special characters I5022 " Here to not catch any backslashes5023 let file = substitute(file, '\', '$\\backslash$', 'g')5024 " Here to not catch footnotes5025 let file = substitute(file, '{', '\\{', 'g')5026 let file = substitute(file, '}', '\\}', 'g')5027 5028 " Remove special chars catchers5029 let file = substitute(file, '@', '@', 'g')5030 let file = substitute(file, '[', '[', 'g')5031 let file = substitute(file, '\', '\\', 'g')5032 let file = substitute(file, ':', ':', 'g')5033 let file = substitute(file, '&\\#64;', '@', 'g')5034 let file = substitute(file, '&\\#91;', '[', 'g')5035 let file = substitute(file, '&\\#92;', '\\', 'g')5036 let file = substitute(file, '&\\#58;', ':', 'g')5037 5038 " Footnotes have to be here to process them by other substitutions:5039 for fn in keys(g:vst_footnotedb)5040 let fnumberleft = '<vim:a href="#footnote-'.fn.'" name="target-'.fn.'">\['5041 let fnumberright = '\]</vim:a>'5042 let content = escape(g:vst_footnotedb[fn], '&/\~')5043 let file = substitute(file, fnumberleft.fn.fnumberright, '\\footnote{'.content.'}', '')5044 endfor5045 " Citations have to be here to process them by other substitutions:5046 for fn in keys(g:vst_citationdb)5047 let fnumberleft = '<vim:a href="#citation-'.fn.'" name="ctarget-'.fn.'">\['5048 let fnumberright = '\]</vim:a>'5049 let content = escape(g:vst_citationdb[fn], '&/\~')5050 let file = substitute(file, fnumberleft.fn.fnumberright, '\\footnote{'.content.'}', '')5051 endfor5052 " Remove footnotes from xml5053 let file = substitute(file, '<vim:footnote.\{-}</vim:footnote>', '', 'g')5054 " Remove citations from xml5055 let file = substitute(file, '<vim:citation.\{-}</vim:citation>', '', 'g')5056 5057 " Replace rawhtml with pre tags5058 "let file = substitute(file, '<vim:rawhtml>', '<vim:pre>', 'g')5059 "let file = substitute(file, '<.vim:rawhtml>', '</vim:pre>', 'g')5060 5061 " Replace rawhtml with htmlonly tags5062 let file = substitute(file, '<vim:rawhtml>', '<vim:htmlonly>', 'g')5063 let file = substitute(file, '<.vim:rawhtml>', '</vim:htmlonly>', 'g')5064 5065 " Remove htmlonly tags and contents5066 let file = substitute(file, '<vim:htmlonly>.\{-}<.vim:htmlonly>', '', 'g')5067 5068 5069 " Special characters II5070 let file = substitute(file, '\~', '\\\~{}', 'g')5071 let file = substitute(file, ' ', '\~', 'g')5072 let file = substitute(file, '&', '\\\&', 'g')5073 let file = substitute(file, '<', '<', 'g')5074 let file = substitute(file, '>', '>', 'g')5075 let file = substitute(file, '©', '(c)', 'g')5076 let file = substitute(file, '#', '\\#', 'g')5077 let file = substitute(file, '\(backslash\)\@<!\$\(.backslash\)\@!', '\\$', 'g')5078 let file = substitute(file, '%', '\\%', 'g')5079 let file = substitute(file, '\^', '\\^{}', 'g')5080 " Hah. This will break _ in links. Problem may exists also with &5081 let file = substitute(file, '_', '\\_', 'g')5082 " TeX symbols5083 let file = substitute(file, 'LaTeX', '\\LaTeX{}', 'g')5084 let file = substitute(file, 'a\@<!TeX', '\\TeX{}', 'g')5085 " Very dirty hack to compile docs but should fix also other things.5086 " Maybe not so common but very hard to spot when proofreading text.5087 let file = substitute(file, '>\\<', '>\\\\<', 'g')5088 let file = substitute(file, '\(^\|\s\)\\\($\|\s\)', '\1\\\2', 'g')5089 "5090 let file = substitute(file, "^", '\\begin{document}'."\n", "")5091 5092 " Create subtitles5093 let file = substitute(file, '<vim:p class="subh.\{-}>\(.\{-}\)</vim:p>', '\\subtitle{\1}', "g")5094 5095 " Create verse environment5096 let file = substitute(file, '<vim:p class="verse.\{-}>\(.\{-}\)</vim:p>', '\\begin{verse}\n\1\n\\end{verse}', "g")5097 5098 " Create attributions5099 let file = substitute(file, '<vim:p class="attribution.\{-}>\(.\{-}\)</vim:p>', '\\attribution{\1}', "g")5100 5101 " Replace table of contents5102 let file = substitute(file, '<vim:p id="tocheader" \_.\{-}\.\. comment:: end of toc -->', '\n\\tableofcontents', '')5103 5104 " Replace new line tags <vim:br>5105 let file = substitute(file, '\n\s*<vim:br.\{-}>\s*\n', '\n\n', "g")5106 let file = substitute(file, '<vim:br.\{-}>', '\\\\', "g")5107 5108 " Title5109 let file = substitute(file, '<vim:h1.\{-}>\_s*\(.\{-}\)</vim:h1>', '\\title{\1}\n\\maketitle', "g")5110 " Sections5111 let file = substitute(file, '<vim:h2 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\section{', "g")5112 let file = substitute(file, '<vim:h3 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\subsection{', "g")5113 let file = substitute(file, '<vim:h4 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\subsubsection{', "g")5114 let file = substitute(file, '<vim:h5 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\paragraph{', "g")5115 let file = substitute(file, '<vim:h6 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\subparagraph{', "g")5116 let file = substitute(file, '<.vim:h[1-6]>', '}', 'g')5117 5118 " Rawlatex directive5119 " Ha. I didn't anticipate this - special chars inside of rawlatex will be5120 " escaped. Operating on string is faster than going through file line5121 " by line so unescaping of chars in while loop similar to pre handling still5122 " should be faster.5123 let file = substitute(file, '<vim:rawlatex>', '% Begin rawlatex', "g")5124 let file = substitute(file, '<.vim:rawlatex>', '% End rawlatex', "g")5125 " And the same for latexonly5126 let file = substitute(file, '<vim:latexonly>', '% Begin rawlatex', "g")5127 let file = substitute(file, '<.vim:latexonly>', '% End rawlatex', "g")5128 " And the same for rawboth5129 let file = substitute(file, '<vim:rawboth>', '% Begin rawlatex', "g")5130 let file = substitute(file, '<.vim:rawboth>', '% End rawlatex', "g")5131 5132 " Lists5133 let file = substitute(file, '<vim:li.\{-}>', '\\item ', 'g')5134 let file = substitute(file, '<.vim:li>', "", "g")5135 let file = substitute(file, '<vim:ul.\{-}>', '\\begin{itemize}', "g")5136 let file = substitute(file, '<.vim:ul.\{-}>', '\\end{itemize}', "g")5137 " Enumitem and enumerate are in conflict. It has to be one or the5138 " other5139 if file =~ 'vim:ol class="[^>]\{-}start="'5140 let file = substitute(file, '<vim:ol class="loweralpha[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\alph*.,start=\1]', "g")5141 let file = substitute(file, '<vim:ol class="upperalpha[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\Alph*.,start=\1]', "g")5142 let file = substitute(file, '<vim:ol class="lowerroman[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\roman*.,start=\1]', "g")5143 let file = substitute(file, '<vim:ol class="upperroman[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\Roman*.,start=\1]', "g")5144 let file = substitute(file, '<vim:ol class="decimal[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\arabic*.,start=\1]', "g")5145 let file = substitute(file, '<vim:ol class="loweralpha.\{-}>', '\\begin{enumerate}[label=\\alph*.]', "g")5146 let file = substitute(file, '<vim:ol class="upperalpha.\{-}>', '\\begin{enumerate}[label=\\Alph*.]', "g")5147 let file = substitute(file, '<vim:ol class="lowerroman.\{-}>', '\\begin{enumerate}[label=\\roman*.]', "g")5148 let file = substitute(file, '<vim:ol class="upperroman.\{-}>', '\\begin{enumerate}[label=\\Roman*.]', "g")5149 let file = substitute(file, '<vim:ol.\{-}>', '\\begin{enumerate}[label=\\arabic*.]', "g")5150 let listings = 'enumitem'5151 else5152 let file = substitute(file, '<vim:ol class="loweralpha.\{-}>', '\\begin{enumerate}[a.]', "g")5153 let file = substitute(file, '<vim:ol class="upperalpha.\{-}>', '\\begin{enumerate}[A.]', "g")5154 let file = substitute(file, '<vim:ol class="lowerroman.\{-}>', '\\begin{enumerate}[i.]', "g")5155 let file = substitute(file, '<vim:ol class="upperroman.\{-}>', '\\begin{enumerate}[I.]', "g")5156 let file = substitute(file, '<vim:ol.\{-}>', '\\begin{enumerate}[1.]', "g")5157 let listings = 'enumerate'5158 endif5159 let file = substitute(file, '<.vim:ol>', '\\end{enumerate}', "g")5160 5161 " Field lists5162 let file = substitute(file, '<vim:dl class="field.\{-}>', '\\begin{deflist}{Keywords:}\n', 'g')5163 let file = substitute(file, '<vim:dt class="field.\{-}>\(.\{-}\)</vim:dt>', '\\item[\1]', 'g')5164 let file = substitute(file, '<vim:dd class="field.\{-}>', '', 'g')5165 let file = substitute(file, '</vim:dd>', '', 'g')5166 let file = substitute(file, "</vim:dl>", '\\end{deflist}', 'g')5167 5168 " Option lists5169 let file = substitute(file, '<vim:dl class="option">', '\\begin{optlist}{longoptionslist}\n', 'g')5170 let file = substitute(file, '<vim:dt>\(.\{-}\)</vim:dt>', '\\item[\1]', 'g')5171 let file = substitute(file, '<vim:dt class="option">\(.\{-}\)</vim:dt>', '\\item[\1]', 'g')5172 let file = substitute(file, '<vim:dd class="option">', '', 'g')5173 let file = substitute(file, '<vim:dd>', '', 'g')5174 let file = substitute(file, "</vim:dl class=\"option\">", '\\end{optlist}', 'g')5175 5176 " Definition lists5177 let file = substitute(file, '<vim:dl>', '\\begin{deflist}{iii}', 'g')5178 let file = substitute(file, '<vim:dt class="normal">\(.\{-}\)</vim:dt>', '\\item[\1]', 'g')5179 let file = substitute(file, '<vim:dd class="normal">', '', 'g')5180 let file = substitute(file, '</vim:dd>', '', 'g')5181 "let file = substitute(file, "</vim:dl>", '\\end{deflist}', 'g')5182 "5183 " Rubric5184 let file = substitute(file, '<vim:rubric.\{-}>', '\\rubric{ ', "g")5185 let file = substitute(file, "</vim:rubric>", ' }', "g")5186 5187 " Pull-quote5188 let file = substitute(file, '<vim:pullquote>', '\\begin{pullquote}', "g")5189 let file = substitute(file, "</vim:pullquote>", '\\end{pullquote}', "g")5190 5191 " Blockquote5192 let file = substitute(file, "<vim:blockquote.\\{-}>", '\\begin{quotation}', "g")5193 let file = substitute(file, "</vim:blockquote>", '\\end{quotation}', "g")5194 5195 " Text styles5196 let file = substitute(file, '<vim:em.\{-}>', '\\emph{', "g")5197 let file = substitute(file, "</vim:em>", "}", "g")5198 let file = substitute(file, '<vim:strong.\{-}>', '\\textbf{', "g")5199 let file = substitute(file, "</vim:strong>", "}", "g")5200 let file = substitute(file, '<vim:code.\{-}>', '\\texttt{', "g")5201 let file = substitute(file, "</vim:code>", "}", "g")5202 5203 " Tables5204 let file = substitute(file, '<vim:table class="\(.\{-}\)" summary=".\{-}coln\(.\{-}\)">', '\\setlongtables\n\\begin{center}\n\\begin{longtable}[c]{\1coln\2}\\hline\n', "g")5205 let file = substitute(file, "<vim:thead>", '', "g")5206 let file = substitute(file, "</vim:thead>", '\\endhead', "g")5207 let file = substitute(file, "<vim:tfoot>", '', "g")5208 let file = substitute(file, "</vim:tfoot>", '', "g")5209 let file = substitute(file, "</vim:table>", '\\end{longtable}\n\\end{center}', "g")5210 let file = substitute(file, '<vim:tr>\n\?<vim:td>', '', "g")5211 let file = substitute(file, '<vim:td>', ' \& ', "g")5212 let file = substitute(file, "</vim:tr>", ' \\\\ \\hline', "g")5213 let file = substitute(file, '<vim:tr>\n\?<vim:td colspan="\(.\{-}\)".\{-} summary="\(.\{-}\)">\(.\{-}\)\_s*</vim:td>', '\n\\multicolumn{\1}{|p{0.\2\\textwidth}|}{\3}', "g")5214 let file = substitute(file, '<vim:td colspan="\(.\{-}\)".\{-} summary="\(.\{-}\)">\(.\{-}\)\_s*</vim:td>', ' \& \\multicolumn{\1}{p{0.\2\\textwidth}|}{\3}', "g")5215 let file = substitute(file, "</vim:td>", '', "g")5216 5217 " Line5218 " \transition allows for easy change of transition display, eg. for5219 " fancy graphics5220 let file = substitute(file, "<vim:hr.\\{-}>", '\\transition', "g")5221 5222 " Comment5223 let file = substitute(file, "<vim:!--", '% ', "g")5224 5225 " Links5226 let file = substitute(file, '<vim:a href="\(#\)\?\(.\{-}\)".\{-}>\(.\{-}\)</vim:a>', '\\href{\2}{\3}', 'g')5227 let file = substitute(file, '<vim:span id="\(.\{-}\)".\{-}>\(.\{-}\)</vim:span>', '\\hypertarget{\1}{\2}', 'g')5228 5229 " Subscript, superscript5230 let file = substitute(file, '<vim:sub.\{-}>\(.\{-}\)</vim:sub>', '\\subs{\1}', 'g')5231 let file = substitute(file, '<vim:sup.\{-}>\(.\{-}\)</vim:sup>', '\\sups{\1}', 'g')5232 5233 " Fix address special field5234 let file = substitute(file, '<vim:pre class="address">\(.\{-}\)</vim:pre>', '\1', 'g')5235 5236 " Replace unknown with pre elements in frame5237 let file = substitute(file, '<vim:unknown>', '<vim:span class="big">Unknown element</vim:span>\n<vim:pre>', 'g')5238 let file = substitute(file, '</vim:unknown>', '</vim:pre>', 'g')5239 5240 " Title-reference role (<vim:cite>)5241 let file = substitute(file, '<vim:cite.\{-}>', '\\emph{', 'g')5242 let file = substitute(file, '</vim:cite>', '}', 'g')5243 5244 " Class big, small5245 let file = substitute(file, '<vim:span class="big.\{-}>', '{\\large ', 'g')5246 let file = substitute(file, '<vim:span class="small.\{-}>', '{\\small ', 'g')5247 let file = substitute(file, '</vim:span>', '}', 'g')5248 5249 " Figure5250 let file = substitute(file, '<vim:figure.\{-}>', '\\begin{center}\n\\begin{minipage}{0.6\\textwidth}', 'g')5251 let file = substitute(file, '</vim:figure>', '\\end{minipage}\n\\end{center}', 'g')5252 5253 " Create ghost commands for custom block directives5254 let file = substitute(file, '<vim:block.\{-}class="\(.\{-}\)">', '\\vst\1{', 'g')5255 let file = substitute(file, '</vim:block>', '}', 'g')5256 5257 " Create ghost commands for custom container directives5258 let file = substitute(file, '<vim:container.\{-}class="\(.\{-}\)">', '\\vst\1{', 'g')5259 let file = substitute(file, '</vim:container>', '}', 'g')5260 5261 " Topic5262 let file = substitute(file, '<vim:topic.\{-}>', '\\hfill\\begin{minipage}{0.9\\textwidth}', 'g')5263 let file = substitute(file, '</vim:topic>', '\\end{minipage}', 'g')5264 5265 " Sidebar5266 let file = substitute(file, '<vim:sidebar.\{-}>', '\\hfill\\begin{minipage}{0.9\\textwidth}', 'g')5267 let file = substitute(file, '</vim:sidebar>', '\\end{minipage}', 'g')5268 5269 " Divs5270 let file = substitute(file, '<vim:div.\{-}>', '\\begin{center}\n\\fbox{\\begin{minipage}{0.8\\textwidth}', 'g')5271 let file = substitute(file, '</vim:div>', '\\end{minipage}}\n\\end{center}', 'g')5272 " Div titles (<vim:span> was already replaced)5273 let file = substitute(file, '<vim:span class="notetitle">\(.\{-}\)}', '\\textbf{\\sffamily\\large \1}\n\\vspace{2mm}', 'g')5274 5275 " Remove rest of vim:span5276 " let file = substitute(file, '<vim:span.\{-}>', '\\emph{', 'g')5277 let file = substitute(file, '<vim:span class="\(.\{-}\)">', '\\vst\1{', 'g')5278 5279 " Replace empty vim:p tags when hypertargets5280 let file = substitute(file, '<vim:p id="\(.\{-}\)"></vim:p>', '\\hypertarget{\1}{}', "g")5281 " Ignore all other <vim:p> tags5282 let file = substitute(file, '<.\?vim:p\>.\{-}>', "", "g")5283 5284 " Make sure no (La)TeX entity is in URL address of hyperlinks5285 let file = substitute(file, '\\href{\([^}]\{-}\)\\\(La\)\?TeX{}', '\\href{\1\2TeX', 'g')5286 let file = substitute(file, '\\hypertarget{\([^}]\{-}\)\\\(La\)\?TeX{}', '\\hypertarget{\1\2TeX', 'g')5287 " Unescape _ from hyperlinks5288 let file = substitute(file, '\\href{\([^}]\{-}\)\\_', '\\href{\1_', 'g')5289 let file = substitute(file, '\\hypertarget{\([^}]\{-}\)\\_', '\\hypertarget{\1_', 'g')5290 " Prepare newcommands from roles5291 if exists("g:vst_roledb")5292 let rolenewcommands = '%% Commands for content of roles directives'."\n"5293 let rolekeys = keys(g:vst_roledb)5294 for i in range(len(rolekeys))5295 let name = g:vst_roledb[rolekeys[i]]5296 let rolenewcommands .= '\newcommand{\vst'.name.'}[1]{\textnormal{#1}}'."\n"5297 endfor5298 unlet! rolekeys5299 unlet! name5300 else5301 let rolenewcommands = "\n"5302 endif5303 " Prepare newcommands from containers5304 if len("g:vst_containers") > 05305 let containernewcommands = '%% Commands for content of container directives'."\n"5306 let usednames = ''5307 for name in g:vst_containers5308 if usednames !~ ','.name.','5309 let usednames .= ','.name.','5310 let containernewcommands .= '\newcommand{\vst'.name.'}[1]{#1}'."\n"5311 endif5312 endfor5313 else5314 let containernewcommands = "\n"5315 endif5316 5317 " Preamble {{{5318 " This one is better for deflist but has some not nice side effects5319 " which have to be worked out5320 "\.'{\renewcommand{\makelabel}[1]{\parbox[b]{\labelwidth}{\makebox[0pt][l]{\textbf{##1}}\mbox{}\\}}'."\n"5321 let preamble =5322 \ '\documentclass[12pt]{article}'."\n"5323 \.'%% Generated by Vim reStructured Text '.s:vst_ver.' - Vim '.v:version/100.".".v:version % 100."\n"5324 \.'\usepackage[a4paper,margin=2.5cm,nohead]{geometry}'."\n"5325 \.'\usepackage{'.listings."}\n"5326 \.'\usepackage{graphicx}'."\n"5327 \.'\usepackage{longtable}'."\n"5328 \.'\usepackage{tabularx}'."\n"5329 \.'\usepackage{amsmath}'."\n"5330 \.'\usepackage['.encoding."]{inputenc}\n"5331 \.countrysettings."\n"5332 \.'\newenvironment{deflist}[1]{%'."\n"5333 \.'\begin{list}{}'."\n"5334 \.'{\renewcommand{\makelabel}[1]{\textbf{##1}\hfill}'."\n"5335 \.'\settowidth{\labelwidth}{\textbf{#1}}'."\n"5336 \.'\leftmargin=\labelwidth'."\n"5337 \.'\advance \leftmargin\labelsep}}'."\n"5338 \.'{\end{list}}'."\n"5339 \.'\newenvironment{optlist}[1]{%'."\n"5340 \.'\begin{list}{}'."\n"5341 \.'{\renewcommand{\makelabel}[1]{\texttt{##1}\hfill}'."\n"5342 \.'\settowidth{\labelwidth}{\texttt{#1}}'."\n"5343 \.'\leftmargin=\labelwidth'."\n"5344 \.'\advance \leftmargin\labelsep}}'."\n"5345 \.'{\end{list}}'."\n"5346 \.'\newenvironment{pullquote}{\begin{quotation}\Large}{\end{quotation}}'."\n"5347 \.'\setlength{\extrarowheight}{2pt}'."\n"5348 \.tocdepth."\n"5349 \.'\newcommand{\transition}{\begin{center}\rule{.8\textwidth}{0.2pt}\end{center}}'."\n"5350 \.'\newcommand{\subtitle}[1]{{\large\textsc{#1}}\vskip15pt}'."\n"5351 \.'\newcommand{\subs}[1]{\raisebox{-0.7ex}{\footnotesize #1}}'."\n"5352 \.'\newcommand{\sups}[1]{\raisebox{0.7ex}{\footnotesize #1}}'."\n"5353 \.'\newcommand{\attribution}[1]{\raggedleft\textit{#1}}'."\n"5354 \.'\newcommand{\rubric}[1]{\vskip15pt{\large #1}}'."\n"5355 \.rolenewcommands."\n"5356 \.containernewcommands."\n"5357 \.userpreamble."\n"5358 \.'\usepackage[pdftex]{hyperref}'."\n"5359 " Additional data {{{5360 let author = ''5361 let data = ''5362 if has_key(g:vst_fielddb, 'author')5363 let author = '\author{'.g:vst_fielddb['author'].'}'."\n"5364 endif5365 if has_key(g:vst_fielddb, 'date')5366 if g:vst_fielddb['date'] == 'NONE'5367 let g:vst_fielddb['date'] = ''5368 endif5369 let data = '\date{'.g:vst_fielddb['date'].'}'."\n"5370 else5371 let data = ''5372 endif5373 " }}}5374 " PDF Info {{{5375 let pdfinfo = ''5376 let pdfauthor = ''5377 let pdftitle = ''5378 let pdfsubject = ''5379 let pdfkeywords = ''5380 if has_key(g:vst_fielddb, 'author')5381 let pdfauthor = 'pdfauthor={'.g:vst_fielddb['author']."},\n"5382 endif5383 if has_key(g:vst_fielddb, 'title')5384 let pdftitle = 'pdftitle={'.g:vst_fielddb['title']."},\n"5385 endif5386 if has_key(g:vst_fielddb, 'keywords')5387 let pdfkeywords = 'pdfkeywords={'.g:vst_fielddb['keywords']."},\n"5388 endif5389 if has_key(g:vst_fielddb, 'subject')5390 let pdfsubject = 'pdfsubject={'.g:vst_fielddb['subject']."}"5391 endif5392 for key in keys(g:vst_metadb)5393 if key =~ 'author' && pdfauthor == ''5394 let pdfauthor = 'pdfauthor={'.g:vst_metadb[key]."},\n"5395 elseif key =~ 'title' && pdftitle == ''5396 let pdftitle = 'pdftitle={'.g:vst_metadb[key]."},\n"5397 elseif key =~ 'keywords' && pdfkeywords == ''5398 let pdfkeywords = 'pdfkeywords={'.g:vst_metadb[key]."},\n"5399 elseif key =~ 'subject' && pdfsubject == ''5400 let pdfsubject = 'pdfsubject={'.g:vst_metadb[key]."}"5401 endif5402 endfor5403 5404 if exists("g:vst_doc_title")5405 let pdftitle = 'pdftitle={'.substitute(g:vst_doc_title, '^\s*', '', '')."},\n"5406 endif5407 5408 let pdfinfo = "\\hypersetup{\npdfcreator={VST, LaTeX, hyperref},\n"5409 \."bookmarksopen=true,\nbookmarksopenlevel=2,\n"5410 \."colorlinks=true,urlcolor=blue,\n"5411 \.pdfauthor.pdftitle.pdfkeywords.pdfsubject."}\n"5412 5413 let file = preamble."\n".pdfinfo."\n".author.data."\n".file."\n".footer5414 " }}}5415 " }}}5416 5417 " Create comments5418 let file = substitute(file, '<vim:comment>\(.\{-}\)<.vim:comment>', '\=VST_CreateTexComment(submatch(1))', 'g')5419 5420 new5421 if &compatible == 15422 set nocompatible5423 endif5424 0put =file5425 5426 " Go through tables to tune them {{{5427 " 1. Create preamble of table5428 " 2. Remove \hline for borderless tables5429 silent call cursor(1,1)5430 while search('begin{longtable', 'W')5431 unlet! line1 line25432 let line1 = line('.')5433 if getline('.') =~ 'vstbordercoln'5434 "silent exe line1.','.line2.'s/\(multicolumn{\d\+}{\)\(.\{-}\)}/\=submatch(1).substitute(submatch(2), "\\(\\d\\+\\)+", "|p{0.\\1\\\\\\\\textwidth}", "g")."}"/ge'5435 silent s/vstbordercoln\(.\{-}\)}/\='|'.substitute(submatch(1), '\(\d\+\)+', 'p{0.\1\\\\textwidth}|', 'g').'}'/e5436 call search('end{longtable', 'W')5437 let line2 = line('.')5438 "silent exe line1.','.line2.'s/\(multicolumn{\d\+}{\)\(.\{-}\)}/\=submatch(1).substitute(submatch(2), "\\(\\d\\+\\)+", "|p{0.\\1\\\\\\textwidth}", "g")."}"/ge'5439 "silent exe line1.','.line2.'s/\(\& \\multicolumn{\d\+}{\)|/\1/ge'5440 elseif getline('.') =~ 'vstblesscoln'5441 silent s/vstblesscoln\(.\{-}\)}/\=substitute(submatch(1), '\(\d\+\)+', 'p{0.\1\\\\textwidth} ', 'g').'}'/e5442 call search('end{longtable', 'W')5443 let line2 = line('.')5444 silent exe line1.','.line2.'s/\\hline\($\|\\end{longtable\)/\1/e'5445 silent exe line1.','.line2.'g/\\multicolumn/s/\(\\textwidth}\)|/\1/ge'5446 silent exe line1.','.line2.'g/\\multicolumn/s/\(\\multicolumn{\d\+}{\)|/\1/ge'5447 endif5448 " NOTE: this changes range so line1, line2 are useless after that5449 silent exe line1.','.line2.'s/\_s*&\_s*/\r\&\r/ge'5450 endwhile5451 " }}}5452 " Process <img> {{{5453 silent call cursor(1,1)5454 while search('<vim:img', 'W') != 05455 let image = getline('.')5456 let imagelink = 05457 " Detect if image is link. It requires messing with order of5458 " elements5459 if getline(line('.')-1) =~ 'href.*{$'5460 let imagelink = 15461 let link = getline(line('.')-1)5462 endif5463 let class = matchstr(image, 'class="\zs.\{-}\ze"')5464 let src = matchstr(image, 'src="\zs.\{-}\ze"')5465 let width = matchstr(image, 'width="\zs.\{-}\ze"')5466 let height = matchstr(image, 'height="\zs.\{-}\ze"')5467 if width == '' && height == ''5468 let dimensions = ''5469 elseif width != '' && height == ''5470 let dimensions = '[width='.width.'pt]'5471 elseif height != '' && width == ''5472 let dimensions = '[height='.height.'pt]'5473 else5474 let dimensions = '[height='.height.'pt, width='.width.'pt]'5475 endif5476 let figure = '\\includegraphics'.dimensions.'{'.src.'}'5477 let alt = ''5478 let title = ''5479 let opening = ''5480 let caption = ''5481 let closing = ''5482 if class !~ 'inline'5483 let alt = matchstr(image, 'alt="\zs.\{-}\ze"')5484 let title = matchstr(image, 'title="\zs.\{-}\ze"')5485 let opening = '\\begin{figure}[ht]\\centering'5486 if title != ''5487 let caption = '\\caption{'.title.'}'5488 "elseif alt != ''5489 "let caption = '\\caption{'.alt.'}'5490 else5491 let caption = ''5492 endif5493 let closing = '\\end{figure}'5494 endif5495 if imagelink != 05496 let link = escape(link, '\')5497 let imagestring = opening.link.figure.'}'.caption.closing5498 " Remove href end closing }, it require jumping between the5499 " lines.5500 silent .-1s/.*//e5501 silent .+2s/.*//e5502 silent normal! k5503 else5504 let imagestring = opening.figure.caption.closing5505 endif5506 silent exe 's+<vim:img.\{-}>+'.imagestring.'+e'5507 silent normal! j5508 endwhile5509 " }}}5510 " Processing preformatted text. {{{5511 " Not using verbatim because it is5512 " in conflict with minipages5513 silent call cursor(1,1)5514 while search('^\s*<vim:pre', 'W')5515 silent s+.*+\\begin{ttfamily}\\begin{flushleft}+5516 silent normal! j5517 let line1 = line('.')5518 let indlist = []5519 while getline('.') !~ '</vim:pre'5520 if getline('.') =~ '^\s*$'5521 silent normal! j5522 continue5523 endif5524 let preind = strlen(matchstr(getline('.'), '^\s*'))5525 let indlist += [preind]5526 silent normal! j5527 endwhile5528 let line2 = line('.')-15529 if line2 < line15530 let line2 = line15531 endif5532 let lineend = line('.')5533 let ind = min(indlist) <= 0 ? 0 : min(indlist)5534 silent exe line1.','.line2.'s/^ \{'.ind.'}/ /e'5535 silent exe line1.','.line2.'s+^+\\mbox{+e'5536 silent exe line1.','.line2.'s+$+}\\\\+e'5537 silent exe line1.','.line2.'s/ /\~/ge'5538 silent exe lineend's+.*+\\end{flushleft}\\end{ttfamily}+'5539 endwhile5540 " }}}5541 " Unescaping special chars from rawlatex. {{{5542 silent call cursor(1,1)5543 while search('^\s*% Begin rawlatex', 'W')5544 silent normal! j5545 let line1 = line('.')5546 while getline('.') !~ '% End rawlatex'5547 silent normal! j5548 endwhile5549 let line2 = line('.')-15550 silent exe line1.','.line2.'s/^\s\+//e'5551 silent exe line1.','.line2.'s/\$\\backslash\$/\\/ge'5552 silent exe line1.','.line2.'s/\\\$/$/ge'5553 silent exe line1.','.line2.'s/\\\({\|\}\)/\1/ge'5554 silent exe line1.','.line2.'s/\\\^{}/^/ge'5555 silent exe line1.','.line2.'s/\\\~{}/\~/ge'5556 silent exe line1.','.line2.'s/\\#/#/ge'5557 silent exe line1.','.line2.'s/\\%/%/ge'5558 silent exe line1.','.line2.'s/\\_/_/ge'5559 " Hack to workaround inner slash escaping mechanism. consider5560 " single backslash at the end of line as double backslash meaning5561 " 'new line'5562 silent exe line1.','.line2.'s/\\$/\\\\/ge'5563 endwhile5564 " }}}5565 " In lines not belonging to pre enclose < and > in $$ to show them. {{{5566 " \langle, \rangle would be more proper solution but they5567 " look too differently for my taste.5568 silent v/^\\mbox/s/</$<$/ge5569 silent v/^\\mbox/s/>/$>$/ge5570 silent v/^\\mbox\|begin{longtable\|multicolumn{/s/|/$|$/ge5571 " }}}5572 " Beautyfication of LaTeX output {{{5573 silent %s/^\s*$//5574 silent %s/\n\{3,}/\r\r/5575 silent %s/\n\+\(\n\s*\\end\)/\1/5576 silent %s/\(\\begin{.\{-}}\n\)\n\+/\1/5577 " Compressing of titles5578 silent %s/title{\n/title{/e5579 silent %s/section{\n/section{/e5580 silent %s/paragraph{\n/paragraph{/e5581 " Shorten lists5582 silent %s/\\item\s*\n\n/\\item\r/e5583 " Because multiple spaces are meaningless:5584 silent %s/\s\+/ /ge5585 " Test it5586 silent %s/{\_s*/{/ge5587 silent %s/\n\n\s*&\s*\n\n/\r\&\r/ge5588 silent %s/\n\n \(\\\\ \\hline\)\s*\n\n/\r\1\r/ge5589 " Fix vertical space in admonitions5590 silent %s/\(\\vspace{2mm}\n\)\(\S\)/\1\r\2/ge5591 " Replace lines for .. figure:: - image first, minipage later.5592 silent %s/\(\\begin{minipage}{0\.6\\textwidth}\)\n\(\\begin{figure.*\)/\2\r\1/ge5593 " Remove special chars catchers5594 silent %s/@/@/ge5595 silent %s/[/[/ge5596 silent %s/\/\\/ge5597 silent %s/:/:/ge5598 silent %s/&\\#64;/@/ge5599 silent %s/&\\#91;/[/ge5600 silent %s/&\\#92;/\\/ge5601 silent %s/&\\#58;/:/ge5602 " Insert new line before \item[], it causes problems in complex5603 " environments5604 silent %s/\\item\[/\r\0/ge5605 " But we don't like if there is more than one blank line5606 silent %s/\n\n\n\\item\[/\r\r\\item\[/ge5607 " Remove empty deflist environment5608 " may be a problem when :Date: NONE is the only element of field list5609 silent %s/\\begin{deflist}{.\{-}}\n\\end{deflist}//ge5610 " Replace non-breaking space characters with ~5611 silent %s/ /\~/ge5612 " }}}5613 " Insert raw files {{{5614 silent call cursor(1,1)5615 while search('-vst-raw-file-placeholder:', 'W')5616 let file = matchstr(getline('.'), '-vst-raw-file-placeholder:\zs.*')5617 " Remove \ before _ - in most cases it was placed there by5618 " escaping mechanism, not user5619 let file = substitute(file, '\\_', '_', 'g')5620 silent s/.*//ge5621 exe 'silent read '.escape(file, ' \#%')5622 endwhile5623 " }}}5624 5625 redraw!5626 5627 " This is place for special CJK postprocessing5628 " What if &encoding=='utf-8'?5629 if &encoding =~? 'big5\|cp950\|euc-tw' || ( &encoding =~? '^utf' && v:ctype =~ 'big5' )5630 5631 silent! g/^\\usepackage.*geometry}/s/.*/\0\r\\usepackage{CJK}/5632 silent! g/^\\usepackage.*inputenc}/d5633 silent! g/^\\usepackage.*hyperref}/s/.*/\\usepackage[CJKbookmarks,bookmarks=false,pdftex]{hyperref}5634 silent! g/^bookmarksopen=true,$/d5635 silent! g/^bookmarksopenlevel=2,$/d5636 if encoding == 'Big5'5637 silent! g/\\begin{document}/s/.*/\0\\begin{CJK}{Bg5}{}/5638 elseif encoding == 'UTF-8'5639 silent! g/\\begin{document}/s/.*/\0\\begin{CJK}{UTF8}{}/5640 else5641 silent! g/\\begin{document}/s/.*/\0\\begin{CJK}{}{}/5642 endif5643 silent! g/\\end{document}/s/.*/\\end{CJK}\0/5644 5645 let cjkpreamble = '\renewcommand\CJKglue{\hskip -0.3pt plus 0.08\baselineskip}'."-cjk-newline-placeholder-"5646 \.'\linespread{1.382}'."-cjk-newline-placeholder-"5647 \.'\renewcommand{\arraystretch}{1.2}'."-cjk-newline-placeholder-"5648 \.'\parindent=0pt'."-cjk-newline-placeholder-"5649 \.'\parskip=1.382ex'."-cjk-newline-placeholder-"5650 \.'\renewenvironment{quote}'."-cjk-newline-placeholder-"5651 \.' {\list{}{\topsep 1ex\parsep 0ex\setlength\leftmargin{1.5em}%'."-cjk-newline-placeholder-"5652 \.' \rightmargin\leftmargin}\item\relax\linespread{1.0}\small}%'."-cjk-newline-placeholder-"5653 \.' {\endlist}'."-cjk-newline-placeholder-"5654 \.'\let\oldfootnote\footnote'."-cjk-newline-placeholder-"5655 \.'\renewcommand\footnote[1]{\oldfootnote{\renewcommand\baselinestretch{1.0}%'."-cjk-newline-placeholder-"5656 \.'\large\footnotesize\ignorespaces#1}}'."-cjk-newline-placeholder-"5657 \.'\addtolength{\footnotesep}{3pt}'5658 5659 silent call cursor(1,1)5660 silent call search('^\\usepackage{amsmath}')5661 silent call append(line('.'), cjkpreamble)5662 " Placeholder stuff is necessary because no Vim function for5663 " inserting text like newline character.5664 silent! %s/-cjk-newline-placeholder-/\r/g5665 silent call cursor(1,1)5666 5667 endif5668 5669 " User postprocessing5670 if g:vst_tex_post != '' && filereadable(g:vst_tex_post)5671 exe "silent! source ".g:vst_tex_post5672 endif5673 5674 " Handling of pdf export {{{5675 if format =~ 'pdf'5676 silent call cursor(1,1)5677 let file_tex = filename.'.tex'5678 if !exists('g:vst_pdf_command')5679 let g:vst_pdf_command = 'pdflatex -interaction=nonstopmode'5680 endif5681 silent exe 'write! '.escape(file_tex, ' \#%')5682 silent exe "call system(\"".g:vst_pdf_command." '".file_tex."'\")"5683 if search('\\tableofcontents', 'W')5684 silent exe "call system(\"".g:vst_pdf_command." '".file_tex."'\")"5685 endif5686 if v:shell_error == 05687 bw! %5688 echomsg "Document compiled OK. You can view it in PDF viewer."5689 if exists("g:vst_pdf_clean") && g:vst_pdf_clean == 15690 call delete(file_tex)5691 call delete(filename.'.log')5692 call delete(filename.'.out')5693 call delete(filename.'.aux')5694 endif5695 if exists("g:vst_pdf_view") && g:vst_pdf_view == 15696 if !exists("g:vst_pdf_viewer")5697 if has("win32")5698 let g:vst_pdf_viewer = ""5699 elseif has("unix")5700 if executable("kpdf")5701 let g:vst_pdf_viewer = "kpdf"5702 elseif executable("xpdf")5703 let g:vst_pdf_viewer = "xpdf"5704 else5705 let g:vst_pdf_viewer = "no_pdf_viewer"5706 endif5707 endif5708 endif5709 silent exe "call system(\"".g:vst_pdf_viewer." '".filename.".pdf'\")"5710 silent redraw!5711 endif5712 else5713 echomsg "Something went wrong, check TeX code or command settings."5714 endif5715 silent call cursor(1,1)5716 call VST_End()5717 return5718 endif5719 " }}}5720 5721 " Latex-Suite (or any other tex ftype settings) brokes *many*5722 " things. Load it at the end5723 setlocal ft=tex5724 if exists("g:vst_write_export") && g:vst_write_export != 05725 silent exe 'write! '.escape(filename, ' \#%').'.tex'5726 endif5727 5728 silent call cursor(1,1)5729 " }}}5730 " Auxiliary commands {{{5731 elseif format =~ '^head'5732 " Symbols for section titles {{{5733 call VST_Headers(text)5734 unlet! b:vst_first_parsing5735 call VST_DictTable(g:vst_headers, 'Level', 'Symbol', 0)5736 " }}}5737 elseif format =~ '^toc'5738 " Table of contents for file {{{5739 let line = line('.')5740 call VST_Headers(text)5741 unlet! b:vst_first_parsing5742 let i = 15743 let tocc = []5744 let b:vst_toc_numbers = {}5745 let i1 = -15746 let i2 = -15747 let i3 = -15748 let i4 = -15749 let i5 = -15750 let i6 = -15751 5752 while i < len(g:paras)5753 if g:ptype[i] =~ '^h\d'5754 " Real table5755 call add(tocc, [g:ptype[i], g:paras[i], g:plinen[i]])5756 " Header numbers5757 let header_text = matchstr(g:paras[i], '^.\{-}\ze\n')5758 let lvl = strpart(g:ptype[i], 1)5759 if lvl == 15760 let b:vst_toc_numbers[header_text] = ''5761 let i2 = 05762 let i3 = 05763 let i4 = 05764 let i5 = 05765 let i6 = 05766 elseif lvl == 25767 let i2 += 15768 let b:vst_toc_numbers[header_text] = i2.' '5769 let i3 = 05770 let i4 = 05771 let i5 = 05772 let i6 = 05773 elseif lvl == 35774 let i3 += 15775 let b:vst_toc_numbers[header_text] = i2.'.'.i3.' '5776 let i4 = 05777 let i5 = 05778 let i6 = 05779 elseif lvl == 45780 let i4 += 15781 let b:vst_toc_numbers[header_text] = i2.'.'.i3.'.'.i4.' '5782 let i5 = 05783 let i6 = 05784 elseif lvl == 55785 let i5 += 15786 let b:vst_toc_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.' '5787 let i6 = 05788 elseif lvl == 65789 let i6 += 15790 let b:vst_toc_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.'.'.i6.' '5791 endif5792 endif5793 let i += 15794 endwhile5795 5796 echo VST_TocTable(tocc, 'Nr', 'Title', ' Line', line)5797 " }}}5798 elseif format =~ '^fold'5799 " Folding {{{5800 let b:vst_fold = {}5801 call VST_Headers(text)5802 unlet! b:vst_first_parsing5803 " Prepare numbers of head lines {{{5804 let b:vst_fold_numbers = {}5805 let i = 05806 let i1 = -15807 let i2 = -15808 let i3 = -15809 let i4 = -15810 let i5 = -15811 let i6 = -15812 while i < len(g:paras)5813 if g:ptype[i] =~ '^h\d'5814 let header_text = matchstr(g:paras[i], '^.\{-}\ze\n')5815 let lvl = strpart(g:ptype[i], 1)5816 if lvl == 15817 let b:vst_fold_numbers[header_text] = ''5818 let i2 = 05819 let i3 = 05820 let i4 = 05821 let i5 = 05822 let i6 = 05823 elseif lvl == 25824 let i2 += 15825 let b:vst_fold_numbers[header_text] = i2.' '5826 let i3 = 05827 let i4 = 05828 let i5 = 05829 let i6 = 05830 elseif lvl == 35831 let i3 += 15832 let b:vst_fold_numbers[header_text] = i2.'.'.i3.' '5833 let i4 = 05834 let i5 = 05835 let i6 = 05836 elseif lvl == 45837 let i4 += 15838 let b:vst_fold_numbers[header_text] = i2.'.'.i3.'.'.i4.' '5839 let i5 = 05840 let i6 = 05841 elseif lvl == 55842 let i5 += 15843 let b:vst_fold_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.' '5844 let i6 = 05845 elseif lvl == 65846 let i6 += 15847 let b:vst_fold_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.'.'.i6.' '5848 endif5849 5850 let b:vst_fold[header_text] = lvl-15851 endif5852 let i += 15853 endwhile5854 " }}}5855 " Prepare fold levels {{{5856 let b:vst_fold_lvl = matchstr(format, '\zs.\ze\s*$')5857 if b:vst_fold_lvl =~ 'r'5858 for i in [1, 2, 3, 4, 5, 6]5859 let b:vst_fold_list_{i} = filter(deepcopy(b:vst_fold), 'v:val == i')5860 let b:vst_flvl_{i} = keys(b:vst_fold_list_{i})5861 endfor5862 else5863 if b:vst_fold_lvl !~ '\d'5864 let b:vst_fold_lvl = 05865 elseif b:vst_fold_lvl =~ '\d' && b:vst_fold_lvl > 65866 let b:vst_fold_lvl = 65867 endif5868 if b:vst_fold_lvl != 05869 let b:vst_fold_list = filter(deepcopy(b:vst_fold), 'v:val <= b:vst_fold_lvl')5870 else5871 let b:vst_fold_list = b:vst_fold5872 endif5873 endif5874 " }}}5875 setlocal foldmethod=expr5876 setlocal foldexpr=VST_FoldExpr(v:lnum)5877 setlocal foldtext=VST_FoldText()5878 " }}}5879 elseif format =~ '^fblank'5880 " Folding by blank lines {{{5881 let directive = matchstr(format, '^f\zs.*')5882 setlocal foldmethod=expr5883 set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':15884 function! VST_FoldText()5885 let text = getline(v:foldstart)5886 let indent = '+'.v:folddashes5887 return indent.repeat(' ', 2).text.' '5888 endfunction5889 setlocal foldtext=VST_FoldText()5890 " }}}5891 elseif format =~ '^f'5892 " Folding by directive {{{5893 "elseif format =~ '^f\(block\|container\|image\|figure\|sidebar\|compound\|topic\|rubric\|table\|tip\|note\|warning\|admonition\|include\|pull-quote\|class\|meta\|raw\|2html\)'5894 let directive = matchstr(format, '^f\zs.*')5895 setlocal foldmethod=expr5896 "exe "setlocal foldexpr=getline(v:lnum)=~?'^\\\\s*\\\.\\\.\\\ ".directive."::'?'>1':1"5897 exe "setlocal foldexpr=getline(v:lnum)=~?'^\\\\s*\\\.\\\.\\\ ".directive."'?'>1':1"5898 function! VST_FoldDirective()5899 let text = getline(v:foldstart)5900 let indent = '+'.v:folddashes5901 let fill = 65 - (len(indent) + len(text) + 3)5902 if fill < 15903 let fill = 15904 endif5905 return indent.' '.text.repeat(' ', fill).v:foldstart.' ('.v:foldstart*100/line('$').'%)'5906 endfunction5907 setlocal foldtext=VST_FoldDirective()5908 " }}}5909 elseif format =~ '^link'5910 " Link table {{{5911 call VST_Headers(text)5912 unlet! b:vst_first_parsing5913 call VST_DictTable(g:vst_hlinkdb, 'Text', 'Link', 0)5914 " }}}5915 elseif format =~ '^slink'5916 " Sorted link table {{{5917 call VST_Headers(text)5918 unlet! b:vst_first_parsing5919 call VST_DictTable(g:vst_hlinkdb, 'Text', 'Link', 1)5920 " }}}5921 elseif format =~ '^rep'5922 " Replacement table {{{5923 call VST_Headers(text)5924 unlet! b:vst_first_parsing5925 call VST_DictTable(g:vst_replacedb, 'Symbol', 'Replacement', 0)5926 " }}}5927 elseif format =~ '^srep'5928 " Sorted replacement table {{{5929 call VST_Headers(text)5930 unlet! b:vst_first_parsing5931 call VST_DictTable(g:vst_replacedb, 'Symbol', 'Replacement', 1)5932 " }}}5933 elseif format =~ '^help'5934 " Help for commands {{{5935 echo5936 \ "Help for :Vst arguments:\n"5937 \."html - [default] export to HTML format\n"5938 \."tex - export to LaTeX format\n"5939 \."pdf - export to LaTeX format and compile PDF\n"5940 \."rest - export to reST format\n"5941 \."s5 - export to S5 HTML presentation\n"5942 \." ---------------\n"5943 \."toc - file table of contents\n"5944 \."head - show used symbols for headers\n"5945 \."link - show table of link declarations\n"5946 \."slink - show sorted table of link declarations\n"5947 \."rep - show table of replacements\n"5948 \."srep - show sorted table of replacements\n"5949 \."preproc - process inclusion commands (non-recursively)\n"5950 \."help - this message\n"5951 \." ---------------\n"5952 \."fold - (re)create folds in file\n"5953 \."foldr - (re)create folds recursively in file\n"5954 \."fold1 - (re)create folds of 1st level headers in file\n"5955 \."fold2 - (re)create folds up to 2nd level header in file\n"5956 \."fold3 - (re)create folds up to 3rd level header in file\n"5957 \."fold4 - (re)create folds up to 4th level header in file\n"5958 \."fold5 - (re)create folds up to 5th level header in file\n"5959 \."fold6 - (re)create folds up to 6th level header in file\n"5960 \." ---------------\n"5961 \."Additional commands:\n"5962 \.":Vsti - immediately write file\n"5963 \.":Vstm - display menus (no arguments)"5964 return ''5965 " }}}5966 elseif format =~ '^pre'5967 " Interpret all including commands and put them in file {{{5968 silent normal! ggdG5969 let jtext = join(text, "\n")5970 silent 0put =jtext5971 silent call cursor(1,1)5972 " }}}5973 " }}}5974 endif5975 5976 call VST_End()5977 5978 return ''4658 let s5body2 = "</div>\n</div>" 4659 else 4660 let s5body = '' 4661 let s5head = '' 4662 let s5body2 = '' 4663 endif 4664 " }}} 4665 4666 let metainfo .= metadata 4667 4668 if file =~ '<vim:ol[^>]*start="' 4669 let g:zzz = 1 4670 let doctype = 4671 \ '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n" 4672 \.' "http://www.w3.org/TR/html4/loose.dtd">'."\n" 4673 "\ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '."\n" 4674 "\.' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> '."\n" 4675 else 4676 let doctype = 4677 \ '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n" 4678 \.' "http://www.w3.org/TR/html4/strict.dtd">'."\n" 4679 "\ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '."\n" 4680 "\.' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\n" 4681 endif 4682 4683 let header = 4684 \ doctype 4685 \.'<html xmlns="http://www.w3.org/1999/xhtml" lang="'.language.'" ' 4686 \.'xml:lang="'.language.'">'."\n" 4687 \.'<head>'."\n" 4688 \.'<meta http-equiv="Content-Type" content="text/html; charset='.encoding.'" />'."\n" 4689 \.'<title>'.htmltitle.'</title>'."\n" 4690 \.'<meta name="Generator" content="Vim reStructured Text '.s:vst_ver.' - Vim '.v:version/100.".".v:version % 100.'" />'."\n" 4691 \.metainfo."\n" 4692 \.css."\n" 4693 \.s5head."\n" 4694 \.'</head>'."\n" 4695 \.'<body>'."\n" 4696 4697 let closing = '</body>'."\n".'</html>' 4698 4699 let file = header."\n".s5body."\n".file."\n".s5body2."\n".closing 4700 let file = substitute(file, '</vim:', '</', 'g') 4701 let file = substitute(file, '<vim:', '<', 'g') 4702 " let file = substitute(file, '\(\[\d\+\]</a>\)_', '\1', 'g') 4703 " let file = substitute(file, '\(\[#\]</a>\)_', '\1', 'g') 4704 4705 " Create comment tags 4706 let file = substitute(file, '</comment>', ' -->', 'g') 4707 let file = substitute(file, '<comment.\{-}>', '<!-- ', 'g') 4708 4709 " Replace rawlatex with pre tags 4710 "let file = substitute(file, '</rawlatex', '</pre', 'g') 4711 "let file = substitute(file, '<rawlatex>', '<pre class="rawlatex"', 'g') 4712 "let file = substitute(file, '<rawlatex class="\(.\{-}\)">', '<pre class="rawlatex \1">', 'g') 4713 " Remove rawlatex content 4714 let file = substitute(file, '<rawlatex.\{-}</rawlatex>', '', 'g') 4715 4716 " Remove latexonly tags and contents 4717 let file = substitute(file, '<latexonly\.{-}>.\{-}</latexonly>', '', 'g') 4718 4719 " Replace footnote and citation with div class="footnote" 4720 let file = substitute(file, '</footnote', '</div', 'g') 4721 let file = substitute(file, '<footnote>', '<div class="footnote">', 'g') 4722 let file = substitute(file, '<footnote class="\(.\{-}\)">', '<div class="footnote \1">', 'g') 4723 let file = substitute(file, '</citation', '</div', 'g') 4724 let file = substitute(file, '<citation>', '<div class="footnote">', 'g') 4725 let file = substitute(file, '<citation class="\(.\{-}\)">', '<div class="footnote \1">', 'g') 4726 4727 " Replace topic with div 4728 let file = substitute(file, '</topic', '</div', 'g') 4729 let file = substitute(file, '<topic', '<div ', 'g') 4730 4731 " Replace sidebar with div 4732 let file = substitute(file, '</sidebar', '</div', 'g') 4733 let file = substitute(file, '<sidebar', '<div ', 'g') 4734 4735 " Replace figure with div 4736 let file = substitute(file, '</figure', '</div', 'g') 4737 let file = substitute(file, '<figure', '<div', 'g') 4738 4739 " Replace block with div 4740 let file = substitute(file, '</block\>', '</div', 'g') 4741 let file = substitute(file, '<block\>', '<div', 'g') 4742 4743 " Replace container with div 4744 let file = substitute(file, '</container\>', '</div', 'g') 4745 let file = substitute(file, '<container\>', '<div', 'g') 4746 4747 " Replace unknown with div and header 4748 let file = substitute(file, '</unknown\>', '</div', 'g') 4749 let file = substitute(file, '<unknown>', '<div class="unknown"><strong>Unknown element:</strong><br />', 'g') 4750 4751 " Replace pullquote with blockquote class 4752 let file = substitute(file, '</pullquote', '</blockquote', 'g') 4753 let file = substitute(file, '<pullquote>', '<blockquote class="pull">', 'g') 4754 let file = substitute(file, '<pullquote class="\(.\{-}\)">', '<blockquote class="pull \1">', 'g') 4755 4756 " Replace rubric with span class 4757 let file = substitute(file, '</rubric', '</p', 'g') 4758 let file = substitute(file, '<rubric>', '<p class="rubric">', 'g') 4759 let file = substitute(file, '<rubric class="\(.\{-}\)">', '<p class="rubric \1">', 'g') 4760 4761 " Turn field list (dl) into table. 4762 " This can be expensive set of regexps so check if this element exists 4763 " at all 4764 if file =~ 'dt class="field' 4765 let file = substitute(file, '<dl class="field\(.\{-}\)">', '<table class="field\1" summary="Field list">', 'g') 4766 let file = substitute(file, '\(<dd class="field.\{-}\n\)</dl>', '\1</table>', 'g') 4767 let file = substitute(file, '<dt class="field fabstract">Abstract<.dt><dd class="field fabstract">\(.\{-}\)<.dd>', '<tr><td class="fkey fakey" colspan="2">Abstract</td></tr><tr><td class="fval faval" colspan="2">\1</td></tr>', 'g') 4768 let file = substitute(file, '<dt class="field fdedication">Dedication<.dt><dd class="field fdedication">\(.\{-}\)<.dd>', '<tr><td class="fkey fdkey" colspan="2">Dedication</td></tr><tr><td class="fval fdval" colspan="2">\1</td></tr>', 'g') 4769 let file = substitute(file, '<dt class="field.\{-}>\(.\{-}\)<.dt><dd class="field.\{-}>\(.\{-}\)<.dd>', '<tr><td class="fkey">\1</td><td class="fval">\2</td></tr>', 'g') 4770 endif 4771 4772 " Replace weird table summary value with proper <col /> tags 4773 let file = substitute(file, '<table\( class="vst.\{-}summary="\).\{-}coln\(.\{-}\)">', '\="<table".submatch(1)."\">".VST_ColNumbers(submatch(2))', 'g') 4774 " Remove class attribute from closing of dl list 4775 let file = substitute(file, '\(</dl\) class=".\{-}"', '\1', 'g') 4776 4777 " Remove summary from td tags 4778 let file = substitute(file, '\(<td[^>]*\) summary=".\{-}"', '\1', 'g') 4779 4780 " Remove rawhtml tags 4781 let file = substitute(file, '</rawhtml>', '', 'g') 4782 let file = substitute(file, '<rawhtml.\{-}>', '', 'g') 4783 4784 " Remove rawboth tags 4785 let file = substitute(file, '</rawboth>', '', 'g') 4786 let file = substitute(file, '<rawboth.\{-}>', '', 'g') 4787 4788 " Remove htmlonly tags 4789 let file = substitute(file, '</htmlonly>', '', 'g') 4790 let file = substitute(file, '<htmlonly.\{-}>', '', 'g') 4791 4792 " Remove consecutive empty lines 4793 let file = substitute(file, '\n\n\{3,}', '\n\n', 'g') 4794 4795 " Replace --(-) with emdash entity in attributions 4796 let file = substitute(file, '\(<p class="attribution.\{-}>\_s\{-}\)---\?', '\1\—', 'g') 4797 4798 " Add backlinks from section headers 4799 if exists("b:IsTOC") && b:IsTOC == 1 4800 let file = substitute(file, '\(<h\d id="\)\(.\{-}\)"\(.\{-}>\)', '\1\2"\3<a href="#toc-\2">', 'g') 4801 let file = substitute(file, '<\/h\d>', '<\/a>\0', 'g') 4802 unlet! b:IsTOC 4803 endif 4804 4805 new 4806 if &compatible == 1 4807 set nocompatible 4808 endif 4809 silent! 0put =file 4810 " Beautify HTML a bit: 4811 " Reduce indentation inside of <pre> tags to minimum of 1 space {{{ 4812 silent call cursor(1,1) 4813 while search('^\s*<pre', 'W') 4814 let rawlatex = (getline('.') =~ 'class="rawlatex' ? 1 : 0) 4815 silent normal! j 4816 let line1 = line('.') 4817 let indlist = [] 4818 while getline('.') !~ '</pre' 4819 if getline('.') =~ '^\s*$' 4820 silent normal! j 4821 continue 4822 endif 4823 let preind = strlen(matchstr(getline('.'), '^\s*')) 4824 let indlist += [preind] 4825 silent normal! j 4826 endwhile 4827 let line2 = line('.')-1 4828 " When pre is empty (closing tag is in next line after opening 4829 " tag) don't continue 4830 if line1 == line2 + 1 4831 continue 4832 endif 4833 let lineend = line('.') 4834 let ind = min(indlist) <= 0 ? 0 : min(indlist) 4835 silent exe line1.','.line2.'s/^ \{'.ind.'}/ /e' 4836 " Previously doubled \ was treated as escaped and reduced to one. 4837 " Now it is highly probable that one \ at the end of line was 4838 " supposed to be new line symbol. 4839 if rawlatex == 1 4840 silent exe line1.','.line2.'s/\\$/\\\\/e' 4841 endif 4842 endwhile 4843 " }}} 4844 " Put 2html CSS styles into head {{{ 4845 silent call cursor(1,1) 4846 if search('<pre class="tohtml-[^"]\+">') 4847 call VST_2html() 4848 if exists('g:vst_2html_css') 4849 silent call cursor(1,1) 4850 let tohtml_css = '<style type="text/css">'."\n".'/*<![CDATA[*/'."\n" 4851 \ .join(g:vst_2html_css, "\n")."\n".'/*]]>*/'."\n".'</style>' 4852 call search('<\/head>') 4853 put! =tohtml_css 4854 unlet! g:vst_2html_css 4855 endif 4856 endif 4857 redraw! 4858 " }}} 4859 " Insert raw files {{{ 4860 silent call cursor(1,1) 4861 while search('-vst-raw-file-placeholder:', 'W') 4862 let rawfile = matchstr(getline('.'), '-vst-raw-file-placeholder:\zs.*') 4863 let g:rf = rawfile 4864 silent s/.*//ge 4865 if filereadable(rawfile) 4866 exe 'silent read '.escape(rawfile, ' \#%') 4867 endif 4868 endwhile 4869 " }}} 4870 setlocal ft=html 4871 4872 " S5 postprocessing {{{ 4873 if format == 's5' 4874 silent call cursor(1,1) 4875 silent call search('<div class="presentation">') 4876 let line = line('.') 4877 silent exe line.',$ s/<h1/<div class="slide">\r<h1/ge' 4878 silent exe line.',$ s/<h2/<div class="slide">\r<h1/ge' 4879 silent exe line.',$ s/<div class="slide">/<\/div>\r\0/ge' 4880 silent exe line.',$ s/<\/h2>/<\/h1>/ge' 4881 "silent g/<a href="http/s/<a href=".\{-}"/\0 class="external"/ge 4882 silent exe line 4883 silent exe line.',$ s/\(<div class="presentation">\)\_s*<\/div>/\1/ge' 4884 " Create s5ui directory and file structure 4885 if !isdirectory('s5ui') 4886 call mkdir('s5ui') 4887 endif 4888 let s5files = [ 4889 \ 'blank.gif', 4890 \ 'framing.css', 4891 \ 'iepngfix.htc', 4892 \ 'opera.css', 4893 \ 'outline.css', 4894 \ 'pretty.css', 4895 \ 'print.css', 4896 \ 's5-core.css', 4897 \ 'slides.css', 4898 \ 'slides.js'] 4899 let workingdir = expand('%:p:h').'/' 4900 for file in s5files 4901 if !filereadable('s5ui/'.file) 4902 let rtp = split(&rtp, ',') 4903 for i in range(len(rtp)) 4904 if filereadable(rtp[i].'/autoload/vst/s5ui/'.file) 4905 let s5file = rtp[i].'/autoload/vst/s5ui/'.file 4906 break 4907 endif 4908 endfor 4909 silent exe 'below 1split '.escape(s5file, ' \#%') 4910 silent exe 'write! '.escape(workingdir' \#%').'s5ui/'.escape(file, ' \#%') 4911 silent exe 'bw! '.escape(s5file, ' \#%') 4912 endif 4913 endfor 4914 " Write file after changes 4915 silent exe 'cd '.escape(workingdir, ' \#%') 4916 4917 endif 4918 " }}} 4919 if exists("g:vst_write_export") && g:vst_write_export != 0 4920 silent exe 'write! '.escape(filename, ' \#%').'.html' 4921 endif 4922 " User postprocessing 4923 if g:vst_html_post != '' && filereadable(g:vst_html_post) 4924 exe 'silent! source '.escape(g:vst_html_post, ' \#%') 4925 endif 4926 silent call cursor(1,1) 4927 call VST_End() 4928 " }}} 4929 elseif format == 'xml' 4930 " XML export {{{ 4931 new 4932 silent 0put =file 4933 setlocal ft=xml 4934 if exists("g:vst_write_export") && g:vst_write_export != 0 4935 silent exe 'write! '.escape(filename, ' \#%').'.xml' 4936 endif 4937 silent call cursor(1,1) 4938 call VST_End() 4939 " }}} 4940 elseif format =~? '^re\?st$' 4941 " reST export {{{ 4942 let rest_file = getline(1, '$') 4943 " Potential problems when size of register has limits. :help 'viminfo' 4944 new 4945 silent! 0put =rest_file 4946 unlet! rest_file 4947 silent! %s/\(^\s*\.\. \)block::/\1admonition::/ge 4948 silent! g/^\s*:identify:/d 4949 silent! %s/\(^\s*\)\(:\S.\{-} \)/\1--VIM, \2/ge 4950 " <c-v>160 - non breaking space 4951 silent! %s/\\\@<!\\-/ /ge 4952 silent! %s/\(^\s*\)\.\. 2html::.*/\1:: 4953 silent call cursor(1,1) 4954 " }}} 4955 elseif format =~ '^\(tex\|pdf\)$' 4956 " LaTeX export {{{ 4957 " 4958 function! VST_CreateTexComment(text) 4959 let scomm = split(a:text, '\n') 4960 let i = 0 4961 while i < len(scomm) 4962 let scomm[i] = substitute(scomm[i], '^', '%%', '') 4963 let i += 1 4964 endwhile 4965 let par = join(scomm, '\n') 4966 return par 4967 endfunction 4968 4969 " Handle encoding and country options. {{{ 4970 let encoding = tolower(encoding) 4971 if encoding =~ 'iso-8859-1\|iso-8859-15' 4972 let encoding = 'latin1' 4973 elseif encoding =~ "windows-" 4974 let encoding = substitute(encoding, 'windows-', , 'cp', '') 4975 elseif encoding == 'iso-8859-2' 4976 let encoding = 'latin2' 4977 elseif encoding == 'sjis' 4978 let encoding = 'Shift_JIS' 4979 elseif encoding == 'euc-cn' 4980 let encoding = 'GB_2312-80' 4981 elseif encoding == 'euc-tw' 4982 let encoding = "" 4983 elseif encoding =~ '^euc\|^iso\|^koi' 4984 let encoding = substitute(encoding, '.*', '\U\0', '') 4985 elseif encoding == 'cp949' 4986 let encoding = 'KS_C_5601-1987' 4987 elseif encoding == 'cp936' 4988 let encoding = 'GBK' 4989 elseif encoding =~ '^ucs\|^utf' 4990 let encoding = 'UTF-8' 4991 else 4992 let encoding = "" 4993 endif 4994 4995 " Country specific settings 4996 " Automatically add polski when iso-8859-2 is used. 4997 if encoding =~ 'latin2\|cp1250' 4998 let countrysettings = '\usepackage{polski}' 4999 else 5000 let countrysettings = '' 5001 endif 5002 " }}} 5003 5004 " TOC depth 5005 if exists("s:vst_tocdepth") 5006 let tocdepth = '\setcounter{tocdepth}{'.s:vst_tocdepth.'}' 5007 else 5008 let tocdepth = '' 5009 endif 5010 5011 " User defined preamble 5012 if exists("g:vst_tex_preamble") && filereadable(g:vst_tex_preamble) 5013 let userpreamble = "\\input{".g:vst_tex_preamble."}" 5014 else 5015 let userpreamble = '' 5016 endif 5017 5018 let footer = '\end{document}' 5019 5020 "let file = substitute(file, "><", ">\n<", "g") 5021 " Special characters I 5022 " Here to not catch any backslashes 5023 let file = substitute(file, '\', '$\\backslash$', 'g') 5024 " Here to not catch footnotes 5025 let file = substitute(file, '{', '\\{', 'g') 5026 let file = substitute(file, '}', '\\}', 'g') 5027 5028 " Remove special chars catchers 5029 let file = substitute(file, '@', '@', 'g') 5030 let file = substitute(file, '[', '[', 'g') 5031 let file = substitute(file, '\', '\\', 'g') 5032 let file = substitute(file, ':', ':', 'g') 5033 let file = substitute(file, '&\\#64;', '@', 'g') 5034 let file = substitute(file, '&\\#91;', '[', 'g') 5035 let file = substitute(file, '&\\#92;', '\\', 'g') 5036 let file = substitute(file, '&\\#58;', ':', 'g') 5037 5038 " Footnotes have to be here to process them by other substitutions: 5039 for fn in keys(g:vst_footnotedb) 5040 let fnumberleft = '<vim:a href="#footnote-'.fn.'" name="target-'.fn.'">\[' 5041 let fnumberright = '\]</vim:a>' 5042 let content = escape(g:vst_footnotedb[fn], '&/\~') 5043 let file = substitute(file, fnumberleft.fn.fnumberright, '\\footnote{'.content.'}', '') 5044 endfor 5045 " Citations have to be here to process them by other substitutions: 5046 for fn in keys(g:vst_citationdb) 5047 let fnumberleft = '<vim:a href="#citation-'.fn.'" name="ctarget-'.fn.'">\[' 5048 let fnumberright = '\]</vim:a>' 5049 let content = escape(g:vst_citationdb[fn], '&/\~') 5050 let file = substitute(file, fnumberleft.fn.fnumberright, '\\footnote{'.content.'}', '') 5051 endfor 5052 " Remove footnotes from xml 5053 let file = substitute(file, '<vim:footnote.\{-}</vim:footnote>', '', 'g') 5054 " Remove citations from xml 5055 let file = substitute(file, '<vim:citation.\{-}</vim:citation>', '', 'g') 5056 5057 " Replace rawhtml with pre tags 5058 "let file = substitute(file, '<vim:rawhtml>', '<vim:pre>', 'g') 5059 "let file = substitute(file, '<.vim:rawhtml>', '</vim:pre>', 'g') 5060 5061 " Replace rawhtml with htmlonly tags 5062 let file = substitute(file, '<vim:rawhtml>', '<vim:htmlonly>', 'g') 5063 let file = substitute(file, '<.vim:rawhtml>', '</vim:htmlonly>', 'g') 5064 5065 " Remove htmlonly tags and contents 5066 let file = substitute(file, '<vim:htmlonly>.\{-}<.vim:htmlonly>', '', 'g') 5067 5068 5069 " Special characters II 5070 let file = substitute(file, '\~', '\\\~{}', 'g') 5071 let file = substitute(file, ' ', '\~', 'g') 5072 let file = substitute(file, '&', '\\\&', 'g') 5073 let file = substitute(file, '<', '<', 'g') 5074 let file = substitute(file, '>', '>', 'g') 5075 let file = substitute(file, '©', '(c)', 'g') 5076 let file = substitute(file, '#', '\\#', 'g') 5077 let file = substitute(file, '\(backslash\)\@<!\$\(.backslash\)\@!', '\\$', 'g') 5078 let file = substitute(file, '%', '\\%', 'g') 5079 let file = substitute(file, '\^', '\\^{}', 'g') 5080 " Hah. This will break _ in links. Problem may exists also with & 5081 let file = substitute(file, '_', '\\_', 'g') 5082 " TeX symbols 5083 let file = substitute(file, 'LaTeX', '\\LaTeX{}', 'g') 5084 let file = substitute(file, 'a\@<!TeX', '\\TeX{}', 'g') 5085 " Very dirty hack to compile docs but should fix also other things. 5086 " Maybe not so common but very hard to spot when proofreading text. 5087 let file = substitute(file, '>\\<', '>\\\\<', 'g') 5088 let file = substitute(file, '\(^\|\s\)\\\($\|\s\)', '\1\\\2', 'g') 5089 " 5090 let file = substitute(file, "^", '\\begin{document}'."\n", "") 5091 5092 " Create subtitles 5093 let file = substitute(file, '<vim:p class="subh.\{-}>\(.\{-}\)</vim:p>', '\\subtitle{\1}', "g") 5094 5095 " Create verse environment 5096 let file = substitute(file, '<vim:p class="verse.\{-}>\(.\{-}\)</vim:p>', '\\begin{verse}\n\1\n\\end{verse}', "g") 5097 5098 " Create attributions 5099 let file = substitute(file, '<vim:p class="attribution.\{-}>\(.\{-}\)</vim:p>', '\\attribution{\1}', "g") 5100 5101 " Replace table of contents 5102 let file = substitute(file, '<vim:p id="tocheader" \_.\{-}\.\. comment:: end of toc -->', '\n\\tableofcontents', '') 5103 5104 " Replace new line tags <vim:br> 5105 let file = substitute(file, '\n\s*<vim:br.\{-}>\s*\n', '\n\n', "g") 5106 let file = substitute(file, '<vim:br.\{-}>', '\\\\', "g") 5107 5108 " Title 5109 let file = substitute(file, '<vim:h1.\{-}>\_s*\(.\{-}\)</vim:h1>', '\\title{\1}\n\\maketitle', "g") 5110 " Sections 5111 let file = substitute(file, '<vim:h2 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\section{', "g") 5112 let file = substitute(file, '<vim:h3 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\subsection{', "g") 5113 let file = substitute(file, '<vim:h4 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\subsubsection{', "g") 5114 let file = substitute(file, '<vim:h5 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\paragraph{', "g") 5115 let file = substitute(file, '<vim:h6 id="\(.\{-}\)".\{-}>', '\\hypertarget{\1}{}\n\\subparagraph{', "g") 5116 let file = substitute(file, '<.vim:h[1-6]>', '}', 'g') 5117 5118 " Rawlatex directive 5119 " Ha. I didn't anticipate this - special chars inside of rawlatex will be 5120 " escaped. Operating on string is faster than going through file line 5121 " by line so unescaping of chars in while loop similar to pre handling still 5122 " should be faster. 5123 let file = substitute(file, '<vim:rawlatex>', '% Begin rawlatex', "g") 5124 let file = substitute(file, '<.vim:rawlatex>', '% End rawlatex', "g") 5125 " And the same for latexonly 5126 let file = substitute(file, '<vim:latexonly>', '% Begin rawlatex', "g") 5127 let file = substitute(file, '<.vim:latexonly>', '% End rawlatex', "g") 5128 " And the same for rawboth 5129 let file = substitute(file, '<vim:rawboth>', '% Begin rawlatex', "g") 5130 let file = substitute(file, '<.vim:rawboth>', '% End rawlatex', "g") 5131 5132 " Lists 5133 let file = substitute(file, '<vim:li.\{-}>', '\\item ', 'g') 5134 let file = substitute(file, '<.vim:li>', "", "g") 5135 let file = substitute(file, '<vim:ul.\{-}>', '\\begin{itemize}', "g") 5136 let file = substitute(file, '<.vim:ul.\{-}>', '\\end{itemize}', "g") 5137 " Enumitem and enumerate are in conflict. It has to be one or the 5138 " other 5139 if file =~ 'vim:ol class="[^>]\{-}start="' 5140 let file = substitute(file, '<vim:ol class="loweralpha[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\alph*.,start=\1]', "g") 5141 let file = substitute(file, '<vim:ol class="upperalpha[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\Alph*.,start=\1]', "g") 5142 let file = substitute(file, '<vim:ol class="lowerroman[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\roman*.,start=\1]', "g") 5143 let file = substitute(file, '<vim:ol class="upperroman[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\Roman*.,start=\1]', "g") 5144 let file = substitute(file, '<vim:ol class="decimal[^>]\{-}start="\(\d\+\)">', '\\begin{enumerate}[label=\\arabic*.,start=\1]', "g") 5145 let file = substitute(file, '<vim:ol class="loweralpha.\{-}>', '\\begin{enumerate}[label=\\alph*.]', "g") 5146 let file = substitute(file, '<vim:ol class="upperalpha.\{-}>', '\\begin{enumerate}[label=\\Alph*.]', "g") 5147 let file = substitute(file, '<vim:ol class="lowerroman.\{-}>', '\\begin{enumerate}[label=\\roman*.]', "g") 5148 let file = substitute(file, '<vim:ol class="upperroman.\{-}>', '\\begin{enumerate}[label=\\Roman*.]', "g") 5149 let file = substitute(file, '<vim:ol.\{-}>', '\\begin{enumerate}[label=\\arabic*.]', "g") 5150 let listings = 'enumitem' 5151 else 5152 let file = substitute(file, '<vim:ol class="loweralpha.\{-}>', '\\begin{enumerate}[a.]', "g") 5153 let file = substitute(file, '<vim:ol class="upperalpha.\{-}>', '\\begin{enumerate}[A.]', "g") 5154 let file = substitute(file, '<vim:ol class="lowerroman.\{-}>', '\\begin{enumerate}[i.]', "g") 5155 let file = substitute(file, '<vim:ol class="upperroman.\{-}>', '\\begin{enumerate}[I.]', "g") 5156 let file = substitute(file, '<vim:ol.\{-}>', '\\begin{enumerate}[1.]', "g") 5157 let listings = 'enumerate' 5158 endif 5159 let file = substitute(file, '<.vim:ol>', '\\end{enumerate}', "g") 5160 5161 " Field lists 5162 let file = substitute(file, '<vim:dl class="field.\{-}>', '\\begin{deflist}{Keywords:}\n', 'g') 5163 let file = substitute(file, '<vim:dt class="field.\{-}>\(.\{-}\)</vim:dt>', '\\item[\1]', 'g') 5164 let file = substitute(file, '<vim:dd class="field.\{-}>', '', 'g') 5165 let file = substitute(file, '</vim:dd>', '', 'g') 5166 let file = substitute(file, "</vim:dl>", '\\end{deflist}', 'g') 5167 5168 " Option lists 5169 let file = substitute(file, '<vim:dl class="option">', '\\begin{optlist}{longoptionslist}\n', 'g') 5170 let file = substitute(file, '<vim:dt>\(.\{-}\)</vim:dt>', '\\item[\1]', 'g') 5171 let file = substitute(file, '<vim:dt class="option">\(.\{-}\)</vim:dt>', '\\item[\1]', 'g') 5172 let file = substitute(file, '<vim:dd class="option">', '', 'g') 5173 let file = substitute(file, '<vim:dd>', '', 'g') 5174 let file = substitute(file, "</vim:dl class=\"option\">", '\\end{optlist}', 'g') 5175 5176 " Definition lists 5177 let file = substitute(file, '<vim:dl>', '\\begin{deflist}{iii}', 'g') 5178 let file = substitute(file, '<vim:dt class="normal">\(.\{-}\)</vim:dt>', '\\item[\1]', 'g') 5179 let file = substitute(file, '<vim:dd class="normal">', '', 'g') 5180 let file = substitute(file, '</vim:dd>', '', 'g') 5181 "let file = substitute(file, "</vim:dl>", '\\end{deflist}', 'g') 5182 " 5183 " Rubric 5184 let file = substitute(file, '<vim:rubric.\{-}>', '\\rubric{ ', "g") 5185 let file = substitute(file, "</vim:rubric>", ' }', "g") 5186 5187 " Pull-quote 5188 let file = substitute(file, '<vim:pullquote>', '\\begin{pullquote}', "g") 5189 let file = substitute(file, "</vim:pullquote>", '\\end{pullquote}', "g") 5190 5191 " Blockquote 5192 let file = substitute(file, "<vim:blockquote.\\{-}>", '\\begin{quotation}', "g") 5193 let file = substitute(file, "</vim:blockquote>", '\\end{quotation}', "g") 5194 5195 " Text styles 5196 let file = substitute(file, '<vim:em.\{-}>', '\\emph{', "g") 5197 let file = substitute(file, "</vim:em>", "}", "g") 5198 let file = substitute(file, '<vim:strong.\{-}>', '\\textbf{', "g") 5199 let file = substitute(file, "</vim:strong>", "}", "g") 5200 let file = substitute(file, '<vim:code.\{-}>', '\\texttt{', "g") 5201 let file = substitute(file, "</vim:code>", "}", "g") 5202 5203 " Tables 5204 let file = substitute(file, '<vim:table class="\(.\{-}\)" summary=".\{-}coln\(.\{-}\)">', '\\setlongtables\n\\begin{center}\n\\begin{longtable}[c]{\1coln\2}\\hline\n', "g") 5205 let file = substitute(file, "<vim:thead>", '', "g") 5206 let file = substitute(file, "</vim:thead>", '\\endhead', "g") 5207 let file = substitute(file, "<vim:tfoot>", '', "g") 5208 let file = substitute(file, "</vim:tfoot>", '', "g") 5209 let file = substitute(file, "</vim:table>", '\\end{longtable}\n\\end{center}', "g") 5210 let file = substitute(file, '<vim:tr>\n\?<vim:td>', '', "g") 5211 let file = substitute(file, '<vim:td>', ' \& ', "g") 5212 let file = substitute(file, "</vim:tr>", ' \\\\ \\hline', "g") 5213 let file = substitute(file, '<vim:tr>\n\?<vim:td colspan="\(.\{-}\)".\{-} summary="\(.\{-}\)">\(.\{-}\)\_s*</vim:td>', '\n\\multicolumn{\1}{|p{0.\2\\textwidth}|}{\3}', "g") 5214 let file = substitute(file, '<vim:td colspan="\(.\{-}\)".\{-} summary="\(.\{-}\)">\(.\{-}\)\_s*</vim:td>', ' \& \\multicolumn{\1}{p{0.\2\\textwidth}|}{\3}', "g") 5215 let file = substitute(file, "</vim:td>", '', "g") 5216 5217 " Line 5218 " \transition allows for easy change of transition display, eg. for 5219 " fancy graphics 5220 let file = substitute(file, "<vim:hr.\\{-}>", '\\transition', "g") 5221 5222 " Comment 5223 let file = substitute(file, "<vim:!--", '% ', "g") 5224 5225 " Links 5226 let file = substitute(file, '<vim:a href="\(#\)\?\(.\{-}\)".\{-}>\(.\{-}\)</vim:a>', '\\href{\2}{\3}', 'g') 5227 let file = substitute(file, '<vim:span id="\(.\{-}\)".\{-}>\(.\{-}\)</vim:span>', '\\hypertarget{\1}{\2}', 'g') 5228 5229 " Subscript, superscript 5230 let file = substitute(file, '<vim:sub.\{-}>\(.\{-}\)</vim:sub>', '\\subs{\1}', 'g') 5231 let file = substitute(file, '<vim:sup.\{-}>\(.\{-}\)</vim:sup>', '\\sups{\1}', 'g') 5232 5233 " Fix address special field 5234 let file = substitute(file, '<vim:pre class="address">\(.\{-}\)</vim:pre>', '\1', 'g') 5235 5236 " Replace unknown with pre elements in frame 5237 let file = substitute(file, '<vim:unknown>', '<vim:span class="big">Unknown element</vim:span>\n<vim:pre>', 'g') 5238 let file = substitute(file, '</vim:unknown>', '</vim:pre>', 'g') 5239 5240 " Title-reference role (<vim:cite>) 5241 let file = substitute(file, '<vim:cite.\{-}>', '\\emph{', 'g') 5242 let file = substitute(file, '</vim:cite>', '}', 'g') 5243 5244 " Class big, small 5245 let file = substitute(file, '<vim:span class="big.\{-}>', '{\\large ', 'g') 5246 let file = substitute(file, '<vim:span class="small.\{-}>', '{\\small ', 'g') 5247 let file = substitute(file, '</vim:span>', '}', 'g') 5248 5249 " Figure 5250 let file = substitute(file, '<vim:figure.\{-}>', '\\begin{center}\n\\begin{minipage}{0.6\\textwidth}', 'g') 5251 let file = substitute(file, '</vim:figure>', '\\end{minipage}\n\\end{center}', 'g') 5252 5253 " Create ghost commands for custom block directives 5254 let file = substitute(file, '<vim:block.\{-}class="\(.\{-}\)">', '\\vst\1{', 'g') 5255 let file = substitute(file, '</vim:block>', '}', 'g') 5256 5257 " Create ghost commands for custom container directives 5258 let file = substitute(file, '<vim:container.\{-}class="\(.\{-}\)">', '\\vst\1{', 'g') 5259 let file = substitute(file, '</vim:container>', '}', 'g') 5260 5261 " Topic 5262 let file = substitute(file, '<vim:topic.\{-}>', '\\hfill\\begin{minipage}{0.9\\textwidth}', 'g') 5263 let file = substitute(file, '</vim:topic>', '\\end{minipage}', 'g') 5264 5265 " Sidebar 5266 let file = substitute(file, '<vim:sidebar.\{-}>', '\\hfill\\begin{minipage}{0.9\\textwidth}', 'g') 5267 let file = substitute(file, '</vim:sidebar>', '\\end{minipage}', 'g') 5268 5269 " Divs 5270 let file = substitute(file, '<vim:div.\{-}>', '\\begin{center}\n\\fbox{\\begin{minipage}{0.8\\textwidth}', 'g') 5271 let file = substitute(file, '</vim:div>', '\\end{minipage}}\n\\end{center}', 'g') 5272 " Div titles (<vim:span> was already replaced) 5273 let file = substitute(file, '<vim:span class="notetitle">\(.\{-}\)}', '\\textbf{\\sffamily\\large \1}\n\\vspace{2mm}', 'g') 5274 5275 " Remove rest of vim:span 5276 " let file = substitute(file, '<vim:span.\{-}>', '\\emph{', 'g') 5277 let file = substitute(file, '<vim:span class="\(.\{-}\)">', '\\vst\1{', 'g') 5278 5279 " Replace empty vim:p tags when hypertargets 5280 let file = substitute(file, '<vim:p id="\(.\{-}\)"></vim:p>', '\\hypertarget{\1}{}', "g") 5281 " Ignore all other <vim:p> tags 5282 let file = substitute(file, '<.\?vim:p\>.\{-}>', "", "g") 5283 5284 " Make sure no (La)TeX entity is in URL address of hyperlinks 5285 let file = substitute(file, '\\href{\([^}]\{-}\)\\\(La\)\?TeX{}', '\\href{\1\2TeX', 'g') 5286 let file = substitute(file, '\\hypertarget{\([^}]\{-}\)\\\(La\)\?TeX{}', '\\hypertarget{\1\2TeX', 'g') 5287 " Unescape _ from hyperlinks 5288 let file = substitute(file, '\\href{\([^}]\{-}\)\\_', '\\href{\1_', 'g') 5289 let file = substitute(file, '\\hypertarget{\([^}]\{-}\)\\_', '\\hypertarget{\1_', 'g') 5290 " Prepare newcommands from roles 5291 if exists("g:vst_roledb") 5292 let rolenewcommands = '%% Commands for content of roles directives'."\n" 5293 let rolekeys = keys(g:vst_roledb) 5294 for i in range(len(rolekeys)) 5295 let name = g:vst_roledb[rolekeys[i]] 5296 let rolenewcommands .= '\newcommand{\vst'.name.'}[1]{\textnormal{#1}}'."\n" 5297 endfor 5298 unlet! rolekeys 5299 unlet! name 5300 else 5301 let rolenewcommands = "\n" 5302 endif 5303 " Prepare newcommands from containers 5304 if len("g:vst_containers") > 0 5305 let containernewcommands = '%% Commands for content of container directives'."\n" 5306 let usednames = '' 5307 for name in g:vst_containers 5308 if usednames !~ ','.name.',' 5309 let usednames .= ','.name.',' 5310 let containernewcommands .= '\newcommand{\vst'.name.'}[1]{#1}'."\n" 5311 endif 5312 endfor 5313 else 5314 let containernewcommands = "\n" 5315 endif 5316 5317 " Preamble {{{ 5318 " This one is better for deflist but has some not nice side effects 5319 " which have to be worked out 5320 "\.'{\renewcommand{\makelabel}[1]{\parbox[b]{\labelwidth}{\makebox[0pt][l]{\textbf{##1}}\mbox{}\\}}'."\n" 5321 let preamble = 5322 \ '\documentclass[12pt]{article}'."\n" 5323 \.'%% Generated by Vim reStructured Text '.s:vst_ver.' - Vim '.v:version/100.".".v:version % 100."\n" 5324 \.'\usepackage[a4paper,margin=2.5cm,nohead]{geometry}'."\n" 5325 \.'\usepackage{'.listings."}\n" 5326 \.'\usepackage{graphicx}'."\n" 5327 \.'\usepackage{longtable}'."\n" 5328 \.'\usepackage{tabularx}'."\n" 5329 \.'\usepackage{amsmath}'."\n" 5330 \.'\usepackage['.encoding."]{inputenc}\n" 5331 \.countrysettings."\n" 5332 \.'\newenvironment{deflist}[1]{%'."\n" 5333 \.'\begin{list}{}'."\n" 5334 \.'{\renewcommand{\makelabel}[1]{\textbf{##1}\hfill}'."\n" 5335 \.'\settowidth{\labelwidth}{\textbf{#1}}'."\n" 5336 \.'\leftmargin=\labelwidth'."\n" 5337 \.'\advance \leftmargin\labelsep}}'."\n" 5338 \.'{\end{list}}'."\n" 5339 \.'\newenvironment{optlist}[1]{%'."\n" 5340 \.'\begin{list}{}'."\n" 5341 \.'{\renewcommand{\makelabel}[1]{\texttt{##1}\hfill}'."\n" 5342 \.'\settowidth{\labelwidth}{\texttt{#1}}'."\n" 5343 \.'\leftmargin=\labelwidth'."\n" 5344 \.'\advance \leftmargin\labelsep}}'."\n" 5345 \.'{\end{list}}'."\n" 5346 \.'\newenvironment{pullquote}{\begin{quotation}\Large}{\end{quotation}}'."\n" 5347 \.'\setlength{\extrarowheight}{2pt}'."\n" 5348 \.tocdepth."\n" 5349 \.'\newcommand{\transition}{\begin{center}\rule{.8\textwidth}{0.2pt}\end{center}}'."\n" 5350 \.'\newcommand{\subtitle}[1]{{\large\textsc{#1}}\vskip15pt}'."\n" 5351 \.'\newcommand{\subs}[1]{\raisebox{-0.7ex}{\footnotesize #1}}'."\n" 5352 \.'\newcommand{\sups}[1]{\raisebox{0.7ex}{\footnotesize #1}}'."\n" 5353 \.'\newcommand{\attribution}[1]{\raggedleft\textit{#1}}'."\n" 5354 \.'\newcommand{\rubric}[1]{\vskip15pt{\large #1}}'."\n" 5355 \.rolenewcommands."\n" 5356 \.containernewcommands."\n" 5357 \.userpreamble."\n" 5358 \.'\usepackage[pdftex]{hyperref}'."\n" 5359 " Additional data {{{ 5360 let author = '' 5361 let data = '' 5362 if has_key(g:vst_fielddb, 'author') 5363 let author = '\author{'.g:vst_fielddb['author'].'}'."\n" 5364 endif 5365 if has_key(g:vst_fielddb, 'date') 5366 if g:vst_fielddb['date'] == 'NONE' 5367 let g:vst_fielddb['date'] = '' 5368 endif 5369 let data = '\date{'.g:vst_fielddb['date'].'}'."\n" 5370 else 5371 let data = '' 5372 endif 5373 " }}} 5374 " PDF Info {{{ 5375 let pdfinfo = '' 5376 let pdfauthor = '' 5377 let pdftitle = '' 5378 let pdfsubject = '' 5379 let pdfkeywords = '' 5380 if has_key(g:vst_fielddb, 'author') 5381 let pdfauthor = 'pdfauthor={'.g:vst_fielddb['author']."},\n" 5382 endif 5383 if has_key(g:vst_fielddb, 'title') 5384 let pdftitle = 'pdftitle={'.g:vst_fielddb['title']."},\n" 5385 endif 5386 if has_key(g:vst_fielddb, 'keywords') 5387 let pdfkeywords = 'pdfkeywords={'.g:vst_fielddb['keywords']."},\n" 5388 endif 5389 if has_key(g:vst_fielddb, 'subject') 5390 let pdfsubject = 'pdfsubject={'.g:vst_fielddb['subject']."}" 5391 endif 5392 for key in keys(g:vst_metadb) 5393 if key =~ 'author' && pdfauthor == '' 5394 let pdfauthor = 'pdfauthor={'.g:vst_metadb[key]."},\n" 5395 elseif key =~ 'title' && pdftitle == '' 5396 let pdftitle = 'pdftitle={'.g:vst_metadb[key]."},\n" 5397 elseif key =~ 'keywords' && pdfkeywords == '' 5398 let pdfkeywords = 'pdfkeywords={'.g:vst_metadb[key]."},\n" 5399 elseif key =~ 'subject' && pdfsubject == '' 5400 let pdfsubject = 'pdfsubject={'.g:vst_metadb[key]."}" 5401 endif 5402 endfor 5403 5404 if exists("g:vst_doc_title") 5405 let pdftitle = 'pdftitle={'.substitute(g:vst_doc_title, '^\s*', '', '')."},\n" 5406 endif 5407 5408 let pdfinfo = "\\hypersetup{\npdfcreator={VST, LaTeX, hyperref},\n" 5409 \."bookmarksopen=true,\nbookmarksopenlevel=2,\n" 5410 \."colorlinks=true,urlcolor=blue,\n" 5411 \.pdfauthor.pdftitle.pdfkeywords.pdfsubject."}\n" 5412 5413 let file = preamble."\n".pdfinfo."\n".author.data."\n".file."\n".footer 5414 " }}} 5415 " }}} 5416 5417 " Create comments 5418 let file = substitute(file, '<vim:comment>\(.\{-}\)<.vim:comment>', '\=VST_CreateTexComment(submatch(1))', 'g') 5419 5420 new 5421 if &compatible == 1 5422 set nocompatible 5423 endif 5424 0put =file 5425 5426 " Go through tables to tune them {{{ 5427 " 1. Create preamble of table 5428 " 2. Remove \hline for borderless tables 5429 silent call cursor(1,1) 5430 while search('begin{longtable', 'W') 5431 unlet! line1 line2 5432 let line1 = line('.') 5433 if getline('.') =~ 'vstbordercoln' 5434 "silent exe line1.','.line2.'s/\(multicolumn{\d\+}{\)\(.\{-}\)}/\=submatch(1).substitute(submatch(2), "\\(\\d\\+\\)+", "|p{0.\\1\\\\\\\\textwidth}", "g")."}"/ge' 5435 silent s/vstbordercoln\(.\{-}\)}/\='|'.substitute(submatch(1), '\(\d\+\)+', 'p{0.\1\\\\textwidth}|', 'g').'}'/e 5436 call search('end{longtable', 'W') 5437 let line2 = line('.') 5438 "silent exe line1.','.line2.'s/\(multicolumn{\d\+}{\)\(.\{-}\)}/\=submatch(1).substitute(submatch(2), "\\(\\d\\+\\)+", "|p{0.\\1\\\\\\textwidth}", "g")."}"/ge' 5439 "silent exe line1.','.line2.'s/\(\& \\multicolumn{\d\+}{\)|/\1/ge' 5440 elseif getline('.') =~ 'vstblesscoln' 5441 silent s/vstblesscoln\(.\{-}\)}/\=substitute(submatch(1), '\(\d\+\)+', 'p{0.\1\\\\textwidth} ', 'g').'}'/e 5442 call search('end{longtable', 'W') 5443 let line2 = line('.') 5444 silent exe line1.','.line2.'s/\\hline\($\|\\end{longtable\)/\1/e' 5445 silent exe line1.','.line2.'g/\\multicolumn/s/\(\\textwidth}\)|/\1/ge' 5446 silent exe line1.','.line2.'g/\\multicolumn/s/\(\\multicolumn{\d\+}{\)|/\1/ge' 5447 endif 5448 " NOTE: this changes range so line1, line2 are useless after that 5449 silent exe line1.','.line2.'s/\_s*&\_s*/\r\&\r/ge' 5450 endwhile 5451 " }}} 5452 " Process <img> {{{ 5453 silent call cursor(1,1) 5454 while search('<vim:img', 'W') != 0 5455 let image = getline('.') 5456 let imagelink = 0 5457 " Detect if image is link. It requires messing with order of 5458 " elements 5459 if getline(line('.')-1) =~ 'href.*{$' 5460 let imagelink = 1 5461 let link = getline(line('.')-1) 5462 endif 5463 let class = matchstr(image, 'class="\zs.\{-}\ze"') 5464 let src = matchstr(image, 'src="\zs.\{-}\ze"') 5465 let width = matchstr(image, 'width="\zs.\{-}\ze"') 5466 let height = matchstr(image, 'height="\zs.\{-}\ze"') 5467 if width == '' && height == '' 5468 let dimensions = '' 5469 elseif width != '' && height == '' 5470 let dimensions = '[width='.width.'pt]' 5471 elseif height != '' && width == '' 5472 let dimensions = '[height='.height.'pt]' 5473 else 5474 let dimensions = '[height='.height.'pt, width='.width.'pt]' 5475 endif 5476 let figure = '\\includegraphics'.dimensions.'{'.src.'}' 5477 let alt = '' 5478 let title = '' 5479 let opening = '' 5480 let caption = '' 5481 let closing = '' 5482 if class !~ 'inline' 5483 let alt = matchstr(image, 'alt="\zs.\{-}\ze"') 5484 let title = matchstr(image, 'title="\zs.\{-}\ze"') 5485 let opening = '\\begin{figure}[ht]\\centering' 5486 if title != '' 5487 let caption = '\\caption{'.title.'}' 5488 "elseif alt != '' 5489 "let caption = '\\caption{'.alt.'}' 5490 else 5491 let caption = '' 5492 endif 5493 let closing = '\\end{figure}' 5494 endif 5495 if imagelink != 0 5496 let link = escape(link, '\') 5497 let imagestring = opening.link.figure.'}'.caption.closing 5498 " Remove href end closing }, it require jumping between the 5499 " lines. 5500 silent .-1s/.*//e 5501 silent .+2s/.*//e 5502 silent normal! k 5503 else 5504 let imagestring = opening.figure.caption.closing 5505 endif 5506 silent exe 's+<vim:img.\{-}>+'.imagestring.'+e' 5507 silent normal! j 5508 endwhile 5509 " }}} 5510 " Processing preformatted text. {{{ 5511 " Not using verbatim because it is 5512 " in conflict with minipages 5513 silent call cursor(1,1) 5514 while search('^\s*<vim:pre', 'W') 5515 silent s+.*+\\begin{ttfamily}\\begin{flushleft}+ 5516 silent normal! j 5517 let line1 = line('.') 5518 let indlist = [] 5519 while getline('.') !~ '</vim:pre' 5520 if getline('.') =~ '^\s*$' 5521 silent normal! j 5522 continue 5523 endif 5524 let preind = strlen(matchstr(getline('.'), '^\s*')) 5525 let indlist += [preind] 5526 silent normal! j 5527 endwhile 5528 let line2 = line('.')-1 5529 if line2 < line1 5530 let line2 = line1 5531 endif 5532 let lineend = line('.') 5533 let ind = min(indlist) <= 0 ? 0 : min(indlist) 5534 silent exe line1.','.line2.'s/^ \{'.ind.'}/ /e' 5535 silent exe line1.','.line2.'s+^+\\mbox{+e' 5536 silent exe line1.','.line2.'s+$+}\\\\+e' 5537 silent exe line1.','.line2.'s/ /\~/ge' 5538 silent exe lineend's+.*+\\end{flushleft}\\end{ttfamily}+' 5539 endwhile 5540 " }}} 5541 " Unescaping special chars from rawlatex. {{{ 5542 silent call cursor(1,1) 5543 while search('^\s*% Begin rawlatex', 'W') 5544 silent normal! j 5545 let line1 = line('.') 5546 while getline('.') !~ '% End rawlatex' 5547 silent normal! j 5548 endwhile 5549 let line2 = line('.')-1 5550 silent exe line1.','.line2.'s/^\s\+//e' 5551 silent exe line1.','.line2.'s/\$\\backslash\$/\\/ge' 5552 silent exe line1.','.line2.'s/\\\$/$/ge' 5553 silent exe line1.','.line2.'s/\\\({\|\}\)/\1/ge' 5554 silent exe line1.','.line2.'s/\\\^{}/^/ge' 5555 silent exe line1.','.line2.'s/\\\~{}/\~/ge' 5556 silent exe line1.','.line2.'s/\\#/#/ge' 5557 silent exe line1.','.line2.'s/\\%/%/ge' 5558 silent exe line1.','.line2.'s/\\_/_/ge' 5559 " Hack to workaround inner slash escaping mechanism. consider 5560 " single backslash at the end of line as double backslash meaning 5561 " 'new line' 5562 silent exe line1.','.line2.'s/\\$/\\\\/ge' 5563 endwhile 5564 " }}} 5565 " In lines not belonging to pre enclose < and > in $$ to show them. {{{ 5566 " \langle, \rangle would be more proper solution but they 5567 " look too differently for my taste. 5568 silent v/^\\mbox/s/</$<$/ge 5569 silent v/^\\mbox/s/>/$>$/ge 5570 silent v/^\\mbox\|begin{longtable\|multicolumn{/s/|/$|$/ge 5571 " }}} 5572 " Beautyfication of LaTeX output {{{ 5573 silent %s/^\s*$// 5574 silent %s/\n\{3,}/\r\r/ 5575 silent %s/\n\+\(\n\s*\\end\)/\1/ 5576 silent %s/\(\\begin{.\{-}}\n\)\n\+/\1/ 5577 " Compressing of titles 5578 silent %s/title{\n/title{/e 5579 silent %s/section{\n/section{/e 5580 silent %s/paragraph{\n/paragraph{/e 5581 " Shorten lists 5582 silent %s/\\item\s*\n\n/\\item\r/e 5583 " Because multiple spaces are meaningless: 5584 silent %s/\s\+/ /ge 5585 " Test it 5586 silent %s/{\_s*/{/ge 5587 silent %s/\n\n\s*&\s*\n\n/\r\&\r/ge 5588 silent %s/\n\n \(\\\\ \\hline\)\s*\n\n/\r\1\r/ge 5589 " Fix vertical space in admonitions 5590 silent %s/\(\\vspace{2mm}\n\)\(\S\)/\1\r\2/ge 5591 " Replace lines for .. figure:: - image first, minipage later. 5592 silent %s/\(\\begin{minipage}{0\.6\\textwidth}\)\n\(\\begin{figure.*\)/\2\r\1/ge 5593 " Remove special chars catchers 5594 silent %s/@/@/ge 5595 silent %s/[/[/ge 5596 silent %s/\/\\/ge 5597 silent %s/:/:/ge 5598 silent %s/&\\#64;/@/ge 5599 silent %s/&\\#91;/[/ge 5600 silent %s/&\\#92;/\\/ge 5601 silent %s/&\\#58;/:/ge 5602 " Insert new line before \item[], it causes problems in complex 5603 " environments 5604 silent %s/\\item\[/\r\0/ge 5605 " But we don't like if there is more than one blank line 5606 silent %s/\n\n\n\\item\[/\r\r\\item\[/ge 5607 " Remove empty deflist environment 5608 " may be a problem when :Date: NONE is the only element of field list 5609 silent %s/\\begin{deflist}{.\{-}}\n\\end{deflist}//ge 5610 " Replace non-breaking space characters with ~ 5611 silent %s/ /\~/ge 5612 " }}} 5613 " Insert raw files {{{ 5614 silent call cursor(1,1) 5615 while search('-vst-raw-file-placeholder:', 'W') 5616 let file = matchstr(getline('.'), '-vst-raw-file-placeholder:\zs.*') 5617 " Remove \ before _ - in most cases it was placed there by 5618 " escaping mechanism, not user 5619 let file = substitute(file, '\\_', '_', 'g') 5620 silent s/.*//ge 5621 exe 'silent read '.escape(file, ' \#%') 5622 endwhile 5623 " }}} 5624 5625 redraw! 5626 5627 " This is place for special CJK postprocessing 5628 " What if &encoding=='utf-8'? 5629 if &encoding =~? 'big5\|cp950\|euc-tw' || ( &encoding =~? '^utf' && v:ctype =~ 'big5' ) 5630 5631 silent! g/^\\usepackage.*geometry}/s/.*/\0\r\\usepackage{CJK}/ 5632 silent! g/^\\usepackage.*inputenc}/d 5633 silent! g/^\\usepackage.*hyperref}/s/.*/\\usepackage[CJKbookmarks,bookmarks=false,pdftex]{hyperref} 5634 silent! g/^bookmarksopen=true,$/d 5635 silent! g/^bookmarksopenlevel=2,$/d 5636 if encoding == 'Big5' 5637 silent! g/\\begin{document}/s/.*/\0\\begin{CJK}{Bg5}{}/ 5638 elseif encoding == 'UTF-8' 5639 silent! g/\\begin{document}/s/.*/\0\\begin{CJK}{UTF8}{}/ 5640 else 5641 silent! g/\\begin{document}/s/.*/\0\\begin{CJK}{}{}/ 5642 endif 5643 silent! g/\\end{document}/s/.*/\\end{CJK}\0/ 5644 5645 let cjkpreamble = '\renewcommand\CJKglue{\hskip -0.3pt plus 0.08\baselineskip}'."-cjk-newline-placeholder-" 5646 \.'\linespread{1.382}'."-cjk-newline-placeholder-" 5647 \.'\renewcommand{\arraystretch}{1.2}'."-cjk-newline-placeholder-" 5648 \.'\parindent=0pt'."-cjk-newline-placeholder-" 5649 \.'\parskip=1.382ex'."-cjk-newline-placeholder-" 5650 \.'\renewenvironment{quote}'."-cjk-newline-placeholder-" 5651 \.' {\list{}{\topsep 1ex\parsep 0ex\setlength\leftmargin{1.5em}%'."-cjk-newline-placeholder-" 5652 \.' \rightmargin\leftmargin}\item\relax\linespread{1.0}\small}%'."-cjk-newline-placeholder-" 5653 \.' {\endlist}'."-cjk-newline-placeholder-" 5654 \.'\let\oldfootnote\footnote'."-cjk-newline-placeholder-" 5655 \.'\renewcommand\footnote[1]{\oldfootnote{\renewcommand\baselinestretch{1.0}%'."-cjk-newline-placeholder-" 5656 \.'\large\footnotesize\ignorespaces#1}}'."-cjk-newline-placeholder-" 5657 \.'\addtolength{\footnotesep}{3pt}' 5658 5659 silent call cursor(1,1) 5660 silent call search('^\\usepackage{amsmath}') 5661 silent call append(line('.'), cjkpreamble) 5662 " Placeholder stuff is necessary because no Vim function for 5663 " inserting text like newline character. 5664 silent! %s/-cjk-newline-placeholder-/\r/g 5665 silent call cursor(1,1) 5666 5667 endif 5668 5669 " User postprocessing 5670 if g:vst_tex_post != '' && filereadable(g:vst_tex_post) 5671 exe "silent! source ".g:vst_tex_post 5672 endif 5673 5674 " Handling of pdf export {{{ 5675 if format =~ 'pdf' 5676 silent call cursor(1,1) 5677 let file_tex = filename.'.tex' 5678 if !exists('g:vst_pdf_command') 5679 let g:vst_pdf_command = 'pdflatex -interaction=nonstopmode' 5680 endif 5681 silent exe 'write! '.escape(file_tex, ' \#%') 5682 silent exe "call system(\"".g:vst_pdf_command." '".file_tex."'\")" 5683 if search('\\tableofcontents', 'W') 5684 silent exe "call system(\"".g:vst_pdf_command." '".file_tex."'\")" 5685 endif 5686 if v:shell_error == 0 5687 bw! % 5688 echomsg "Document compiled OK. You can view it in PDF viewer." 5689 if exists("g:vst_pdf_clean") && g:vst_pdf_clean == 1 5690 call delete(file_tex) 5691 call delete(filename.'.log') 5692 call delete(filename.'.out') 5693 call delete(filename.'.aux') 5694 endif 5695 if exists("g:vst_pdf_view") && g:vst_pdf_view == 1 5696 if !exists("g:vst_pdf_viewer") 5697 if has("win32") 5698 let g:vst_pdf_viewer = "" 5699 elseif has("unix") 5700 if executable("kpdf") 5701 let g:vst_pdf_viewer = "kpdf" 5702 elseif executable("xpdf") 5703 let g:vst_pdf_viewer = "xpdf" 5704 else 5705 let g:vst_pdf_viewer = "no_pdf_viewer" 5706 endif 5707 endif 5708 endif 5709 silent exe "call system(\"".g:vst_pdf_viewer." '".filename.".pdf'\")" 5710 silent redraw! 5711 endif 5712 else 5713 echomsg "Something went wrong, check TeX code or command settings." 5714 endif 5715 silent call cursor(1,1) 5716 call VST_End() 5717 return 5718 endif 5719 " }}} 5720 5721 " Latex-Suite (or any other tex ftype settings) brokes *many* 5722 " things. Load it at the end 5723 setlocal ft=tex 5724 if exists("g:vst_write_export") && g:vst_write_export != 0 5725 silent exe 'write! '.escape(filename, ' \#%').'.tex' 5726 endif 5727 5728 silent call cursor(1,1) 5729 " }}} 5730 " Auxiliary commands {{{ 5731 elseif format =~ '^head' 5732 " Symbols for section titles {{{ 5733 call VST_Headers(text) 5734 unlet! b:vst_first_parsing 5735 call VST_DictTable(g:vst_headers, 'Level', 'Symbol', 0) 5736 " }}} 5737 elseif format =~ '^toc' 5738 " Table of contents for file {{{ 5739 let line = line('.') 5740 call VST_Headers(text) 5741 unlet! b:vst_first_parsing 5742 let i = 1 5743 let tocc = [] 5744 let b:vst_toc_numbers = {} 5745 let i1 = -1 5746 let i2 = -1 5747 let i3 = -1 5748 let i4 = -1 5749 let i5 = -1 5750 let i6 = -1 5751 5752 while i < len(g:paras) 5753 if g:ptype[i] =~ '^h\d' 5754 " Real table 5755 call add(tocc, [g:ptype[i], g:paras[i], g:plinen[i]]) 5756 " Header numbers 5757 let header_text = matchstr(g:paras[i], '^.\{-}\ze\n') 5758 let lvl = strpart(g:ptype[i], 1) 5759 if lvl == 1 5760 let b:vst_toc_numbers[header_text] = '' 5761 let i2 = 0 5762 let i3 = 0 5763 let i4 = 0 5764 let i5 = 0 5765 let i6 = 0 5766 elseif lvl == 2 5767 let i2 += 1 5768 let b:vst_toc_numbers[header_text] = i2.' ' 5769 let i3 = 0 5770 let i4 = 0 5771 let i5 = 0 5772 let i6 = 0 5773 elseif lvl == 3 5774 let i3 += 1 5775 let b:vst_toc_numbers[header_text] = i2.'.'.i3.' ' 5776 let i4 = 0 5777 let i5 = 0 5778 let i6 = 0 5779 elseif lvl == 4 5780 let i4 += 1 5781 let b:vst_toc_numbers[header_text] = i2.'.'.i3.'.'.i4.' ' 5782 let i5 = 0 5783 let i6 = 0 5784 elseif lvl == 5 5785 let i5 += 1 5786 let b:vst_toc_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.' ' 5787 let i6 = 0 5788 elseif lvl == 6 5789 let i6 += 1 5790 let b:vst_toc_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.'.'.i6.' ' 5791 endif 5792 endif 5793 let i += 1 5794 endwhile 5795 5796 echo VST_TocTable(tocc, 'Nr', 'Title', ' Line', line) 5797 " }}} 5798 elseif format =~ '^fold' 5799 " Folding {{{ 5800 let b:vst_fold = {} 5801 call VST_Headers(text) 5802 unlet! b:vst_first_parsing 5803 " Prepare numbers of head lines {{{ 5804 let b:vst_fold_numbers = {} 5805 let i = 0 5806 let i1 = -1 5807 let i2 = -1 5808 let i3 = -1 5809 let i4 = -1 5810 let i5 = -1 5811 let i6 = -1 5812 while i < len(g:paras) 5813 if g:ptype[i] =~ '^h\d' 5814 let header_text = matchstr(g:paras[i], '^.\{-}\ze\n') 5815 let lvl = strpart(g:ptype[i], 1) 5816 if lvl == 1 5817 let b:vst_fold_numbers[header_text] = '' 5818 let i2 = 0 5819 let i3 = 0 5820 let i4 = 0 5821 let i5 = 0 5822 let i6 = 0 5823 elseif lvl == 2 5824 let i2 += 1 5825 let b:vst_fold_numbers[header_text] = i2.' ' 5826 let i3 = 0 5827 let i4 = 0 5828 let i5 = 0 5829 let i6 = 0 5830 elseif lvl == 3 5831 let i3 += 1 5832 let b:vst_fold_numbers[header_text] = i2.'.'.i3.' ' 5833 let i4 = 0 5834 let i5 = 0 5835 let i6 = 0 5836 elseif lvl == 4 5837 let i4 += 1 5838 let b:vst_fold_numbers[header_text] = i2.'.'.i3.'.'.i4.' ' 5839 let i5 = 0 5840 let i6 = 0 5841 elseif lvl == 5 5842 let i5 += 1 5843 let b:vst_fold_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.' ' 5844 let i6 = 0 5845 elseif lvl == 6 5846 let i6 += 1 5847 let b:vst_fold_numbers[header_text] = i2.'.'.i3.'.'.i4.'.'.i5.'.'.i6.' ' 5848 endif 5849 5850 let b:vst_fold[header_text] = lvl-1 5851 endif 5852 let i += 1 5853 endwhile 5854 " }}} 5855 " Prepare fold levels {{{ 5856 let b:vst_fold_lvl = matchstr(format, '\zs.\ze\s*$') 5857 if b:vst_fold_lvl =~ 'r' 5858 for i in [1, 2, 3, 4, 5, 6] 5859 let b:vst_fold_list_{i} = filter(deepcopy(b:vst_fold), 'v:val == i') 5860 let b:vst_flvl_{i} = keys(b:vst_fold_list_{i}) 5861 endfor 5862 else 5863 if b:vst_fold_lvl !~ '\d' 5864 let b:vst_fold_lvl = 0 5865 elseif b:vst_fold_lvl =~ '\d' && b:vst_fold_lvl > 6 5866 let b:vst_fold_lvl = 6 5867 endif 5868 if b:vst_fold_lvl != 0 5869 let b:vst_fold_list = filter(deepcopy(b:vst_fold), 'v:val <= b:vst_fold_lvl') 5870 else 5871 let b:vst_fold_list = b:vst_fold 5872 endif 5873 endif 5874 " }}} 5875 setlocal foldmethod=expr 5876 setlocal foldexpr=VST_FoldExpr(v:lnum) 5877 setlocal foldtext=VST_FoldText() 5878 " }}} 5879 elseif format =~ '^fblank' 5880 " Folding by blank lines {{{ 5881 let directive = matchstr(format, '^f\zs.*') 5882 setlocal foldmethod=expr 5883 set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1 5884 function! VST_FoldText() 5885 let text = getline(v:foldstart) 5886 let indent = '+'.v:folddashes 5887 return indent.repeat(' ', 2).text.' ' 5888 endfunction 5889 setlocal foldtext=VST_FoldText() 5890 " }}} 5891 elseif format =~ '^f' 5892 " Folding by directive {{{ 5893 "elseif format =~ '^f\(block\|container\|image\|figure\|sidebar\|compound\|topic\|rubric\|table\|tip\|note\|warning\|admonition\|include\|pull-quote\|class\|meta\|raw\|2html\)' 5894 let directive = matchstr(format, '^f\zs.*') 5895 setlocal foldmethod=expr 5896 "exe "setlocal foldexpr=getline(v:lnum)=~?'^\\\\s*\\\.\\\.\\\ ".directive."::'?'>1':1" 5897 exe "setlocal foldexpr=getline(v:lnum)=~?'^\\\\s*\\\.\\\.\\\ ".directive."'?'>1':1" 5898 function! VST_FoldDirective() 5899 let text = getline(v:foldstart) 5900 let indent = '+'.v:folddashes 5901 let fill = 65 - (len(indent) + len(text) + 3) 5902 if fill < 1 5903 let fill = 1 5904 endif 5905 return indent.' '.text.repeat(' ', fill).v:foldstart.' ('.v:foldstart*100/line('$').'%)' 5906 endfunction 5907 setlocal foldtext=VST_FoldDirective() 5908 " }}} 5909 elseif format =~ '^link' 5910 " Link table {{{ 5911 call VST_Headers(text) 5912 unlet! b:vst_first_parsing 5913 call VST_DictTable(g:vst_hlinkdb, 'Text', 'Link', 0) 5914 " }}} 5915 elseif format =~ '^slink' 5916 " Sorted link table {{{ 5917 call VST_Headers(text) 5918 unlet! b:vst_first_parsing 5919 call VST_DictTable(g:vst_hlinkdb, 'Text', 'Link', 1) 5920 " }}} 5921 elseif format =~ '^rep' 5922 " Replacement table {{{ 5923 call VST_Headers(text) 5924 unlet! b:vst_first_parsing 5925 call VST_DictTable(g:vst_replacedb, 'Symbol', 'Replacement', 0) 5926 " }}} 5927 elseif format =~ '^srep' 5928 " Sorted replacement table {{{ 5929 call VST_Headers(text) 5930 unlet! b:vst_first_parsing 5931 call VST_DictTable(g:vst_replacedb, 'Symbol', 'Replacement', 1) 5932 " }}} 5933 elseif format =~ '^help' 5934 " Help for commands {{{ 5935 echo 5936 \ "Help for :Vst arguments:\n" 5937 \."html - [default] export to HTML format\n" 5938 \."tex - export to LaTeX format\n" 5939 \."pdf - export to LaTeX format and compile PDF\n" 5940 \."rest - export to reST format\n" 5941 \."s5 - export to S5 HTML presentation\n" 5942 \." ---------------\n" 5943 \."toc - file table of contents\n" 5944 \."head - show used symbols for headers\n" 5945 \."link - show table of link declarations\n" 5946 \."slink - show sorted table of link declarations\n" 5947 \."rep - show table of replacements\n" 5948 \."srep - show sorted table of replacements\n" 5949 \."preproc - process inclusion commands (non-recursively)\n" 5950 \."help - this message\n" 5951 \." ---------------\n" 5952 \."fold - (re)create folds in file\n" 5953 \."foldr - (re)create folds recursively in file\n" 5954 \."fold1 - (re)create folds of 1st level headers in file\n" 5955 \."fold2 - (re)create folds up to 2nd level header in file\n" 5956 \."fold3 - (re)create folds up to 3rd level header in file\n" 5957 \."fold4 - (re)create folds up to 4th level header in file\n" 5958 \."fold5 - (re)create folds up to 5th level header in file\n" 5959 \."fold6 - (re)create folds up to 6th level header in file\n" 5960 \." ---------------\n" 5961 \."Additional commands:\n" 5962 \.":Vsti - immediately write file\n" 5963 \.":Vstm - display menus (no arguments)" 5964 return '' 5965 " }}} 5966 elseif format =~ '^pre' 5967 " Interpret all including commands and put them in file {{{ 5968 silent normal! ggdG 5969 let jtext = join(text, "\n") 5970 silent 0put =jtext 5971 silent call cursor(1,1) 5972 " }}} 5973 " }}} 5974 endif 5975 5976 call VST_End() 5977 5978 return '' 5979 5979 5980 5980 endfunction … … 5988 5988 " transition element 5989 5989 function! VST_Ornaments() 5990 " Get ornament character5991 " HEADDEF:5992 let s:vst_headdef = '\(=\{3,}\|+\{3,}\|\*\{3,}\|\^\{3,}\|%\{3,}\|\$\{3,}\|#\{3,}\|@\{3,}\|;\{3,}\|"\{3,}\|\.\{3,}\|,\{3,}\|`\{3,}\|\~\{3,}\|-\{3,}\|!\{3,}\|(\{3,}\|)\{3,}\|:\{3,}\|_\{3,}\|&\{3,}\|}\{3,}\|{\{3,}\||\{3,}\|?\{3,}\|<\{3,}\|>\{3,}\|\\\{3,}\|\[\{3,}\|\]\{3,}\|\/\{3,}\|''\{3,}\)'5993 let s:vst_headchars2 = '\(=\|+\|\*\|\^\|%\|\$\|#\|@\|;\|"\|\.\|,\|`\|\~\|-\|!\|(\|)\|:\|_\|&\|}\|{\||\|?\|<\|>\|\\\|\[\|\]\|\/\|''\)'5994 let curline = getline(line('.'))5995 let character = curline[len(curline)-1]5996 if curline =~ '^\s*$'5997 " Temporary thing, to by-pass headchars test5998 let character = '-'5999 elseif curline !~ '^\s*'.s:vst_headchars2.'\+$'6000 return ''6001 endif6002 6003 let prevline = getline(line('.')-1)6004 let nextline = getline(line('.')+1)6005 6006 if prevline =~ '^\s*$'6007 let prevline_is_empty = 16008 else6009 let prevline_is_empty = 06010 endif6011 6012 if nextline =~ '^\s*$'6013 let nextline_is_empty = 16014 else6015 let nextline_is_empty = 06016 endif6017 6018 if prevline_is_empty == 1 && nextline_is_empty == 16019 " We are to insert transition element6020 if &tw > 506021 let trans_len = &tw/36022 else6023 let trans_len = 206024 endif6025 if curline =~ '^\s*$'6026 " Current line consists of only white characters. Try to find last6027 " used transition6028 let last_trans_line = search('\n\s*\n\s*'.s:vst_headdef.'\s*\n\s*\n' , 'bWn') + 26029 if last_trans_line == 26030 let character = '-'6031 else6032 let character = matchstr(getline(last_trans_line), '^\s*\zs.\ze')6033 endif6034 endif6035 return repeat(character, trans_len)6036 elseif prevline_is_empty == 0 && nextline_is_empty == 16037 " Insert single ornament6038 let prevline_len = len(prevline)6039 if curline =~ '^\s*$'6040 " Current line consists of only white characters. Try to find last6041 " single ornament section6042 let last_single_ornament = search('\(\%^\|\n\s*\n\|\%^\s*\n\).\{-}\n\s*'.s:vst_headdef.'\s*\n\s*\n' , 'bWn') + 36043 if last_single_ornament == 4 && getline(1) =~ '^\s*$' && getline(2) =~ '^\s*$'6044 let last_single_ornament = 46045 elseif last_single_ornament == 4 && getline(1) =~ '^\s*$'6046 let last_single_ornament = 36047 let real3 = 16048 elseif last_single_ornament == 46049 let last_single_ornament = 26050 endif6051 if last_single_ornament == 36052 if !exists('real3')6053 let character = '-'6054 else6055 let character = matchstr(getline(last_single_ornament), '^\s*\zs.\ze')6056 unlet! real36057 endif6058 else6059 let character = matchstr(getline(last_single_ornament), '^\s*\zs.\ze')6060 endif6061 endif6062 if prevline_len < 36063 let ornament_len = 3 - len(curline)6064 else6065 let ornament_len = prevline_len - len(curline)6066 endif6067 return repeat(character, ornament_len)."\n"6068 elseif prevline_is_empty == 1 && nextline_is_empty == 06069 " Insert double ornament6070 let nextline_len = len(nextline)6071 " Unfortunately this line borks undo history6072 normal! 2"_dd6073 if curline =~ '^\s*$'6074 " Current line consists of only white characters. Try to find last6075 " used ornament6076 let last_double_ornament = search('\(\%^\|\n\s*\n\|\%^\s*\n\)\s*'.s:vst_headdef.'\s*\n.\{-}\n\s*\2\s*\n' , 'bWn') + 26077 if last_double_ornament == 3 && getline(1) =~ '^\s*$' && getline(2) !~ '^\s*$'6078 let last_double_ornament = 46079 endif6080 if last_double_ornament == 26081 let character = '='6082 else6083 let character = matchstr(getline(last_double_ornament), '^\s*\zs.\ze')6084 endif6085 endif6086 if len(curline) == 06087 let correction = 06088 else6089 let correction = 16090 endif6091 if nextline_len < 36092 let ornament_len = 36093 else6094 let ornament_len = nextline_len6095 endif6096 let ornament = repeat(character, ornament_len)6097 return ornament."\n".nextline."\n".ornament."\n"6098 else6099 return ''6100 endif6101 6102 return ''5990 " Get ornament character 5991 " HEADDEF: 5992 let s:vst_headdef = '\(=\{3,}\|+\{3,}\|\*\{3,}\|\^\{3,}\|%\{3,}\|\$\{3,}\|#\{3,}\|@\{3,}\|;\{3,}\|"\{3,}\|\.\{3,}\|,\{3,}\|`\{3,}\|\~\{3,}\|-\{3,}\|!\{3,}\|(\{3,}\|)\{3,}\|:\{3,}\|_\{3,}\|&\{3,}\|}\{3,}\|{\{3,}\||\{3,}\|?\{3,}\|<\{3,}\|>\{3,}\|\\\{3,}\|\[\{3,}\|\]\{3,}\|\/\{3,}\|''\{3,}\)' 5993 let s:vst_headchars2 = '\(=\|+\|\*\|\^\|%\|\$\|#\|@\|;\|"\|\.\|,\|`\|\~\|-\|!\|(\|)\|:\|_\|&\|}\|{\||\|?\|<\|>\|\\\|\[\|\]\|\/\|''\)' 5994 let curline = getline(line('.')) 5995 let character = curline[len(curline)-1] 5996 if curline =~ '^\s*$' 5997 " Temporary thing, to by-pass headchars test 5998 let character = '-' 5999 elseif curline !~ '^\s*'.s:vst_headchars2.'\+$' 6000 return '' 6001 endif 6002 6003 let prevline = getline(line('.')-1) 6004 let nextline = getline(line('.')+1) 6005 6006 if prevline =~ '^\s*$' 6007 let prevline_is_empty = 1 6008 else 6009 let prevline_is_empty = 0 6010 endif 6011 6012 if nextline =~ '^\s*$' 6013 let nextline_is_empty = 1 6014 else 6015 let nextline_is_empty = 0 6016 endif 6017 6018 if prevline_is_empty == 1 && nextline_is_empty == 1 6019 " We are to insert transition element 6020 if &tw > 50 6021 let trans_len = &tw/3 6022 else 6023 let trans_len = 20 6024 endif 6025 if curline =~ '^\s*$' 6026 " Current line consists of only white characters. Try to find last 6027 " used transition 6028 let last_trans_line = search('\n\s*\n\s*'.s:vst_headdef.'\s*\n\s*\n' , 'bWn') + 2 6029 if last_trans_line == 2 6030 let character = '-' 6031 else 6032 let character = matchstr(getline(last_trans_line), '^\s*\zs.\ze') 6033 endif 6034 endif 6035 return repeat(character, trans_len) 6036 elseif prevline_is_empty == 0 && nextline_is_empty == 1 6037 " Insert single ornament 6038 let prevline_len = len(prevline) 6039 if curline =~ '^\s*$' 6040 " Current line consists of only white characters. Try to find last 6041 " single ornament section 6042 let last_single_ornament = search('\(\%^\|\n\s*\n\|\%^\s*\n\).\{-}\n\s*'.s:vst_headdef.'\s*\n\s*\n' , 'bWn') + 3 6043 if last_single_ornament == 4 && getline(1) =~ '^\s*$' && getline(2) =~ '^\s*$' 6044 let last_single_ornament = 4 6045 elseif last_single_ornament == 4 && getline(1) =~ '^\s*$' 6046 let last_single_ornament = 3 6047 let real3 = 1 6048 elseif last_single_ornament == 4 6049 let last_single_ornament = 2 6050 endif 6051 if last_single_ornament == 3 6052 if !exists('real3') 6053 let character = '-' 6054 else 6055 let character = matchstr(getline(last_single_ornament), '^\s*\zs.\ze') 6056 unlet! real3 6057 endif 6058 else 6059 let character = matchstr(getline(last_single_ornament), '^\s*\zs.\ze') 6060 endif 6061 endif 6062 if prevline_len < 3 6063 let ornament_len = 3 - len(curline) 6064 else 6065 let ornament_len = prevline_len - len(curline) 6066 endif 6067 return repeat(character, ornament_len)."\n" 6068 elseif prevline_is_empty == 1 && nextline_is_empty == 0 6069 " Insert double ornament 6070 let nextline_len = len(nextline) 6071 " Unfortunately this line borks undo history 6072 normal! 2"_dd 6073 if curline =~ '^\s*$' 6074 " Current line consists of only white characters. Try to find last 6075 " used ornament 6076 let last_double_ornament = search('\(\%^\|\n\s*\n\|\%^\s*\n\)\s*'.s:vst_headdef.'\s*\n.\{-}\n\s*\2\s*\n' , 'bWn') + 2 6077 if last_double_ornament == 3 && getline(1) =~ '^\s*$' && getline(2) !~ '^\s*$' 6078 let last_double_ornament = 4 6079 endif 6080 if last_double_ornament == 2 6081 let character = '=' 6082 else 6083 let character = matchstr(getline(last_double_ornament), '^\s*\zs.\ze') 6084 endif 6085 endif 6086 if len(curline) == 0 6087 let correction = 0 6088 else 6089 let correction = 1 6090 endif 6091 if nextline_len < 3 6092 let ornament_len = 3 6093 else 6094 let ornament_len = nextline_len 6095 endif 6096 let ornament = repeat(character, ornament_len) 6097 return ornament."\n".nextline."\n".ornament."\n" 6098 else 6099 return '' 6100 endif 6101 6102 return '' 6103 6103 6104 6104 endfunction … … 6107 6107 " headers 6108 6108 function! VST_RotateOrnaments() 6109 " HEADDEF:6110 let s:vst_headdef = '\(=\{3,}\|+\{3,}\|\*\{3,}\|\^\{3,}\|%\{3,}\|\$\{3,}\|#\{3,}\|@\{3,}\|;\{3,}\|"\{3,}\|\.\{3,}\|,\{3,}\|`\{3,}\|\~\{3,}\|-\{3,}\|!\{3,}\|(\{3,}\|)\{3,}\|:\{3,}\|_\{3,}\|&\{3,}\|}\{3,}\|{\{3,}\||\{3,}\|?\{3,}\|<\{3,}\|>\{3,}\|\\\{3,}\|\[\{3,}\|\]\{3,}\|\/\{3,}\|''\{3,}\)'6111 let s:vst_headchars2 = '\(=\|+\|\*\|\^\|%\|\$\|#\|@\|;\|"\|\.\|,\|`\|\~\|-\|!\|(\|)\|:\|_\|&\|}\|{\||\|?\|<\|>\|\\\|\[\|\]\|\/\|''\)'6112 " Make sure we are in position to perform any actions6113 " This is more general regexp, could match several6114 if getline('.') !~ '^\s*'.s:vst_headdef.'\s*$'6115 return 06116 endif6117 6118 " Get situation: double/single ornament, transition6119 let prevline = getline(line('.')-1)6120 let nextline = getline(line('.')+1)6121 6122 if prevline =~ '^\s*$'6123 let prevline_is_empty = 16124 else6125 let prevline_is_empty = 06126 endif6127 6128 if nextline =~ '^\s*$'6129 let nextline_is_empty = 16130 else6131 let nextline_is_empty = 06132 endif6133 6134 if !exists("g:vst_headers")6135 call input('No knowledge about headers, run :Vst head')6136 return 06137 endif6138 6139 if nextline_is_empty == 1 && prevline_is_empty == 06140 " Single ornament6141 let a = 06142 endif6143 " Make sure we have data about headers. Note: updating of data will be6144 " done manually or updated at the end6109 " HEADDEF: 6110 let s:vst_headdef = '\(=\{3,}\|+\{3,}\|\*\{3,}\|\^\{3,}\|%\{3,}\|\$\{3,}\|#\{3,}\|@\{3,}\|;\{3,}\|"\{3,}\|\.\{3,}\|,\{3,}\|`\{3,}\|\~\{3,}\|-\{3,}\|!\{3,}\|(\{3,}\|)\{3,}\|:\{3,}\|_\{3,}\|&\{3,}\|}\{3,}\|{\{3,}\||\{3,}\|?\{3,}\|<\{3,}\|>\{3,}\|\\\{3,}\|\[\{3,}\|\]\{3,}\|\/\{3,}\|''\{3,}\)' 6111 let s:vst_headchars2 = '\(=\|+\|\*\|\^\|%\|\$\|#\|@\|;\|"\|\.\|,\|`\|\~\|-\|!\|(\|)\|:\|_\|&\|}\|{\||\|?\|<\|>\|\\\|\[\|\]\|\/\|''\)' 6112 " Make sure we are in position to perform any actions 6113 " This is more general regexp, could match several 6114 if getline('.') !~ '^\s*'.s:vst_headdef.'\s*$' 6115 return 0 6116 endif 6117 6118 " Get situation: double/single ornament, transition 6119 let prevline = getline(line('.')-1) 6120 let nextline = getline(line('.')+1) 6121 6122 if prevline =~ '^\s*$' 6123 let prevline_is_empty = 1 6124 else 6125 let prevline_is_empty = 0 6126 endif 6127 6128 if nextline =~ '^\s*$' 6129 let nextline_is_empty = 1 6130 else 6131 let nextline_is_empty = 0 6132 endif 6133 6134 if !exists("g:vst_headers") 6135 call input('No knowledge about headers, run :Vst head') 6136 return 0 6137 endif 6138 6139 if nextline_is_empty == 1 && prevline_is_empty == 0 6140 " Single ornament 6141 let a = 0 6142 endif 6143 " Make sure we have data about headers. Note: updating of data will be 6144 " done manually or updated at the end 6145 6145 endfunction 6146 6146 " }}}
Note: See TracChangeset
for help on using the changeset viewer.
