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!
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.
It could not be much easier:
<?php
require_once 'markdownify.php';
$md = new Markdownify;
echo $md->parseString($htmlInput);
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:
false.false and sets the width to which the outputted Markdown text shall be
wordwrapped. Default is false This feature is not yet finished!true.Markdownify is published under the LGPL, i.e. you can use it freely as in beer and speech. Also using Markdownify in commercial products is allowed. Open Source makes it possible!
Milian Wolff is the brain behind Markdownify. He is 19 years old and currently studying physics in Berlin. He does webdevelopment for years now and his projects get released under open source licenses.
Here are some ways to get in contact with him: