MojoMojo::Formatter::Textile - Texile+SmartyPants formatting for your content


MojoMojo documentation Contained in the MojoMojo distribution.

Index


Code Index:

NAME

Top

MojoMojo::Formatter::Textile - Texile+SmartyPants formatting for your content

DESCRIPTION

Top

This formatter processes content using Text::Textile (a syntax for writing human-friendly formatted text), then post-processes that using Text::SmartyPants (which transforms plain ASCII punctuation characters into "smart" typographic punctuation HTML entities, such as smart quotes or the ellipsis character).

Textile reference: <http://hobix.com/textile/>

METHODS

Top

main_format_content

Calls the formatter. Takes a ref to the content as well as the context object. Note that this is different from the format_content method of non-main formatters. This is because we don't want all main formatters to be called when iterating over pluggable modules in MojoMojo::Schema::ResultSet::Content::format_content.

main_format_content will only be called by <MojoMojo::Formatter::Main>.

SEE ALSO

Top

MojoMojo, Module::Pluggable::Ordered, Text::Textile

AUTHORS

Top

Marcus Ramberg <mramberg@cpan.org>

LICENSE

Top

This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.


MojoMojo documentation Contained in the MojoMojo distribution.
package MojoMojo::Formatter::Textile;

use parent 'MojoMojo::Formatter';

use Text::Textile;
use Text::SmartyPants;
my $textile = Text::Textile->new(
    flavor => 'xhtml1',
    charset => 'utf-8',
    char_encoding => 0,  # don't encode any other entities than <, >, " and &
);

# We do not want Text::Textile to encode HTML entities at all because that will
# conflict with with <pre> tags generated by SyntaxHighlight. SyntaxHighlight
# already converts C<< < >> and C<< > >> to C<&lt;> and C<&gt;,> and letting
# Textile process that again will produce C<&amp;lt;> and C<&amp;gt;>
{
    no strict 'refs';
    no warnings;
    *{"Text::Textile::encode_html"} = sub { my ($self, $html) = @_; return $html; };
}

sub main_format_content {
    my ( $class, $content ) = @_;

    $$content = $textile->process($$content);
    $$content = Text::SmartyPants->process($$content);
    # for uniformity with Markdown, make sure the output ends with *one* newline.
    # See justification in L<MojoMojo::Formatter::Markdown/format_content>.
    $$content =~ s/\n*$/\n/;
    return $$content;
}

1;