Permalink
Browse files

work in progress

  • Loading branch information...
1 parent 8824990 commit cfd80f9f2008e6ec5cddb2b33f06b401323557da @petdance committed Mar 29, 2012
Showing with 71 additions and 8 deletions.
  1. +65 −4 lib/HTML/Lint.pm
  2. +6 −4 lib/HTML/Lint/Error.pm
View
@@ -77,7 +77,8 @@ sub new {
my $self = {
_errors => [],
- _types => [],
+ _types => [],
+ _flags => {},
};
$self->{_parser} = HTML::Lint::Parser->new( sub { $self->gripe( @_ ) } );
bless $self, $class;
@@ -177,6 +178,18 @@ sub clear_errors {
return;
}
+=head2 $lint->set_flags( $which, $what )
+
+=cut
+
+sub set_flags {
+ my $self = shift;
+ my $which = shift;
+ my $what = shift;
+
+ return;
+}
+
=head2 $lint->only_types( $type1[, $type2...] )
Specifies to only want errors of a certain type.
@@ -289,6 +302,7 @@ sub new {
end_document_h => [ \&_end_document, 'self,line,column' ],
start_h => [ \&_start, 'self,tagname,line,column,@attr' ],
end_h => [ \&_end, 'self,tagname,line,column,tokenpos,@attr' ],
+ comment_h => [ \&_comment, 'self,tagname,line,column,text' ],
text_h => [ \&_text, 'self,text' ],
strict_names => 0,
empty_element_tags => 1,
@@ -384,6 +398,53 @@ sub _text {
return;
}
+sub _comment {
+ my ($self,$tagname,$line,$column,$text) = @_;
+
+ if ( $tagname =~ m/^\s*html-lint\s*(.+)\s*$/ ) {
+ my $text = $1;
+
+ my @commands = split( /\s*,\s*/, $text );
+
+ for my $command ( @commands ) {
+ print "command=[$command]\n";
+ my ($which,$what) = split( /\s*:\s*/, $command, 2 );
+ _trim($_) for ($which,$what);
+ print "which,what=[$which][$what]\n";
+
+ my ($val,$msg) = _translate_what( $what );
+
+ if ($msg) {
+ $self->gripe( 'config-unknown-setting', setting => $what,
+ where => HTML::Lint::Error::where($line,$column) );
+ next;
+ }
+
+ $self->{_flags}{$which} = $val;
+ }
+ }
+
+ return;
+}
+
+sub _translate_what {
+ my $what = shift;
+
+ print "[$what]\n";
+
+ $what = _trim( $what );
+ return (1,undef) if $what =~ /^(?:1|on|true)$/;
+ return (0,undef) if $what =~ /^(?:0|off|false)$/;
+ return (undef,qq{Unknown status "$what"});
+}
+
+sub _trim {
+ $_[0] =~ s/^\s+//;
+ $_[0] =~ s/\s+$//;
+
+ return $_[0];
+}
+
sub _end {
my ($self,$tag,$line,$column,$tokenpos,@attr) = @_;
@@ -516,10 +577,10 @@ DO NOT send bug reports to http://rt.cpan.org/ or http://code.google.com/
=head1 COPYRIGHT & LICENSE
-Copyright 2005-2011 Andy Lester.
+Copyright 2005-2012 Andy Lester.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the Artistic License v2.0.
+This program is free software; you can redistribute it and/or modify it
+under the terms of the Artistic License v2.0.
http://www.opensource.org/licenses/Artistic-2.0
@@ -55,9 +55,10 @@ This is usually something like an unknown attribute on a tag.
=cut
-use constant STRUCTURE => 1;
-use constant HELPER => 2;
-use constant FLUFF => 3;
+use constant CONFIG => 1;
+use constant STRUCTURE => 2;
+use constant HELPER => 3;
+use constant FLUFF => 4;
=head2 new()
@@ -227,7 +228,7 @@ None, other than incorporating more errors, as driven by HTML::Lint.
=head1 COPYRIGHT & LICENSE
-Copyright 2005-2011 Andy Lester.
+Copyright 2005-2012 Andy Lester.
This program is free software; you can redistribute it and/or modify it
under the terms of the Artistic License v2.0.
@@ -245,6 +246,7 @@ Andy Lester, C<andy at petdance.com>
# Generic element stuff
%errors = (
+ 'config-unknown-setting' => ['Unknown setting "${setting}"', CONFIG],
'elem-unknown' => ['Unknown element <${tag}>', STRUCTURE],
'elem-unopened' => ['</${tag}> with no opening <${tag}>', STRUCTURE],
'elem-unclosed' => ['<${tag}> at ${where} is never closed', STRUCTURE],

0 comments on commit cfd80f9

Please sign in to comment.