w3.vim 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "============================================================================
  2. "File: w3.vim
  3. "Description: Syntax checking plugin for syntastic
  4. "Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_html_w3_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_html_w3_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. " Constants {{{1
  19. let s:DEFAULTS = {
  20. \ 'html': {
  21. \ 'ctype': 'text/html',
  22. \ 'doctype': 'HTML5' },
  23. \ 'svg': {
  24. \ 'ctype': 'image/svg+xml',
  25. \ 'doctype': 'SVG 1.1' },
  26. \ 'xhtml': {
  27. \ 'ctype': 'application/xhtml+xml',
  28. \ 'doctype': 'XHTML 1.1' } }
  29. " }}}1
  30. " @vimlint(EVL101, 1, l:ctype)
  31. " @vimlint(EVL101, 1, l:doctype)
  32. function! SyntaxCheckers_html_w3_GetLocList() dict " {{{1
  33. let buf = bufnr('')
  34. let type = self.getFiletype()
  35. let fname = syntastic#util#shescape(fnamemodify(bufname(buf), ':p'))
  36. let api = syntastic#util#var(type . '_w3_api', 'https://validator.w3.org/check')
  37. for key in keys(s:DEFAULTS[type])
  38. let l:{key} = syntastic#util#var(type . '_w3_' . key, get(s:DEFAULTS[type], key))
  39. endfor
  40. " vint: -ProhibitUsingUndeclaredVariable
  41. let makeprg = self.getExecEscaped() . ' -q -L -s --compressed -F output=json' .
  42. \ (doctype !=# '' ? ' -F doctype=' . syntastic#util#shescape(doctype) : '') .
  43. \ ' -F uploaded_file=@' . fname .
  44. \ '\;type=' . ctype .
  45. \ '\;filename=' . fname .
  46. \ ' ' . api
  47. " vint: ProhibitUsingUndeclaredVariable
  48. let errorformat =
  49. \ '%A %\+{,' .
  50. \ '%C %\+"lastLine": %l\,%\?,' .
  51. \ '%C %\+"lastColumn": %c\,%\?,' .
  52. \ '%C %\+"message": "%m"\,%\?,' .
  53. \ '%C %\+"type": "%trror"\,%\?,' .
  54. \ '%-G %\+"type": "%tnfo"\,%\?,' .
  55. \ '%C %\+"subtype": "%tarning"\,%\?,' .
  56. \ '%Z %\+}\,,' .
  57. \ '%-G%.%#'
  58. let loclist = SyntasticMake({
  59. \ 'makeprg': makeprg,
  60. \ 'errorformat': errorformat,
  61. \ 'defaults': {'bufnr': bufnr('')},
  62. \ 'returns': [0] })
  63. for e in loclist
  64. let e['text'] = substitute(e['text'], '\m\\\([\"]\)', '\1', 'g')
  65. endfor
  66. return loclist
  67. endfunction " }}}1
  68. " @vimlint(EVL104, 0, l:doctype)
  69. " @vimlint(EVL101, 0, l:ctype)
  70. call g:SyntasticRegistry.CreateAndRegisterChecker({
  71. \ 'filetype': 'html',
  72. \ 'name': 'w3',
  73. \ 'exec': 'curl' })
  74. let &cpo = s:save_cpo
  75. unlet s:save_cpo
  76. " vim: set sw=4 sts=4 et fdm=marker: