Skip Menu |
 

This queue is for tickets about the PPI-HTML CPAN distribution.

Report information
The Basics
Id: 29298
Status: new
Priority: 0/
Queue: PPI-HTML

People
Owner: Nobody in particular
Requestors: moritz [...] faui2k3.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: feature request: css_prefix (with patch)
Download (untitled) / with headers
text/plain 145b
Attached patch adds a 'css_prefix' option to new() that allows the user to supply a custom prefix to CSS classes. The patch is made against 1.07.
Subject: css_prefix.patch
Download css_prefix.patch
text/x-diff 2.8k
--- lib/PPI/HTML.pm.orig 2007-09-11 10:00:15.000000000 +0200 +++ lib/PPI/HTML.pm 2007-09-11 10:08:49.000000000 +0200 @@ -102,6 +102,11 @@ will also be cloned if it to be modified, to prevent destroying any CSS objects passed in. +=item css_prefix + +If you set the C<css_prefix> to a string, all CSS classes in the generated +HTML will be prefixed with that string. + =back Returns a new L<PPI::HTML> object @@ -116,6 +121,7 @@ my $self = bless { line_numbers => !! $args{line_numbers}, page => !! $args{page}, + css_prefix => defined $args{css_prefix} ? $args{css_prefix} : q{}, # colors => undef, # css => undef, }, $class; @@ -227,7 +233,7 @@ # Convert each string to a fragment my @fragments = (); - my $css_class = $self->_css_class( $Token ); + my $css_class = $self->_css_class( $Token ); foreach my $string ( @strings ) { my $Fragment = PPI::HTML::Fragment->new( $string, $css_class ) or return (); push @fragments, $Fragment; @@ -425,51 +431,52 @@ sub _css_class { my ($self, $Token) = @_; + my $prefix = $self->{css_prefix}; if ( $Token->isa('PPI::Token::Word') ) { # There are some words we can be very confident are # being used as keywords unless ( $Token->snext_sibling and $Token->snext_sibling->content eq '=>' ) { if ( $Token->content eq 'sub' ) { - return 'keyword'; + return $prefix . 'keyword'; } elsif ( $Token->content eq 'return' ) { - return 'keyword'; + return $prefix . 'keyword'; } elsif ( $Token->content eq 'undef' ) { - return 'core'; + return $prefix . 'core'; } elsif ( $Token->content eq 'shift' ) { - return 'core'; + return $prefix . 'core'; } elsif ( $Token->content eq 'defined' ) { - return 'core'; + return $prefix . 'core'; } } if ( $Token->parent->isa('PPI::Statement::Include') ) { if ( $Token->content =~ /^(?:use|no)$/ ) { - return 'keyword'; + return $prefix . 'keyword'; } if ( $Token->content eq $Token->parent->pragma ) { - return 'pragma'; + return $prefix . 'pragma'; } } elsif ( $Token->parent->isa('PPI::Statement::Variable') ) { if ( $Token->content =~ /^(?:my|local|our)$/ ) { - return 'keyword'; + return $prefix . 'keyword'; } } elsif ( $Token->parent->isa('PPI::Statement::Compond') ) { if ( $Token->content =~ /^(?:if|else|elsif|unless|for|foreach|while|my)$/ ) { - return 'keyword'; + return $prefix . 'keyword'; } } elsif ( $Token->parent->isa('PPI::Statement::Package') ) { if ( $Token->content eq 'package' ) { - return 'keyword'; + return $prefix . 'keyword'; } } elsif ( $Token->parent->isa('PPI::Statement::Scheduled') ) { - return 'keyword'; + return $prefix . 'keyword'; } } # Normal colouring my $css = lc ref $Token; $css =~ s/^.+:://; - $css; + return $prefix . $css; } 1;


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.