PHP Markdown 解析器:PHP Markdown
PHP Markdown 包括 PHP Markdown 解析器和其他 PHP Markdown 编辑器的额外功能。
Introduction
This is a library package that includes the PHP Markdown parser and its sibling PHP Markdown Extra with additional features.
Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).
"Markdown" is actually two things: a plain text markup syntax, and a software tool, originally written in Perl, that converts the plain text markup to HTML. PHP Markdown is a port to PHP of the original Markdown program by John Gruber.
- Full documentation of the Markdown syntax
— Daring Fireball (John Gruber) - Markdown Extra syntax additions
— Michel Fortin
Requirement
This library package requires PHP 5.3 or later.
Note: The older plugin/library hybrid package for PHP Markdown and PHP Markdown Extra is still maintained and will work with PHP 4.0.5 and later.
Before PHP 5.3.7, pcre.backtrack_limit defaults to 100 000, which is too small in many situations. You might need to set it to higher values. Later PHP releases defaults to 1 000 000, which is usually fine.
Usage
This library package is meant to be used with class autoloading. For autoloading to work, your project needs have setup a PSR-0-compatible autoloader. See the included Readme.php file for a minimal autoloader setup. (If you cannot use autoloading, see below.)
With class autoloading in place, putting the 'Michelf' folder in your include path should be enough for this to work:
use \Michelf\Markdown; $my_html = Markdown::defaultTransform($my_text);
Markdown Extra syntax is also available the same way:
use \Michelf\MarkdownExtra; $my_html = MarkdownExtra::defaultTransform($my_text);
If you wish to use PHP Markdown with another text filter function built to parse HTML, you should filter the text after thetransformfunction call. This is an example with [PHP SmartyPants][psp]:
use \Michelf\Markdown, \Michelf\SmartyPants; $my_html = Markdown::defaultTransform($my_text); $my_html = SmartyPants::defaultTransform($my_html);
All these examples are using the staticdefaultTransformstatic function found inside the parser class. If you want to customize the parser configuration, you can also instantiate it directly and change some configuration variables:
use \Michelf\MarkdownExtra; $parser = new MarkdownExtra; $parser->fn_id_prefix = "post22-"; $my_html = $parser->transform($my_text);
To learn more, see the full list of configuration variables.