Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Embrace HTML5

Closes #10.
  • Loading branch information...
commit bdc8b580b5b583aeb43efb19aac2ab8ce5566dff 1 parent d507e2c
Tim Pope authored August 21, 2011

Showing 1 changed file with 37 additions and 11 deletions. Show diff stats Hide diff stats

  1. 48  plugin/ragtag.vim
48  plugin/ragtag.vim
@@ -35,7 +35,7 @@ endfunction
35 35
 function! s:Init()
36 36
   let b:loaded_ragtag = 1
37 37
   inoremap <silent> <buffer> <SID>xmlversion  <?xml version="1.0" encoding="<C-R>=toupper(<SID>charset())<CR>"?>
38  
-  inoremap      <buffer> <SID>htmltrans   <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  38
+  inoremap      <buffer> <SID>html5       <!DOCTYPE html>
39 39
   inoremap      <buffer> <SID>xhtmltrans  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
40 40
   if s:subtype() == "xml"
41 41
     imap <script> <buffer> <SID>doctype <SID>xmlversion
@@ -44,11 +44,11 @@ function! s:Init()
44 44
   elseif s:subtype() == "xhtml"
45 45
     imap <script> <buffer> <SID>doctype <SID>xhtmltrans
46 46
   else
47  
-    imap <script> <buffer> <SID>doctype <SID>htmltrans
  47
+    imap <script> <buffer> <SID>doctype <SID>html5
48 48
   endif
49 49
   imap <script> <buffer> <C-X>! <SID>doctype
50 50
 
51  
-  imap <silent> <buffer> <C-X># <meta http-equiv="Content-Type" content="text/html; charset=<C-R>=<SID>charset()<CR>"<C-R>=<SID>closetag()<CR>
  51
+  imap <silent> <buffer> <C-X># <C-R>=<SID>charsetTag()<CR>
52 52
   inoremap <silent> <buffer> <SID>HtmlComplete <C-R>=<SID>htmlEn()<CR><C-X><C-O><C-P><C-R>=<SID>htmlDis()<CR><C-N>
53 53
   imap     <buffer> <C-X>H <SID>HtmlComplete
54 54
   inoremap <silent> <buffer> <C-X>$ <C-R>=<SID>javascriptIncludeTag()<CR>
@@ -118,7 +118,7 @@ function! s:Init()
118 118
   elseif &ft == "mason"
119 119
     inoremap <buffer> <C-X>] <%perl><CR></%perl><Esc>O
120 120
   elseif &ft == "html" || &ft == "xhtml" || &ft == "xml"
121  
-    imap     <buffer> <C-X>] <script<Space>type="text/javascript"><CR></script><Esc>O
  121
+    imap     <buffer> <C-X>] <script<C-R>=<SID>javascriptType()<CR>><CR></script><Esc>O
122 122
   else
123 123
     imap     <buffer> <C-X>] <C-X><Lt><CR><C-X>><Esc>O
124 124
   endif
@@ -217,23 +217,39 @@ function! s:doctypeSeek()
217 217
   return (index < 0 ? s:repeat("\<C-P>",-index) : s:repeat("\<C-N>",index))
218 218
 endfunction
219 219
 
  220
+function! s:stylesheetType()
  221
+  if s:subtype() == 'html5'
  222
+    return ''
  223
+  else
  224
+    return ' type="text/css"'
  225
+  endif
  226
+endfunction
  227
+
220 228
 function! s:stylesheetTag()
221 229
   if !exists("b:ragtag_stylesheet_link_tag")
222 230
     if exists("b:allml_stylesheet_link_tag")
223 231
       let b:ragtag_stylesheet_link_tag = b:allml_stylesheet_link_tag
224 232
     else
225  
-      let b:ragtag_stylesheet_link_tag = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/stylesheets/\r.css\" />"
  233
+      let b:ragtag_stylesheet_link_tag = '<link rel="stylesheet"'.s:stylesheetType()." href=\"/stylesheets/\r.css\" />"
226 234
     endif
227 235
   endif
228 236
   return s:insertTag(b:ragtag_stylesheet_link_tag)
229 237
 endfunction
230 238
 
  239
+function! s:javascriptType()
  240
+  if s:subtype() == 'html5'
  241
+    return ''
  242
+  else
  243
+    return ' type="text/javascript"'
  244
+  endif
  245
+endfunction
  246
+
231 247
 function! s:javascriptIncludeTag()
232 248
   if !exists("b:ragtag_javascript_include_tag")
233 249
     if exists("b:allml_javascript_include_tag")
234 250
       let b:ragtag_javascript_include_tag = b:allml_javascript_include_tag
235 251
     else
236  
-      let b:ragtag_javascript_include_tag = "<script type=\"text/javascript\" src=\"/javascripts/\r.js\"></script>"
  252
+      let b:ragtag_javascript_include_tag = '<script'.s:javascriptType()." src=\"/javascripts/\r.js\"></script>"
237 253
     endif
238 254
   endif
239 255
   return s:insertTag(b:ragtag_javascript_include_tag)
@@ -278,12 +294,14 @@ function! s:subtype()
278 294
     return "xml"
279 295
   elseif top =~? '\<xhtml\>'
280 296
     return 'xhtml'
281  
-  elseif top =~ '[^<]\<html\>'
  297
+  elseif top =~? '<!DOCTYPE html>'
  298
+    return 'html5'
  299
+  elseif top =~? '[^<]\<html\>'
282 300
     return "html"
283  
-  elseif &ft == "xhtml" || &ft == '\<eruby\>'
  301
+  elseif &ft == "xhtml"
284 302
     return "xhtml"
285 303
   elseif exists("b:loaded_ragtag")
286  
-    return "html"
  304
+    return "html5"
287 305
   else
288 306
     return ""
289 307
   endif
@@ -319,6 +337,14 @@ function! s:charset()
319 337
   endif
320 338
 endfunction
321 339
 
  340
+function! s:charsetTag()
  341
+  if s:subtype() == 'html5'
  342
+    return '<meta charset="'.s:charset().'"'.s:closetag()
  343
+  else
  344
+    return '<meta http-equiv="Content-Type" content="text/html; charset='.s:charset().'"'.s:closetag()
  345
+  endif
  346
+endfunction
  347
+
322 348
 function! s:tagextras()
323 349
   if s:subtype() == "xml"
324 350
     return ""
@@ -329,9 +355,9 @@ function! s:tagextras()
329 355
     endif
330 356
     return ' xmlns="http://www.w3.org/1999/xhtml" lang="'.lang.'" xml:lang="'.lang.'"'
331 357
   elseif @" == 'style'
332  
-    return ' type="text/css"'
  358
+    return s:stylesheetType()
333 359
   elseif @" == 'script'
334  
-    return ' type="text/javascript"'
  360
+    return s:javascriptType()
335 361
   elseif @" == 'table'
336 362
     return ' cellspacing="0"'
337 363
   else

0 notes on commit bdc8b58

Please sign in to comment.
Something went wrong with that request. Please try again.