netcarver/textile

Textile markup language parser

Maintainers

๐Ÿ‘ netcarver

Package info

github.com/textile/php-textile

Wiki

pkg:composer/netcarver/textile

Statistics

Installs: 1โ€‰527โ€‰237

Dependents: 24

Suggesters: 2

Stars: 229

Open Issues: 24

v4.1.4 2025-12-20 18:52 UTC

Requires

  • php: >=5.3.0

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 53593a5a57b4c1db37d96237ab204b4d5548f19f

parserhtmllanguagedocumentmarkupformattextileplaintextphp-textile


README

Textile reference | Live editor

๐Ÿ‘ Image
๐Ÿ‘ Image
๐Ÿ‘ Image

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.

Install

Using Composer:

$ composer require netcarver/textile

Usage

The Textile parser can be accessed through the Netcarver\Textile\Parser class. The class is highly configurable, and actual parsing happens with the parse method:

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

Parsing untrusted input

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

$parser = new \Netcarver\Textile\Parser();
echo $parser
 ->setRestricted(true)
 ->parse('!bad/image/not/allowed.svg!');

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

Parsing single-line fields

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

$parser = new \Netcarver\Textile\Parser();
echo $parser
 ->setBlockTags(false)
 ->parse('Hello *strong* world!');

The above outputs:

Hello <strong>strong</strong> world!

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 setDocumentType method:

$parser = new \Netcarver\Textile\Parser();
echo $parser
 ->setDocumentType('html5')
 ->parse('HTML(HyperText Markup Language)');

Setting alternate glyphs

Textileโ€™s typographic substitutions can be overridden with the setSymbol method. If you need to setup Textile to do non-standard substitutions, call setSymbol before you parse the input with parse.

$parser = new \Netcarver\Textile\Parser();
$parser
 ->setSymbol('half', '1&#8260;2')
 ->parse('Hello [1/2] World!');

The symbol names you can pass to setSymbol can be found here.

Prefixing relative image and link paths

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

$parser = new \Netcarver\Textile\Parser();
$parser
 ->setImagePrefix('/user/uploads')
 ->setLinkPrefix('/')
 ->parse('!image.jpg! "link":page');

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.

Development

See CONTRIBUTING.textile.