Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created June 12, 2012 20:30
Show Gist options
  • Save hail2u/2919942 to your computer and use it in GitHub Desktop.
Save hail2u/2919942 to your computer and use it in GitHub Desktop.
HTML syntax checker with Nu Validator
#!/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;
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