Markdown is a pure text format you can easily write and convert to HTML. It has several nice features and one of
those is inline HTML. I one of my current projects (you will see it soon enought…) I'm combining PHP Markdown
with some of the new HTML5 elements:
Normal text…
<figure>
<figcaption>The appearance of FooBar</figcaption>
<img src="foobar.jpg" />
</figure>
Some more text…
Markdown wraps p
elements around everything that looks like paragraphs. This would also apply to inline HTML code
but Markdown already has a build in list of HTML block elements. If it encounters one of those it's not wrapped inside a
p
element. Because HTML5 is pretty new stuff Markdown don't know the HTML5 block elements yet. Therefore it wraps
the figure
element inside a p
element thus making the document invalid (and screwing up the styles).
Thankfully the PHP Markdown source code is very well documented and this made it a pice of cake to add the figure
element to the list of block level elements. In Line 1770 of PHP Markdown 1.0.1n the variable $block_tags_re
contains the list of block level elements:
# Tags that are always treated as block tags:
var $block_tags_re = 'p|div|h[1-6]|…|hr|legend';
I abbreviated the list a bit for clarity. Just add |figure to the end and you're done. After that modification
PHP Markdown stopped to wrap p
elements around the figure
elements.
Since HTML5 is no way near finished it is probably to early to add the HTML5 block level elements to the source of the PHP
Markdown project itself. However for the advantages of HTML5 I'm willing to live with such a small modification. :)