Markdown is a great way to format texts for the Internet. Without much experience an easy to read text is written — without the bloat of HTML tags.
But this comes — like so many things — with a cost: performance will suffer and CPU is wasted since normally Markdown would have to convert your texts to HTML for every page impression. Only some way of caching could prevent this.
That is exactly the point where Markdownify (formerly html2text.php) comes into play: Write texts in Markdown and save them in HTML. You won’t need a copy of the original Markdown input, since Markdownify can convert the saved HTML back to Markdown. And because page impressions are far more often than write actions, this gives you a simple way to increase your page’s performance.
Another benefit for a CMS or similar software is that now only one format of text is saved — HTML. The user can now choose wether to write texts in plain HTML or use a full fledged Wysiwyg editor. And of course he can write in Markdown!
Yeah, but what do I lose?
PHP Markdown Extra has the ability to markdown abbrevations (< abbr >). Markdownify_Extra will convert these, though the following problem can arise:
< p >< abbr title="Definition 1" >ABK▄RZUNG< /abbr >< /p >
< p >< abbr title="Definition 2" >ABK▄RZUNG< /abbr >< /p >
As you can see on the demo page (don’t forget to activate Markdownify Extra), the last definition will be neglected. This is just a very minor problem in my eyes since two definitions for one and the same abbrevation don’t make much sense!
Status: Markdownify is currently in beta status. Markdownify_Extra is still missing support for “Markdown in blockelements” and word wrapping is not yet finished. Additionally I hope to gain a few performance boosts by refactoring a few parts.
Markdownify is written in PHP and should work since PHP 4.3. The test cases from MDTest were used as a basis for the “test driven development” (TDD). To convert Markdown to HTML you should use Michel Fortin’s PHP Markdown or PHP Markdown Extra.
How to use Markdownify
It could not be much easier:
$md = new Markdownify;
And yes — PHP Markdown Extra is supported by Markdownify!. Just use the Markdownify_Extra class and see tables, definition lists and all that glory stuff get converted.
Optionally you can give some parameters to the class constructor:
The first one is a boolean which decides whether link definitions shall be displayed after each block element. Default is false.
The second parameter is an integer or false and sets the width to which the outputted Markdown text shall be wordwrapped. Default is false This feature is not yet finished!
The last argument is a boolean again and tells Markdownify whether to keep non-markdownable HTML tags or to discard them. Default is true.
What's New in This Release:
· PHP 4 fixes
· support uppercase HTML-Tags
· code blocks after lists
· require newlines before markdownable blockelements
· decode apos and quot inside code and pre tags