Skip to content

Commit

Permalink
Item8143: add support for DOCTYPE
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/SafeWikiPlugin@3736 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Apr 28, 2009
1 parent b063939 commit 7ad5ca1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
73 changes: 73 additions & 0 deletions lib/Foswiki/Plugins/SafeWikiPlugin/Declaration.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# See bottom of file for notices

=pod
---+ package Foswiki::Plugins::SafeWikiPlugin::Declaration
A declaration node in an HTML parse tree
=cut

package Foswiki::Plugins::SafeWikiPlugin::Declaration;

use strict;
use Assert;

sub new {
my( $class, $text ) = @_;

my $this = { text => $text };
$this->{children} = [];
return bless( $this, $class );
}

# debug generate the parse tree as HTML
sub stringify {
my( $this ) = @_;
my $r = $this->{text};
foreach my $kid ( @{$this->{children}} ) {
$r .= $kid->stringify();
}
return $r;
}

sub isLeaf {
return 0;
}

# Called by the parser
sub addChild {
my( $this, $node ) = @_;
push( @{$this->{children}}, $node );
}

# generate the parse tree, applying filters
sub generate {
my ($this, $filterURI, $filterHandler) = @_;
my $text = $this->{text};
foreach my $kid ( @{$this->{children}} ) {
$text .= $kid->generate($filterURI, $filterHandler);
}
return $text;
}

1;
__DATA__
Copyright (C) 2007-2008 C-Dot Consultants http://c-dot.co.uk
All rights reserved
Author: Crawford Currie
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details, published at
http://www.gnu.org/copyleft/gpl.html
This notice must be retained in all copies or derivatives of this
code.
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/SafeWikiPlugin/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pub/System/SafeWikiPlugin/safewiki.png 0644
lib/Foswiki/Plugins/SafeWikiPlugin.pm 0644 Perl module
lib/Foswiki/Plugins/SafeWikiPlugin/Config.spec 0444 Configuration parameters
lib/Foswiki/Plugins/SafeWikiPlugin/Parser.pm 0644 Perl module
lib/Foswiki/Plugins/SafeWikiPlugin/Declaration.pm 0644 Perl module
lib/Foswiki/Plugins/SafeWikiPlugin/Node.pm 0644 Perl module
lib/Foswiki/Plugins/SafeWikiPlugin/Leaf.pm 0644 Perl module
20 changes: 16 additions & 4 deletions lib/Foswiki/Plugins/SafeWikiPlugin/Parser.pm
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# See bottom of file for notices

package Foswiki::Plugins::SafeWikiPlugin::Parser;
use base 'HTML::Parser';
use HTML::Parser;

@Foswiki::Plugins::SafeWikiPlugin::Parser::ISA = ( 'HTML::Parser' );

use strict;

require Foswiki::Plugins::SafeWikiPlugin::Node;
require Foswiki::Plugins::SafeWikiPlugin::Leaf;
use Foswiki::Plugins::SafeWikiPlugin::Node ();
use Foswiki::Plugins::SafeWikiPlugin::Leaf ();
use Foswiki::Plugins::SafeWikiPlugin::Declaration ();

sub new {
my ($class) = @_;

my $this = $class->SUPER::new(
start_h => [\&_openTag, 'self,tagname,attr' ],
end_h => [\&_closeTag, 'self,tagname'],
declaration_h => [\&_ignore, 'self'],
declaration_h => [\&_declaration, 'self,text'],
default_h => [\&_text, 'self,text'],
comment_h => [\&_comment, 'self,text'] );
$this->empty_element_tags(1);
Expand Down Expand Up @@ -87,6 +90,15 @@ sub _closeTag {
$this->_apply( $tag );
}

sub _declaration {
my( $this, $text ) = @_;
my $l = new Foswiki::Plugins::SafeWikiPlugin::Declaration($text);
if (defined $this->{stackTop}) {
$l->addChild( $this->{stackTop} );
}
$this->{stackTop} = $l;
}

sub _text {
my( $this, $text ) = @_;
return unless length($text);
Expand Down

0 comments on commit 7ad5ca1

Please sign in to comment.