TextFormatter Class Reference

The TextFormatter class eases text formatting. More...

List of all members.

Public Member Functions

 TextFormatter ($text=null, $formatter=null)
 Initialize a new text formatter instance.
 render ()
 Return the formatted text.

Static Public Member Functions

 format ($text, $formatter=null)
 Formats text using the given formatter.

Public Attributes

 $default_formatter = 'auto'
 The default formatter.

Private Attributes

 $formatters
 List of all available formatters.


Detailed Description

The TextFormatter class eases text formatting.

It provides 4 formatter methods to format the input text: textile, entities, specialchars and raw. The 'textile' formatter formats the text using the rich Textile formatting language. The 'entities' and 'specialchars' formatters escape HTML entities so that the result can safely be displayed in a web browser. The 'raw' formatter returns the unchanged input text (this is useful if the formatter type comes from a database column). Additionally, there's the 'auto' formatter that chooses between textile and raw, depending on the input looking like XHTML (using a very simple heuristic).

Definition at line 37 of file textformatter.lib.php.


Member Function Documentation

TextFormatter::format ( text,
formatter = null 
) [static]

Formats text using the given formatter.

This method is useful if you don't want to instantiate a TextFormatter object. If you want to reuse the textformatter instance, don't use this method.

Parameters:
$text String with text to format
$formatter The name of the formatter to use (optional)
Returns:
String containing the formatted text

Definition at line 55 of file textformatter.lib.php.

TextFormatter::TextFormatter ( text = null,
formatter = null 
)

Initialize a new text formatter instance.

Both the text and formatter parameters are optional and can be set later using the 'text' and 'formatter' container properties.

Parameters:
$text String with text to format (optional).
$formatter The name of the formatter to use (optional).

Definition at line 89 of file textformatter.lib.php.

TextFormatter::render (  ) 

Return the formatted text.

Returns:
The formatted text

Simple heuristic for the automatic mode: check whether the first non-whitespace character is a < character. If so, assume it's already formatted as HTML and treat it as 'raw'. Otherwise, use textile. To improve speed, only the first 50 characters are considered.

Definition at line 105 of file textformatter.lib.php.


Member Data Documentation

TextFormatter::$formatters [private]

Initial value:

 array(
                        'auto',
                        'entities',
                        'raw',
                        'specialchars',
                        'textile',
                        )
List of all available formatters.

Definition at line 67 of file textformatter.lib.php.


The documentation for this class was generated from the following file:

Generated on Sun Aug 2 22:54:38 2009 for Anewt by  doxygen 1.5.9