10

I have implemented the WMD control that Stack Overflow uses into a project of mine, it almost works like a charm, but when I save the changes to the database it is saving the HTML version and not the Markdown version.

So where I have this in my text box:

**boldtext**

It is really saving this:

<b>boldtext</b>

How do I make it save the Markdown version?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mattruma
  • 16,589
  • 32
  • 107
  • 171
  • How are you display the text in preview and in the textarea once it has been saved to the database? Can you share code sample? – Picflight Aug 26 '09 at 17:29
  • I actually save both versions to the database, both the mark down and html version. I use Markdown.Net to do the encoding on the server side. – mattruma Aug 26 '09 at 20:25

2 Answers2

10

Before you include wmd.js, or whatever you've named the WMD editor JavaScript code locally, add one line of JavaScript code:

wmd_options = {"output": "Markdown"};

This will force the output of the editor to Markdown.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Clinton Dreisbach
  • 7,732
  • 6
  • 29
  • 27
1

If you're using the new WMD from http://code.google.com/p/wmd-new/, open wmd.js and add this line:

wmd.wmd_env.output = 'markdown';

Excerpt:

...
wmd.ieCachedRange = null; // cached textarea selection
wmd.ieRetardedClick = false; // flag

wmd.wmd_env.output = 'markdown'; // force markdown output

// Returns true if the DOM element is visible, false if it's hidden.
// Checks if display is anything other than none.
util.isVisible = function (elem) {
...

That should do the trick.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131