netcarver / textile
Textile markup language parser
Installs: 1 092 550
Dependents: 24
Suggesters: 2
Security: 0
Stars: 216
Watchers: 27
Forks: 44
Open Issues: 24
Requires
- php: >=5.3.0
Requires (Dev)
- phpstan/phpstan: 1.12.0
- phpunit/phpunit: ^9.5.20
- psy/psysh: ^0.12.4
- squizlabs/php_codesniffer: 3.*
- symfony/yaml: ^5.4.40
- dev-master / 4.1.x-dev
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.0
- 3.8.x-dev
- v3.8.0
- v3.7.7
- v3.7.6
- v3.7.5
- v3.7.4
- v3.7.3
- v3.7.2
- v3.7.1
- v3.7.0
- 3.6.x-dev
- v3.6.1
- v3.6.0
- 3.5.x-dev
- v3.5.6
- v3.5.5
- v3.5.4
- v3.5.3
- v3.5.2
- v3.5.1
- v3.5.0
- 2.5.x-dev
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- 2.4.x-dev
- v2.4.3
- v2.4.2
- dev-feature/modernization
- dev-website
- dev-exp/unicode-img-title
- dev-issue-145
- dev-issue-168
- dev-issue-164
- dev-issue-96
- dev-self-link-scheme-visibility-control
- dev-issue-129
- dev-issue-22-take-3
This package is auto-updated.
Last update: 2024-11-15 17:29:51 UTC
README
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.
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⁄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.