| 1 | package MojoMojo::Formatter::Textile; | ||
| 2 | |||
| 3 | 27 | ▶ | use parent 'MojoMojo::Formatter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 27 | ▶ | use Text::Textile; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 27 | ▶ | use Text::SmartyPants; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 27 | my $textile = Text::Textile->new( | |
| 8 | flavor => 'xhtml1', | ||
| 9 | charset => 'utf-8', | ||
| 10 | char_encoding => 0, # don't encode any other entities than <, >, " and & | ||
| 11 | ); | ||
| 12 | |||
| 13 | # We do not want Text::Textile to encode HTML entities at all because that will | ||
| 14 | # conflict with with <pre> tags generated by SyntaxHighlight. SyntaxHighlight | ||
| 15 | # already converts C<< < >> and C<< > >> to C<<> and C<>,> and letting | ||
| 16 | # Textile process that again will produce C<&lt;> and C<&gt;> | ||
| 17 | { | ||
| 18 | 27 | ▶ | no strict 'refs'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 27 | ▶ | no warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 43 | ▶ | *{"Text::Textile::encode_html"} = sub { my ($self, $html) = @_; return $html; }; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 21 | } | ||
| 22 | |||
| 23 | =head1 NAME | ||
| 24 | |||
| 25 | MojoMojo::Formatter::Textile - Texile+SmartyPants formatting for your content | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | This formatter processes content using L<Text::Textile> (a syntax for writing | ||
| 30 | human-friendly formatted text), then post-processes that using L<Text::SmartyPants> | ||
| 31 | (which transforms plain ASCII punctuation characters into "smart" typographic | ||
| 32 | punctuation HTML entities, such as smart quotes or the ellipsis character). | ||
| 33 | |||
| 34 | Textile reference: <http://hobix.com/textile/> | ||
| 35 | |||
| 36 | =head1 METHODS | ||
| 37 | |||
| 38 | =head2 main_format_content | ||
| 39 | |||
| 40 | Calls the formatter. Takes a ref to the content as well as the | ||
| 41 | context object. Note that this is different from the format_content method | ||
| 42 | of non-main formatters. This is because we don't want all main formatters | ||
| 43 | to be called when iterating over pluggable modules in | ||
| 44 | L<MojoMojo::Schema::ResultSet::Content::format_content>. | ||
| 45 | |||
| 46 | C<main_format_content> will only be called by <MojoMojo::Formatter::Main>. | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | 36 | ▶ | sub main_format_content { |
|
Subroutine
main_format_content: called CC=1 SCAR=0.0
Pod
documented
| |||
| 51 | 36 | my ( $class, $content ) = @_; | |
| 52 | |||
| 53 | 36 | $$content = $textile->process($$content); | |
| 54 | 36 | $$content = Text::SmartyPants->process($$content); | |
| 55 | # for uniformity with Markdown, make sure the output ends with *one* newline. | ||
| 56 | # See justification in L<MojoMojo::Formatter::Markdown/format_content>. | ||
| 57 | 36 | $$content =~ s/\n*$/\n/; | |
| 58 | 36 | return $$content; | |
| 59 | } | ||
| 60 | |||
| 61 | =head1 SEE ALSO | ||
| 62 | |||
| 63 | L<MojoMojo>, L<Module::Pluggable::Ordered>, L<Text::Textile> | ||
| 64 | |||
| 65 | =head1 AUTHORS | ||
| 66 | |||
| 67 | Marcus Ramberg <mramberg@cpan.org> | ||
| 68 | |||
| 69 | =head1 LICENSE | ||
| 70 | |||
| 71 | This library is free software. You can redistribute it and/or modify | ||
| 72 | it under the same terms as Perl itself. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | 27 | 1; | |