tags:

views:

1522

answers:

4

I am curious to do what happens when you edit a post on this site.

I am using wmd for my markdown editor, of course when I goto edit, I get the HTML it generated not the markdown like on stackoverflow. Now, is there a way I can store both? or is it reliable enough to simply convert the HTML back to markdown to show in the wmd editor?

Thanks!

+8  A: 

Look at the optionsExample.html in your WMD distribution. There's an option to send the result to the server as Markdown.

Chris Jester-Young
Actually, I have seen how to get one or the other, but then I need to convert it to HTML everytime I display it. IS that they best way to go? Either way I think I am in the same boat. Seems more efficent to convert it back only when editing.
Ryan M
You can convert to HTML on the server end, and store both HTML and Markdown in your database. That's how Stack Overflow does it, I believe.
Chris Jester-Young
To avoid lots of repeat sanitisations, I believe that SO also sanitises the HTML'd version before storing that in the DB. (I believe there is a SO blog entry that mentions this, but don't quote me on it.)
Chris Jester-Young
Thank You so much!
Ryan M
This is the javascritp you need to add before you load wmd.js: wmd_options = { output: "Markdown" };
Sire
A: 

Actually, I have seen how to get one or the other, but then I need to convert it to HTML everytime I display it. IS that they best way to go? Either way I think I am in the same boat. Seems more efficent to convert it back only when editing

Ryan M
+2  A: 

As Chris notes, you can send Markdown to the server so you can store it there as such. I started trying to use MarkdownJ to convert on the server-side, but it doesn't (at the time of this writing) convert images to HTML correctly and so I ended up going with Java 6 Scripting: Rhino engine + showdown.js. Since WMD uses showdown.js you get the same Markdown-to-HTML transformation. Works like a charm (for Java 6, anyway).

Willie Wheeler
+1  A: 

If you want to convert HTML to Markdown in batch, I can recommend Aaron Swartz’s html2text.py Python script with which you can just:

cat my.html | python html2text.py # outputs markdown
kvz