Search code examples
htmldjangomarkdownwmd

How to switch web app from HTML to Markdown?


I've got a django-powered site. Currently, all of the textfields are just plain old text inputs that take raw HTML. I have no fancy editor or anything. I would like to start using Markdown and WMD to make things easier for everyone.

Do I have to run some sort of script to go over every text field in the database to convert all the HTML to markdown? If I run the HTML through the markdown filter, will it come out the same on the other side? Will the WMD editor read the HTML from the server and convert it to Markdown for the user to edit?

What's the correct course of action here?


Solution

  • Apparently converting the old HTML to markdown is completely unnecessary. I applied the django.contrib.markup.markdown filter to my templates, and the HTML in the legacy database records was passed straight through. Markdown in non-legacy records was also rendered correctly.

    Granted, my web application does not allow users to be modifying these fields, so it is ok to let HTML pass straight through. If this was a user-editable field, like comments or a wiki, this solution would not suffice. You would have to pass the safe parameter to the markdown template filter, which would strip out all the HTML, and some HTML to markdown conversion would be necessary for legacy posts written in HTML.

    Another solution, in that case, would be to write a new template filter that wrapped the markdown filter. It would allow old HTML posts to pass through, but apply the safe markdown filter to non-legacy posts.