How do you store the markdown using WMD in ASP.NET?
Asked Answered
D

2

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?

Discharge answered 23/9, 2008 at 16:26 Comment(2)
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?Peritoneum
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.Discharge
I
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.

Inconsecutive answered 23/9, 2008 at 17:47 Comment(3)
using this, can you have it output both the markdown AND the html?Agna
@Ryan: It will simply not autoconvert to html on postback.Soupspoon
where 's line that I put wmd_options = {"output" : "Markdown"}; into?Dahlberg
A
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.

Ashti answered 20/3, 2011 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.