Markdown

I wrote this blog platform specifically for my site. It's a minimalistic platform intended for a small site with a single author or administrator. As I was developing the platform, I debated how to handle the input of new entries, specifically whether to include HTML tags in the content of an entry when storing data in the database. I originally stored the entry content as plaintext without HTML tags, and when displaying the content, I used PHP's nl2br method to convert newlines to HTML line break tags.

That solution left me unsatisfied; it felt like a hack. Ultimately I settled on using markdown to input new entries in the system. I store the markdown plaintext in the database, and when displaying the content, I utilize Parsedown to convert the markdown to HTML.

The blog entries can now be displayed for the web quite easily, or they can be used in other applications that understand markdown. Arguably, HTML is widespread enough that portability concerns should be minimal, but its hierarchical nature means that a valid HTML document requires the appropriate opening tag, header, body, closing tag, etc. A blog entry in a database with basic HTML tags is not a valid HTML document on its own. With markdown, the plaintext of the content in the database is valid and can be easily rendered as HTML.

Pedantic? Perhaps, but this solution is satisfying.

Tags: markdown

Comments

* Alex - Sat, 16 Mar 2024 15:47:30 GMT

Test

Reply



What is the capital of the United States?