TrickJarrett.com

HTML to Markdown

5/29/2022 8:03 am |

We're officially a Markdown blog! For those unfamiliar with Markdown, it's a 'markup language.' That is, like HTML, it defines how a document will look - using a very simple system. I'll dive into why I'm doing this later in the post. For you all, you should see (almost) no change on the blog, most everything I discuss here is relating to the backend management of it.

A few days ago, I quickly worked out the code which would take every entry in the blog and convert them from HTML to Markdown. I also took the opportunity to fix some content errors in the site; though it's not all fixed. Before running the conversion, I did a lot of testing to be confident it wouldn't screw up the database - but, having done that, I still took an export of the database as backup before running it. You can never be too careful when dealing with something that could potentially ruin your website.

This morning, after the entries in the database were converted, I switched my admin interface to a different editor which supports Markdown. I am currently going with Editor.md which looks to be a markdown editor made for the Chinese market. It's quite robust, though I have a few things I still need to figure out. Such as, when writing this post, I went to use a modal and the UI popped up in Chinese! Whoops. Thankfully it was a quick fix as they provide a bit of code which fully translates the UI into English.

Once the editor was in place, and I had confirmed all of my normal admin functionality worked, I then finished implementing the publishing which would turn the Markdown into HTML. Thankfully the Parsedown library for PHP is robust and simple. It only took a few lines of code to implement it.

That was it. Overall, very straight forward, and now my blog is future proofed. The future-proofing is one of the major upsides of using Markdown.

The editor I was using before was called Quill, and while it's a very powerful rich-text editor,the HTML it created was not perfect. This isn't a problem limited to Quill, many rich text editors struggle with this. I still remember the nightmare code that Microsoft Word would produce if you saved your document as an HTML file. So, with Quill, I was having to do code cleanups and figure out workarounds for some of its quirks.

Ultimately, this is not a huge thing. Many other blogs store their posts in HTML. I just like knowing it is in Markdown for flexibility. And, making Markdown the core structure of the backend enables me to potentially do some other things for inputting new entries. Dave Winer, the father of RSS, has a neat thing he put together where he can tweet a thread in markdown and his blog will pick it up and import it as an entry. I don't currently plan to do that with this blog, but it's an example of where making Markdown the editorial core enables some greater flexibility.