Library: for developers
- PHP Markdown Lib 1.3 (31 Ko)
- Library package for developers. Requires PHP 5.3. Also available on Packagist et and Github. April 11, 2013.
Classic Version: plugin for WordPress, Smarty, etc.
- Classic version → PHP Markdown & PHP Markdown Extra
- Important announcement: classic version of PHP Markdown and PHP Markdown Extra will stop being supported after February 1, 2014. It’ll continue to work and be available, but after this date further improvements will only go to the Lib version above.
PHP Markdown is a port to PHP of the Markdown tool written by John Gruber.
“Markdown” is two things: a plain text markup syntax, and a software tool that converts the plain text markup to HTML for publishing on the web.
The Markdown syntax allows you to write text naturally and format it without using HTML tags. More importantly: in Markdown format, your text stays enjoyable to read for a human being, and this is true enough that it makes a Markdown document publishable as-is, as plain text. If you are using text-formatted email, you already know some part of the syntax.
Visit the Concepts page for a short introduction full of examples where you will learn to write with Markdown. If you have some understanding of HTML, you can also read the full documentation of Markdown’s syntax, available on John’s web site.
PHP Markdown can work as a plug-in for WordPress, as a modifier for the Smarty templating engine, or as a remplacement for textile formatting in any software that support textile.
PHP Markdown requires PHP version 5.3 or later.
For older PHP versions, see the classic version.
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.
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 don’t want to
use autoloading you can do a classic
require_once to manually include the
files prior use instead.)
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 the
function call. This is an example with PHP SmartyPants:
use \Michelf\Markdown, \Michelf\SmartyPants; $my_html = Markdown::defaultTransform($my_text); $my_html = SmartyPants::defaultTransform($my_html);
All these examples are using the static
defaultTransform static function
found inside the parser class. If you want to customize the parser
configuration, you can also instantiate it directly and change some
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.
Public API and Versioning Policy
Version numbers are of the form major.minor.patch.
The public API of PHP Markdown consist of the two parser classes
MarkdownExtra, their constructors, the
functions and their configuration variables. The public API is stable for
a given major version number. It might get additions when the minor version
Protected members are not considered public API. This is unconventional and deserves an explanation. Incrementing the major version number every time the underlying implementation of something changes is going to give nonessential version numbers for the vast majority of people who just use the parser. Protected members are meant to create parser subclasses that behave in different ways. Very few people create parser subclasses. I don’t want to discourage it by making everything private, but at the same time I can’t guarantee any stable hook between versions if you use protected members.
Syntax changes will increment the minor number for new features, and the patch number for small corrections. A new feature is something that needs a change in the syntax documentation. Note that since PHP Markdown Lib includes two parsers, a syntax change for either of them will increment the minor number. Also note that there is nothing perfectly backward-compatible with the Markdown syntax: all inputs are always valid, so new features always replace something that was previously legal, although generally nonsensical to do.
To file bug reports please send email to: firstname.lastname@example.org
Please include with your report: (1) the example input; (2) the output you expected; (3) the output PHP Markdown actually produced.
Copyright and License
PHP Markdown & Extra
Copyright © 2004-2013 Michel Fortin
All rights reserved.
Copyright © 2004-2006 John Gruber
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name “PHP Markdown” nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.