Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Textile markup language parser for PHP

License

NotificationsYou must be signed in to change notification settings

textile/php-textile

Textile reference |Live editor

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

Install

UsingComposer:

$ composer require netcarver/textile

Usage

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

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

Parsing untrusted input

If you are usingPHP-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 modePHP-Textile doesn’t allow more powerful formatting options such as inline styles, and removes any rawHTML.

Parsing single-line fields

If you are usingPHP-Textile as a field-level formatter to parse just inline spans and glyphs, use thesetBlockTags 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 eitherXHTML or HTML5 output withXHTML being the default for backward compatibility. The targeted doctype can be changed via thesetDocumentType 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 thesetSymbol method. If you need to setup Textile to do non-standard substitutions, callsetSymbol before you parse the input withparse.

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

The symbol names you can pass tosetSymbol can be foundhere.

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

ThePHP-Textile project welcomes constructive input and bug reports from users. Pleaseopen an issue on the repository for a comment, feature request or bug.

Development

SeeCONTRIBUTING.textile.

About

Textile markup language parser for PHP

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors8


[8]ページ先頭

©2009-2026 Movatter.jp