package MojoMojo::Formatter::Text; use base qw/MojoMojo::Formatter/; use URI::Find; =head1 NAME MojoMojo::Formatter::Text - format plain text as xhtml =head1 DESCRIPTION This formatter will format content between {{txt}} and {{end}} as XHTML) It is based on Angerwhale/Format/PlainText.pm =head1 METHODS =over 4 =item format_content_order Format order can be 1-99. The Text formatter runs on 10 =cut sub format_content_order { 10 } =item format_content calls the formatter. Takes a ref to the content as well as the context object. =cut sub format_content { my ( $class, $content, $c ) = @_; my @lines = split /\n/, $$content; my $txt; $$content = ""; my $start_re=$class->gen_re(qr/txt/); my $end_re=$class->gen_re(qr/end/); foreach my $line (@lines) { if ($txt) { if ( $line =~ m/^(.*)$end_re(.*)$/ ) { $$content .= MojoMojo::Formatter::Text->to_xhtml( $xhtml ); $txt = ""; } else { $txt .= $line . "\n"; } } else { if ( $line =~ m/^(.*)$start_re(.*)$/ ) { $$content .= $1; $txt = " ".$2; # make it true :) } else { $$content .= $line . "\n"; } } } } =item to_xhtml takes some text and renders it as XHTML. =cut sub to_xhtml { my ( $class, $text ) = @_; my $result; $text =~ s/&/&/g; $text =~ s/>/>/g; $text =~ s/new( sub { my($uri, $orig_uri) = @_; return qq|$orig_uri|; }); $finder->find(\$text); # fix paragraphs my @paragraphs = split /\n+/m, $text; @paragraphs = grep { $_ !~ /^\s*$/ } @paragraphs; $result = join( ' ', map { "

$_

" } @paragraphs ); return qq{
\n$result
}; } =back =head1 SEE ALSO L,L =head1 AUTHORS Daniel Brosseau =head1 LICENSE This module is licensed under the same terms as Perl itself. =cut 1;