tags:

views:

458

answers:

4

I've noticed that the wmd editor can either output HTML or markdown. Does it make more sense to store the user input (in a database) as markdown or HTML? If as markdown, what is the best way to display it on a webpage later on (any examples would be greatly appreciated).

Given that the recommendation is store it as markdown, are there any standard converters / stylesheets / anything else to actually display it afterwards?

+3  A: 

Speaking from almost total ignorance of markdown and wmd:

If you want the user to be able to edit the entry later, don't you have to store it as markdown?

On retrieval/display you'd need to run it through a markdown renderer of some kind.

Ken Gentle
+5  A: 

I would say it's easier to store the markdown in the database, and process it into HTML when you display it.

You could store the input as HTML, then when the user wants to edit it, use something like markdownify to convert it back to markdown - but you don't really gain anything, and lose a lot (the original markdown formatting, for one). It's also rather round-a-bout (you convert the markdown to HTML, store it. Then convert the HTML to markdown, allow the user to edit it, convert it back to HTML, and store that..)

If you are worried about performance of parsing markdown on every page-view: cache the output HTML somewhere temporary (in memory, or on disc). The HTML is easier to recreate than the source markdown

dbr
A: 

It looks like there are details on how to generate the corresponding HTML for saved markdown on another thread.

Jedidja
A: 

I think the best way to allow consequent editing would be to store markdown file. After user edited, or uploaded, it's file in markdown syntax save it and generate html and store that generated html.

You only need to 're-generate' html when user updates the markdown file.

I'm not sure what technology you use but there is a python markdown processor, there's pygments for code syntax highlight and python-markdown has build in support for pygments so in one line you get html from markdown file and all source code highlighted.

You need to update the css to include styles to use for code highlight, you can dump default style from pygments and attach it to your page style.

Here is an example how to use markdown and pygments with Blogger.

stefanB