Goodbye TinyMCE, Hello Markdown
I’ve been a faithful TinyMCE user for years, but my blogging needs are growing and changing, and TinyMCE just isn’t a fit anymore.
My primary complaint has been with syntax highlighting. The best solution I was able to find was a Javascript libarary called SyntaxHighlighter that requires you to plug into the customization settings of TinyMCE and be fastidious about embedding the right Javascript libraries and CSS stylesheets. While it has served its purpose, I’ve determined that my setup was, among other negatives, WYSIWYG first, everything else second.
Recently I discovered markdown. Yes, I’m a late bloomer. It is everything I ever wanted and nothing I never needed. Also, Django comes fully ready for markdown syntax. For highlighting I chose the ever-popular pygments library. Installing pygments is as easy as a quick pip install. Markdown also had to be installed prior to following a breezy guide on the Django docs.
I dug through multiple editors for the admin before finally choosing django-markitup, a did-the-hard-part-for-you Django app that provides model and form hooks for the awesome Markitup Javascript editor. I forked it to make a minor edit to the Javascript configuration (doesn’t have tab-button logic out of the box for some reason).
After all is said and done, I am able to write standard, syntax highlighted markdown in Django admin, as simple as:
:::django+html {% load markup %} {{ object.content|markdown:"codehilite"|safe }}
which results in:
{% load markup %} {{ object.content|markdown:"codehilite"|safe }}
The markdown templatetag honors HTML, so my existing blog entries don’t even have to be modified! I’ll probably convert a few of them anyway.