Khonsu-Syntax
view release on metacpan or search on metacpan
lib/Khonsu/Syntax.pm view on Meta::CPAN
Warning => '#edac33',
Line => '#dadada'
};
} }
);
}
sub add {
my ($self, $file, %attributes) = @_;
$attributes{y} ||= $file->page->y;
$self->set_attributes(%attributes);
my $kam = Syntax::Kamelon->new(
syntax => $self->syntax || 'Perl',
);
$kam->Parse($self->text);
my %points = $self->get_points();
my $highlight = $self->highlight;
my $line_number = 0;
for my $line (@{ $kam->{FORMATTER}->{LINES} }) {
if ($self->line_numbers) {
$line_number++;
$self->SUPER::add($file,
margin => 0,
font => { colour => $highlight->{Line} },
text => "$line_number |",
y => $points{y},
x => $points{x},
w => $self->line_number_width,
align => 'right'
);
$self->align('');
}
if (! scalar @{$line}) {
$file->page->y($file->page->y + $self->font->line_height);
} else {
for my $part (@{$line}) {
$self->SUPER::add($file,
font => { colour => $highlight->{$part->{tag}} },
text => $part->{text},
margin => 0,
($self->end_w ? (
x => $self->end_w,
w => $file->page->width()
) : ()),
y => $points{y},
);
}
}
$self->end_w(0);
$points{y} = $file->page->y;
}
return $file;
}
sub update_highlighting {
my ($self, %highlighting) = @_;
my $highlight = $self->highlight;
$highlight = {%{$highlight}, %highlighting};
$self->highlight($highlight);
return $self;
}
1;
__END__
=head1 NAME
Khonsu::Syntax - Khonsu PDF Generation Syntax Highlighting Plugin/Component
=head1 VERSION
Version 0.02
=cut
=head1 SYNOPSIS
use khonsu;
Khonsu->load_plugin(qw/+Syntax/);
my $k = Khonsu->new('test', page_args => {padding => 20});
my $json = q|{
"one": 1,
"two": 2,
"three": 3,
"four": 4
}|;
$k->add_syntax(
syntax => 'JSON',
line_numbers => 1,
text => $json
);
$k->save();
=head1 AUTHOR
LNATION, C<< <email at lnation.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-khonsu-syntax at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Khonsu-Syntax>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Khonsu::Syntax
( run in 1.545 second using v1.01-cache-2.11-cpan-2398b32b56e )