Text::Textile::Plaintext - Convert Textile mark-up to plain text
use Text::Textile::Plaintext qw(textile); my $textile = <<EOT; h1. Heading A _simple_ demonstration of Textile markup. * One * Two * Three "More information":http://www.textism.com/tools/textile is available. EOT # Procedural interface: my $text = textile($textile); print $text; # Object-oriented interface my $ttp = Text::Textile::Plaintext->new(); $text = $ttp->process($textile);
The Text::Textile::Plaintext class extends Text::Textile by running the HTML content that it produces through instances of a tree-builder and a formatter. By default, HTML::TreeBuilder and HTML::FormatText are used, but classes that match their interfaces can be substituted.
The functionality provided by this module is identical to that of Text::Textile. Note that even the synopsis, above, is lifted directly from there. The only difference is in the format of the output produced.
As with Text::Textile, this module's functionality may be used either procedurally or via an object interface. You can import the textile() function and call it without having to first instantiate an object instance. See below for documentation on this function and its calling convention.
The following methods are available within this class:
Create a new object of this class. The arguments detailed below, if present, are stripped and processed by Text::Textile::Plaintext while any remaining arguments are passed to the super-class (Text::Textile) constructor.
The arguments handled locally are:
Provide a pre-instantiated instance of HTML::TreeBuilder (or suitable sub-class) to use in place of new() constructing one itself.
Provide a pre-instantiated instance of HTML::FormatText (or suitable sub-class) to use in place of new() constructing one itself.
These are passed directly to the constructor of HTML::FormatText, unless you passed in a specific formatter instance via the formatter parameter, above. The defaults for the margins are those set by HTML::FormatText (3 for the left margin, 72 for the right).
formatter
Both of the objects (tree-builder and formatter) are kept until after the parent constructor is called and the object re-blessed into the calling class. At that point, the values are assigned to the object using the accessor methods defined below. This allows a sub-class to overload the accessors and handle these parameters.
Convert the Textile mark-up in $textile_content to plain text, and return the converted content. This method is identical in nature and calling form to the same-named method in the parent class. The difference is the production of plain text rather than HTML.
$textile_content
This method may be imported and called as a function. In such a case, a temporary Text::Textile::Plaintext object is created and used to invoke the needed parent class functionality.
Get or set the treebuilder attribute.
treebuilder
If a value is given, it is assigned as the new value of the attribute. This must be a reference to an object that is either an instance of HTML::TreeBuilder, or an instance of an object that matches its interface. You can use this to assign a tree-builder that has debugging capacity built into it, for example.
The return value is the current attribute value (after update).
Get or set the formatter attribute.
If a value is given, it is assigned as the new value of the attribute. This must be a reference to an object that is either an instance of HTML::FormatText, or an instance of an object that matches its interface. You can use this to assign a formatter that has debugging capacity built into it, for example.
Note that the method process() is not defined here, as it is inherited from Text::Textile.
This module makes no effort to trap error messages or exceptions. Any output to STDERR or STDOUT, or calls to warn or die by Text::Textile, HTML::TreeBuilder or HTML::FormatText will go through unchallenged unless the user sets up their own exception-handling.
warn
die
In truth, Textile could be converted to text without first being turned into HTML. But Text::Textile does a good job of handling all the various stylistic syntax that can affect things like paragraph justification, etc., and the other modules do their jobs quite well, too.
The HTML::FormatText package has some quirks in the way things are laid-out, such as bulleted lists.
Please report any bugs or feature requests to bug-text-textile-plaintext at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-Textile-Plaintext. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-text-textile-plaintext at rt.cpan.org
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Textile-Plaintext
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Text-Textile-Plaintext
CPAN Ratings
http://cpanratings.perl.org/d/Text-Textile-Plaintext
Search CPAN
http://search.cpan.org/dist/Text-Textile-Plaintext
Source code on GitHub
http://github.com/rjray/text-textile-plaintext/tree/master
This file and the code within are copyright (c) 2009 by Randy J. Ray.
Copying and distribution are permitted under the terms of the Artistic License 2.0 (http://www.opensource.org/licenses/artistic-license-2.0.php) or the GNU LGPL 2.1 (http://www.opensource.org/licenses/lgpl-2.1.php).
Text::Textile
Randy J. Ray <rjray@blackperl.com>
<rjray@blackperl.com>
To install Text::Textile::Plaintext, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Textile::Plaintext
CPAN shell
perl -MCPAN -e shell install Text::Textile::Plaintext
For more information on module installation, please visit the detailed CPAN module installation guide.