Markdown dates back to 2004, incidentally the same year the WHATWG started working on HTML5. Now that HTML 5.0 is a a W3C Recommendation, it would be awesome if the popular Markdown converters would also support the new stuff that the new markup brings with it.
Footnotes
The vanilla Markdown does not have support for footnotes, although Daring Fireball does use them. Support for footnotes was added by MultiMarkdown and the output mimics the HTML used by Daring Fireball:
This had lead to pretty much every Markdown converter that supports MMD’s new features to do this in exactly similar fashion even though HTML5 added a new semantic element called <footer>
that I think not only simplifies the markup but also gets rid of the extra <hr>
element1.
Figures
Another new semantic thing HTML5 added is the <figure>
element. This element is used to represent, according to the spec:
… unit of content, optionally with a caption, that is self-contained, that is typically referenced as a single unit from the main flow of the document, and that can be moved away from the main flow of the document without affecting the document’s meaning.
In blogging context, this means pretty much all the images, code examples and whatever else that is used to illustrate the main text. One fancy thing figure
adds is a straightforward way to caption these figures. For images in blog articles, this would mean that a more correct way to output
would be
Also, this applies equally to the code examples above.
Extending Kramdown
Fortunately, Kramdown allows subclassing its HTML converter among its other totally awesome features.
This class simply then needs to override convert_codeblock
and footnote_content
methods with almost identical methods where the <div>
s in output strings are changed to <figure>
s.
However, as <img>
can also appear inline in text, for example as an emoticon, some additional code is needed to check for just block-level images. Probably a more “correct” approach would be to identify block-level images already in a parser (as Kramdown’s parser does for <code>
). However, one – and very likely not a very good – way to achieve this in the converter is to add a bit of logic to convert_p
.
To get this new converter to work, for example in Jekyll, you also need to create a new Jekyll converter that tells Kramdown to convert the document to #to_html5
instead of #to_html
:
Also, change the default Markdown converter in _config.yml
to:
There are probably other things that would make converted Markdown more civilized in a HTML5 world but these two things, footnotes and figures, have been the two itches that have bothered me the most.