Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
TODO | ||
project.vim | ||
dist.ini | ||
^XML-XSS.* | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env perl | ||
|
||
package XML::XSS::xss; | ||
#ABSTRACT: command-line XML::XSS processor | ||
|
||
use Getopt::Long; | ||
|
||
GetOptions( | ||
'script=s' => \my $script, | ||
'm=s' => \my $module, | ||
'stylesheet=s' => \my $stylesheet, | ||
); | ||
|
||
my $document = join '', <>; | ||
|
||
my $xss; | ||
|
||
if( $stylesheet ) { | ||
my $class = "XML::XSS::Stylesheet::$stylesheet"; | ||
eval "use $class"; | ||
die $@ if $@; | ||
|
||
$xss = $class->new; | ||
} | ||
elsif ( $script ) { | ||
$xss = do $script; | ||
} | ||
elsif( $module ) { | ||
eval "use $module"; | ||
$xss = $module->new; | ||
} | ||
|
||
print $xss->render( $document ); | ||
|
||
__END__ | ||
=pod | ||
=head1 SYNOPSIS | ||
xss --stylesheet <stylesheet> document.xml | ||
=cut |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package XML::XSS::Stylesheet::HTML2TD; | ||
|
||
use Moose; | ||
use XML::XSS; | ||
use Perl::Tidy; | ||
|
||
extends 'XML::XSS'; | ||
|
||
style '*' => ( | ||
pre => \&pre_element, | ||
post => '};', | ||
); | ||
|
||
style '#text' => ( | ||
process => sub { $_[1]->data =~ /\S/ }, | ||
pre => "outs '", | ||
post => "';", | ||
filter => sub { s/'/\\'/g; s/^\s+|\s+$//gm; $_ }, | ||
); | ||
|
||
style '#document' => ( | ||
content => sub { | ||
my ( $self, $node, $args ) = @_; | ||
my $raw = $self->stylesheet->render( $node->childNodes ); | ||
|
||
my $output; | ||
my $err; | ||
eval { | ||
Perl::Tidy::perltidy( | ||
source => \$raw, | ||
destination => \$output, | ||
errorfile => \$err, | ||
) | ||
}; | ||
|
||
# send the raw output if Tidy failed | ||
return $err ? $raw : $output; | ||
}, | ||
); | ||
|
||
sub pre_element { | ||
my ( $self, $node, $args ) = @_; | ||
|
||
my $name = $node->nodeName; | ||
|
||
return "$name {" . pre_attrs( $node ); | ||
} | ||
|
||
sub pre_attrs { | ||
my $node = shift; | ||
|
||
my @attr = $node->attributes or return ''; | ||
|
||
my $output = 'attr { '; | ||
|
||
for ( @attr ) { | ||
my $value = $_->value; | ||
$value =~ s/'/'/g; | ||
$output .= $_->nodeName . ' => ' . "'$value'" . ', '; | ||
} | ||
|
||
$output .= '};'; | ||
|
||
return $output; | ||
} | ||
|
||
1; |