PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/LinqDlrTests/testenv/perl/site/lib/html/Filter.pm

#
Perl | 109 lines | 79 code | 30 blank | 0 comment | 3 complexity | 0cb03e139906a15722ea99dbc5130d56 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. package HTML::Filter;
  2. require HTML::Parser;
  3. @ISA=qw(HTML::Parser);
  4. $VERSION = sprintf("%d.%02d", q$Revision: 2.9 $ =~ /(\d+)\.(\d+)/);
  5. sub declaration { $_[0]->output("<!$_[1]>") }
  6. sub process { $_[0]->output($_[2]) }
  7. sub comment { $_[0]->output("<!--$_[1]-->") }
  8. sub start { $_[0]->output($_[4]) }
  9. sub end { $_[0]->output($_[2]) }
  10. sub text { $_[0]->output($_[1]) }
  11. sub output { print $_[1] }
  12. 1;
  13. __END__
  14. =head1 NAME
  15. HTML::Filter - Filter HTML text through the parser
  16. =head1 NOTE
  17. This module is deprecated. C<HTML::Parser> now provides the
  18. functionally of C<HTML::Filter> much more efficiently with the the
  19. C<default> handler.
  20. =head1 SYNOPSIS
  21. require HTML::Filter;
  22. $p = HTML::Filter->new->parse_file("index.html");
  23. =head1 DESCRIPTION
  24. C<HTML::Filter> is an HTML parser that by default prints the
  25. original text of each HTML element (a slow version of cat(1) basically).
  26. The callback methods may be overridden to modify the filtering for some
  27. HTML elements and you can override output() method which is called to
  28. print the HTML text.
  29. C<HTML::Filter> is a subclass of C<HTML::Parser>. This means that
  30. the document should be given to the parser by calling the $p->parse()
  31. or $p->parse_file() methods.
  32. =head1 EXAMPLES
  33. The first example is a filter that will remove all comments from an
  34. HTML file. This is achieved by simply overriding the comment method
  35. to do nothing.
  36. package CommentStripper;
  37. require HTML::Filter;
  38. @ISA=qw(HTML::Filter);
  39. sub comment { } # ignore comments
  40. The second example shows a filter that will remove any E<lt>TABLE>s
  41. found in the HTML file. We specialize the start() and end() methods
  42. to count table tags and then make output not happen when inside a
  43. table.
  44. package TableStripper;
  45. require HTML::Filter;
  46. @ISA=qw(HTML::Filter);
  47. sub start
  48. {
  49. my $self = shift;
  50. $self->{table_seen}++ if $_[0] eq "table";
  51. $self->SUPER::start(@_);
  52. }
  53. sub end
  54. {
  55. my $self = shift;
  56. $self->SUPER::end(@_);
  57. $self->{table_seen}-- if $_[0] eq "table";
  58. }
  59. sub output
  60. {
  61. my $self = shift;
  62. unless ($self->{table_seen}) {
  63. $self->SUPER::output(@_);
  64. }
  65. }
  66. If you want to collect the parsed text internally you might want to do
  67. something like this:
  68. package FilterIntoString;
  69. require HTML::Filter;
  70. @ISA=qw(HTML::Filter);
  71. sub output { push(@{$_[0]->{fhtml}}, $_[1]) }
  72. sub filtered_html { join("", @{$_[0]->{fhtml}}) }
  73. =head1 SEE ALSO
  74. L<HTML::Parser>
  75. =head1 COPYRIGHT
  76. Copyright 1997-1999 Gisle Aas.
  77. This library is free software; you can redistribute it and/or
  78. modify it under the same terms as Perl itself.
  79. =cut