Created
June 12, 2012 20:30
-
-
Save hail2u/2919942 to your computer and use it in GitHub Desktop.
HTML syntax checker with Nu Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use JSON; | |
use LWP::UserAgent; | |
my $file = shift; | |
my $ua = LWP::UserAgent->new(); | |
my $res = $ua->post("http://validator.w3.org/nu/", | |
Content_type => "form-data", | |
Content => [ | |
out => "json", | |
file => [$file], | |
] | |
); | |
if ($res->is_success) { | |
my $result = from_json($res->decoded_content); | |
my $messages = $result->{messages}; | |
if (scalar(@$messages) > 0) { | |
foreach my $m (@$messages) { | |
if ($m->{type} eq 'error') { | |
print join(":", $file, $m->{lastLine}, $m->{lastColumn}, $m->{message}), "\n"; | |
} | |
} | |
} | |
} else { | |
die $res->status_line; | |
} | |
exit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if exists('current_compiler') | |
finish | |
endif | |
let current_compiler = 'nu-validator' | |
if exists(":CompilerSet") != 2 " older Vim always used :setlocal | |
command -nargs=* CompilerSet setlocal <args> | |
endif | |
let s:cpo_save = &cpo | |
set cpo-=C | |
CompilerSet makeprg=nu-validator.pl\ % | |
CompilerSet errorformat=%f:%l:%c:%m | |
let &cpo = s:cpo_save | |
unlet s:cpo_save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment