php textile

Textile markup language parser for PHP


h1. PHP-Textile

“Textile reference”: | “Live editor”:

!!: !!: !!:

PHP-Textile is a modern Textile markup language parser for PHP. Textile is a humane web text generator that takes lightweight, readable, plaintext-like markup language and converts it into well formed HTML.

h2. Install

Using “Composer”:

bc. $ composer require netcarver/textile

h2. Usage

The Textile parser can be accessed through the @Netcarver\Textile\[email protected] class. The class is highly configurable, and actual parsing happens with the @[email protected] method:

bc. require ‘./vendor/autoload.php’;
$parser = new \Netcarver\Textile\Parser();
echo $parser->parse(‘h1. Hello World!’);

h3. Parsing untrusted input

If you are using PHP-Textile to format user-supplied input, blog comments for instance, remember to enable restricted parser mode:

bc. $parser = new \Netcarver\Textile\Parser();
echo $parser

In restricted mode PHP-Textile doesn’t allow more powerful formatting options such as inline styles, and removes any raw HTML.

h3. Parsing single-line fields

If you are using PHP-Textile as a field-level formatter to parse just inline spans and glyphs, use the @[email protected] method to disable block tags:

bc. $parser = new \Netcarver\Textile\Parser();
echo $parser
->parse(‘Hello strong world!’);

The above outputs:

bc. Hello strong world!

h3. Doctypes

Currently, PHP-Textile can target either XHTML or HTML5 output with XHTML being the default for backward compatibility. The targeted doctype can be changed via the @[email protected] method:

bc. $parser = new \Netcarver\Textile\Parser();
echo $parser
->parse(‘HTML(HyperText Markup Language)’);

h3. Setting alternate glyphs

Textile’s typographic substitutions can be overridden with the @[email protected] method. If you need to setup Textile to do non-standard substitutions, call @[email protected] before you parse the input with @[email protected]

bc. $parser = new \Netcarver\Textile\Parser();
->setSymbol(‘half’, ‘1⁄2’)
->parse(‘Hello [1/2] World!’);

The symbol names you can pass to @[email protected] can be found “here”:

h3. Prefixing relative image and link paths

Setting prefix might be useful if you want to point relative paths to certain consistent location:

bc. $parser = new \Netcarver\Textile\Parser();
->parse(‘!image.jpg! “link”:page’);

h2. Getting in contact

The PHP-Textile project welcomes constructive input and bug reports from users. Please “open an issue”: on the repository for a comment, feature request or bug.

h2. Development

See “CONTRIBUTING.textile”: