[ANN] Object-Oriented PHP Markdown/SmartyPants
Michel Fortin
michel.fortin at michelf.com
Fri May 19 14:35:36 EDT 2006
This is something that I've been asked for many times. So today I'm
announcing that all future versions of PHP Markdown and PHP
SmartyPants will be encapsulated in a parser class. This has two
major benefits:
1. It should make extensions to the syntax easier to create and
maintain as it is now possible to now extend the parser by
replacing (overriding) only the relevant parts without modifying
the existing PHP Markdown code.
2. It allows the use of many parsers in the same PHP script.
Today I'm releasing the new object-oriented counterparts to PHP
Markdown 1.0.1c, PHP Markdown Extra 1.0.1, and PHP SmartyPants
1.5.1e, named respectively PHP Markdown 1.0.1oo, PHP Markdown Extra
1.0.1oo, and PHP SmartyPants 1.5.1oo. Please consider them beta for now:
PHP Markdown 1.0.1oo
<http://www.michelf.com/docs/projets/php-markdown-1.0.1oo.zip>
PHP Markdown Extra 1.0.1oo
<http://www.michelf.com/docs/projets/php-markdown-extra-1.0.1oo.zip>
PHP SmartyPants 1.5.1oo
<http://www.michelf.com/docs/projets/php-smartypants-1.0.1oo.zip>
They should yield identical results than their non-object
counterparts. If not, that's a bug, please tell me.
These new versions feature the same programming interface as before
-- you can still call the Markdown or SmartyPants functions. These
functions will create and use the parser themselves, but you can also
use the parser directly. This:
$html = Markdown($text);
is now equivalent to this if you're using PHP Markdown:
$parser = new Markdown_Parser;
$html = $parser->transform($text);
or this if you're using PHP Markdown Extra:
$parser = new MarkdownExtra_Parser;
$html = $parser->transform($text);
PHP Markdown and PHP Markdown Extra are still both packaged as one
"markdown.php" file, each of them containing a Markdown function; so
they're still mutually exclusive. But the "markdown.php" file of PHP
Markdown Extra contains both the Markdown_Parser and the
MarkdownExtra_Parser classes. Hence, by calling directly the parser,
you can filter text using both syntaxes.
For SmartyPants, attributes are (optionally) specified while
constructing the parser and not while calling the transform method:
$parser = new SmartyPants_Parser('q');
$html = $parser->transform($html);
This is equivalent:
$html = SmartyPants($html, 'q');
I'll release an object-oriented beta for PHP Markdown 1.0.2 later,
probably when John comes out with a new beta; the same for SmartyPants.
Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/
More information about the Markdown-Discuss
mailing list