Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 83a7a2a

Browse files
committed
Checker html/w3: Add support for SVG and XHTML
Apply the same changes that were applied to html/validator in #2241 to w3/html so that it can be used to validate SVG and XHTML as well. Add support for `g:syntastic_{type}_w3_doctype` to control the doctype POST parameter sent to the validator. This is necessary for SVG without a DTD (which would otherwise be validated as generic XML) and useful for all the types to control validation. Signed-off-by: Kevin Locke <[email protected]>
1 parent 1cbf03a commit 83a7a2a

File tree

4 files changed

+272
-15
lines changed

4 files changed

+272
-15
lines changed

doc/syntastic-checkers.txt

Lines changed: 180 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,7 +3175,7 @@ details:
31753175
https://validator.w3.org/source/
31763176

31773177
As a syntastic linter, you can validate your files against the online service
3178-
(see http://validator.w3.org/), or you can install it from sources and run it
3178+
(see https://validator.w3.org/), or you can install it from sources and run it
31793179
as a local service:
31803180

31813181
https://github.com/w3c/markup-validator/
@@ -3184,17 +3184,37 @@ Requirement~
31843184

31853185
This checker uses cURL:
31863186

3187-
http://curl.haxx.se/
3187+
https://curl.haxx.se/
31883188

31893189
Checker options~
31903190

31913191
*'g:syntastic_html_w3_api'*
31923192
Type: string
3193-
Default: "http://validator.w3.org/check"
3193+
Default: "https://validator.w3.org/check"
31943194
URL of the service to use for checking. Leave it to the default to
3195-
run the checks against "http://validator.w3.org/", or set it to
3195+
run the checks against "https://validator.w3.org/", or set it to
31963196
"http://localhost/w3c-validator/check" if you're running a local service.
31973197

3198+
*'g:syntastic_html_w3_doctype'*
3199+
Type: string
3200+
Default: ""
3201+
Name of the document type definition to use for checking. If unspecified, the
3202+
type is detected from the file content. Currently supported values for HTML:
3203+
3204+
- HTML5
3205+
- HTML 4.01 Strict
3206+
- HTML 4.01 Transitional
3207+
- HTML 4.01 Frameset
3208+
- HTML 4.01 + RDFa 1.1
3209+
- HTML 3.2
3210+
- HTML 2.0
3211+
- ISO/IEC 15445:2000 ("ISO HTML")
3212+
3213+
References:
3214+
3215+
https://github.com/w3c/markup-validator/blob/master/htdocs/doctype-select.html
3216+
https://github.com/w3c/markup-validator/blob/master/htdocs/config/types.conf
3217+
31983218
*'g:syntastic_html_w3_exec'*
31993219
Type: string
32003220
Default: "curl"
@@ -3210,11 +3230,13 @@ Note~
32103230

32113231
Non-zero exit codes from "cURL" are typically network errors, and are signaled
32123232
by syntastic with messages such as: >
3213-
syntastic: error: checker html/validator returned abnormal status 26
3233+
syntastic: error: checker html/w3 returned abnormal status 26
32143234
<
32153235
You can lookup the meaning of these codes in cURL's manual:
32163236

3217-
http://curl.haxx.se/docs/manpage.html#EXIT
3237+
https://curl.haxx.se/docs/manpage.html#EXIT
3238+
3239+
See also: |syntastic-svg-w3|, |syntastic-xhtml-w3|.
32183240

32193241
==============================================================================
32203242
SYNTAX CHECKERS FOR JAVA *syntastic-checkers-java*
@@ -6579,6 +6601,7 @@ SYNTAX CHECKERS FOR SVG *syntastic-checkers-svg*
65796601
The following checkers are available for SVG (filetype "svg"):
65806602

65816603
1. Validator................|syntastic-svg-validator|
6604+
2. W3.......................|syntastic-svg-w3|
65826605

65836606
------------------------------------------------------------------------------
65846607
1. Validator *syntastic-svg-validator*
@@ -6670,6 +6693,78 @@ Example~
66706693
<
66716694
See also: |syntastic-html-validator|, |syntastic-xhtml-validator|.
66726695

6696+
------------------------------------------------------------------------------
6697+
2. W3 *syntastic-svg-w3*
6698+
6699+
Name: w3
6700+
Maintainer: Martin Grenfell <[email protected]>
6701+
6702+
"W3" is the W3C Markup Validator for SVG. See the project's page for
6703+
details:
6704+
6705+
https://validator.w3.org/source/
6706+
6707+
As a syntastic linter, you can validate your files against the online service
6708+
(see https://validator.w3.org/), or you can install it from sources and run it
6709+
as a local service:
6710+
6711+
https://github.com/w3c/markup-validator/
6712+
6713+
Requirement~
6714+
6715+
This checker uses cURL:
6716+
6717+
http://curl.haxx.se/
6718+
6719+
Checker options~
6720+
6721+
*'g:syntastic_svg_w3_api'*
6722+
Type: string
6723+
Default: "https://validator.w3.org/check"
6724+
URL of the service to use for checking. Leave it to the default to
6725+
run the checks against "https://validator.w3.org/", or set it to
6726+
"http://localhost/w3c-validator/check" if you're running a local service.
6727+
6728+
*'g:syntastic_svg_w3_doctype'*
6729+
Type: string
6730+
Default: "SVG 1.1" (if not detected from DTD)
6731+
Name of the document type definition to use for checking. If unspecified, the
6732+
type is detected from a Document Type Declaration, if present, or "SVG 1.1" is
6733+
used. Currently supported values for SVG:
6734+
6735+
- SVG 1.0
6736+
- SVG 1.1
6737+
- SVG 1.1 Tiny
6738+
- SVG 1.1 Basic
6739+
6740+
References:
6741+
6742+
https://github.com/w3c/markup-validator/blob/master/htdocs/doctype-select.html
6743+
https://github.com/w3c/markup-validator/blob/master/htdocs/config/types.conf
6744+
6745+
*'g:syntastic_svg_w3_exec'*
6746+
Type: string
6747+
Default: "curl"
6748+
Path to the "cURL" executable. Override it with a full path if your "cURL" is
6749+
not installed in a standard location.
6750+
6751+
This checker doesn't call the "makeprgBuild()" function, and thus it ignores
6752+
the usual 'g:syntastic_svg_w3_<option>' variables. The only exception is
6753+
'g:syntastic_svg_w3_exec', which can be used to override the path to the
6754+
"cURL" executable.
6755+
6756+
Note~
6757+
6758+
Non-zero exit codes from "cURL" are typically network errors, and are signaled
6759+
by syntastic with messages such as: >
6760+
syntastic: error: checker svg/w3 returned abnormal status 26
6761+
<
6762+
You can lookup the meaning of these codes in cURL's manual:
6763+
6764+
http://curl.haxx.se/docs/manpage.svg#EXIT
6765+
6766+
See also: |syntastic-html-w3|, |syntastic-xhtml-w3|.
6767+
66736768
==============================================================================
66746769
SYNTAX CHECKERS FOR TCL *syntastic-checkers-tcl*
66756770

@@ -7483,6 +7578,7 @@ The following checkers are available for xHTML (filetype "xhtml"):
74837578
2. jshint...................|syntastic-xhtml-jshint|
74847579
3. proselint................|syntastic-xhtml-proselint|
74857580
4. Validator................|syntastic-xhtml-validator|
7581+
5. W3.......................|syntastic-xhtml-w3|
74867582

74877583
------------------------------------------------------------------------------
74887584
1. HTML tidy *syntastic-xhtml-tidy*
@@ -7668,6 +7764,84 @@ Example~
76687764
<
76697765
See also: |syntastic-html-validator|, |syntastic-svg-validator|.
76707766

7767+
------------------------------------------------------------------------------
7768+
5. W3 *syntastic-xhtml-w3*
7769+
7770+
Name: w3
7771+
Maintainer: Martin Grenfell <[email protected]>
7772+
7773+
"W3" is the W3C Markup Validator for XHTML. See the project's page for
7774+
details:
7775+
7776+
https://validator.w3.org/source/
7777+
7778+
As a syntastic linter, you can validate your files against the online service
7779+
(see https://validator.w3.org/), or you can install it from sources and run it
7780+
as a local service:
7781+
7782+
https://github.com/w3c/markup-validator/
7783+
7784+
Requirement~
7785+
7786+
This checker uses cURL:
7787+
7788+
https://curl.haxx.se/
7789+
7790+
Checker options~
7791+
7792+
*'g:syntastic_xhtml_w3_api'*
7793+
Type: string
7794+
Default: "https://validator.w3.org/check"
7795+
URL of the service to use for checking. Leave it to the default to
7796+
run the checks against "https://validator.w3.org/", or set it to
7797+
"http://localhost/w3c-validator/check" if you're running a local service.
7798+
7799+
*'g:syntastic_xhtml_w3_doctype'*
7800+
Type: string
7801+
Default: ""
7802+
Name of the document type definition to use for checking. If unspecified, the
7803+
type is detected from the file content. Currently supported values for XHTML:
7804+
7805+
- XHTML 1.0 Strict
7806+
- XHTML 1.0 Transitional
7807+
- XHTML 1.0 Frameset
7808+
- XHTML 1.1
7809+
- XHTML + RDFa
7810+
- XHTML Basic 1.0
7811+
- XHTML Basic 1.1
7812+
- XHTML Mobile Profile 1.2
7813+
- XHTML-Print 1.0
7814+
- XHTML 1.1 plus MathML 2.0
7815+
- XHTML 1.1 plus MathML 2.0 plus SVG 1.1
7816+
7817+
References:
7818+
7819+
https://github.com/w3c/markup-validator/blob/master/htdocs/doctype-select.html
7820+
https://github.com/w3c/markup-validator/blob/master/htdocs/config/types.conf
7821+
7822+
*'g:syntastic_xhtml_w3_exec'*
7823+
Type: string
7824+
Default: "curl"
7825+
Path to the "cURL" executable. Override it with a full path if your "cURL" is
7826+
not installed in a standard location.
7827+
7828+
This checker doesn't call the "makeprgBuild()" function, and thus it ignores
7829+
the usual 'g:syntastic_xhtml_w3_<option>' variables. The only exception is
7830+
'g:syntastic_xhtml_w3_exec', which can be used to override the path to the
7831+
"cURL" executable.
7832+
7833+
Note~
7834+
7835+
Non-zero exit codes from "cURL" are typically network errors, and are signaled
7836+
by syntastic with messages such as: >
7837+
syntastic: error: checker xhtml/w3 returned abnormal status 26
7838+
<
7839+
You can lookup the meaning of these codes in cURL's manual:
7840+
7841+
https://curl.haxx.se/docs/manpage.xhtml#EXIT
7842+
7843+
See also: |syntastic-html-w3|, |syntastic-svg-w3|.
7844+
76717845
==============================================================================
76727846
SYNTAX CHECKERS FOR XML *syntastic-checkers-xml*
76737847

syntax_checkers/html/w3.vim

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,52 @@ if exists('g:loaded_syntastic_html_w3_checker')
1515
endif
1616
let g:loaded_syntastic_html_w3_checker = 1
1717

18-
if !exists('g:syntastic_html_w3_api')
19-
let g:syntastic_html_w3_api = 'http://validator.w3.org/check'
20-
endif
21-
2218
let s:save_cpo = &cpo
2319
set cpo&vim
2420

25-
function! SyntaxCheckers_html_w3_GetLocList() dict
21+
" Constants {{{1
22+
23+
let s:DEFAULTS = {
24+
\ 'api': 'https://validator.w3.org/check',
25+
\ 'doctype': '' }
26+
27+
let s:CONTENT_TYPE = {
28+
\ 'html': 'text/html',
29+
\ 'svg': 'image/svg+xml',
30+
\ 'xhtml': 'application/xhtml+xml' }
31+
32+
" }}}1
33+
34+
" @vimlint(EVL101, 1, l:api)
35+
" @vimlint(EVL101, 1, l:doctype)
36+
" @vimlint(EVL104, 1, l:doctype)
37+
function! SyntaxCheckers_html_w3_GetLocList() dict " {{{1
2638
let buf = bufnr('')
27-
let makeprg = self.getExecEscaped() . ' -q -L -s -F output=json ' .
28-
\ '-F uploaded_file=@' . syntastic#util#shescape(fnamemodify(bufname(buf), ':p')) . '\;type=text/html ' .
29-
\ g:syntastic_html_w3_api
39+
let type = self.getFiletype()
40+
let fname = syntastic#util#shescape(fnamemodify(bufname(buf), ':p'))
41+
42+
for key in keys(s:DEFAULTS)
43+
let l:{key} = syntastic#util#var(type . '_w3_' . key, get(s:DEFAULTS, key))
44+
endfor
45+
let ctype = get(s:CONTENT_TYPE, type, '')
46+
47+
" SVG is detected as generic XML if doctype is unspecified.
48+
" Default "SVG 1.1" with "Only if missing" (fbd=1) to use DTD if present.
49+
let fbd = ''
50+
if type ==# 'svg' && doctype ==# ''
51+
let doctype = 'SVG 1.1'
52+
let fbd = '1'
53+
endif
54+
55+
" vint: -ProhibitUsingUndeclaredVariable
56+
let makeprg = self.getExecEscaped() . ' -q -L -s --compressed -F output=json' .
57+
\ (doctype !=# '' ? ' -F doctype=' . syntastic#util#shescape(doctype) : '') .
58+
\ (fbd !=# '' ? ' -F fbd=' . fbd : '') .
59+
\ ' -F uploaded_file=@' . fname .
60+
\ (ctype !=# '' ? '\;type=' . ctype : '') .
61+
\ '\;filename=' . fname .
62+
\ ' ' . api
63+
" vint: ProhibitUsingUndeclaredVariable
3064

3165
let errorformat =
3266
\ '%A %\+{,' .
@@ -50,7 +84,10 @@ function! SyntaxCheckers_html_w3_GetLocList() dict
5084
endfor
5185

5286
return loclist
53-
endfunction
87+
endfunction " }}}1
88+
" @vimlint(EVL104, 0, l:doctype)
89+
" @vimlint(EVL101, 0, l:doctype)
90+
" @vimlint(EVL101, 0, l:api)
5491

5592
call g:SyntasticRegistry.CreateAndRegisterChecker({
5693
\ 'filetype': 'html',

syntax_checkers/svg/w3.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"============================================================================
2+
"File: w3.vim
3+
"Description: Syntax checking plugin for syntastic
4+
"Maintainer: Kevin Locke <[email protected]>
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+
13+
if exists('g:loaded_syntastic_svg_w3_checker')
14+
finish
15+
endif
16+
let g:loaded_syntastic_svg_w3_checker = 1
17+
18+
call g:SyntasticRegistry.CreateAndRegisterChecker({
19+
\ 'filetype': 'svg',
20+
\ 'name': 'w3',
21+
\ 'redirect': 'html/w3'})
22+
23+
" vim: set sw=4 sts=4 et fdm=marker:

syntax_checkers/xhtml/w3.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"============================================================================
2+
"File: w3.vim
3+
"Description: Syntax checking plugin for syntastic
4+
"Maintainer: Kevin Locke <[email protected]>
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+
13+
if exists('g:loaded_syntastic_xhtml_w3_checker')
14+
finish
15+
endif
16+
let g:loaded_syntastic_xhtml_w3_checker = 1
17+
18+
call g:SyntasticRegistry.CreateAndRegisterChecker({
19+
\ 'filetype': 'xhtml',
20+
\ 'name': 'w3',
21+
\ 'redirect': 'html/w3'})
22+
23+
" vim: set sw=4 sts=4 et fdm=marker:

0 commit comments

Comments
 (0)