How to retrieve BOTH the markdown and html using the wmd-editor control?
Asked Answered
B

1

8

I am using WMD-Editor and would look to store both the Markdown and HTML version of the text that is entered.

I can only seem to get access to the output as Markdown OR HTML, but not both.

I am using ASP.NET MVC and am trying to get something like the following code to work ... just don't know how to get at the HTML.

Here is a snippet of the HTML code:

            <p>
                <%= Html.TextArea("Body", this.Model.Body )%>
                <%= Html.ValidationMessage("Body", "*") %>
                <div class="wmd-preview">
                </div>
            </p>

Here is what I would like to do in my controller:

    [AcceptVerbs(HttpVerbs.Post), Authorize]
    public ActionResult Edit(int id, FormCollection collection)
    {
        ...

        article.Title = collection["Title"];
        article.Body = collection["Body"];
        article.BodyHtml = collection["BodyHtml"];

        ...
    }

Any ideas on how to make this happen would be much appreciated!

Bowfin answered 6/7, 2009 at 23:29 Comment(1)
Doesn't StackOverflow do something similar to this?Bowfin
T
11

I'm using Markdown.NET library for this. Using this library you can convert Markdown markup on the server side. It is very simple:

[AcceptVerbs(HttpVerbs.Post), Authorize]
public ActionResult Edit(int id, FormCollection collection)
{
    ...

    article.Title = collection["Title"];
    article.Body = collection["Body"];

    var bodyHtml = new anrControls.Markdown().Transform(collection["Body"]);

    article.BodyHtml = bodyHtml;

    ...
}

Hope this helps

Tibbitts answered 7/7, 2009 at 9:36 Comment(1)
That Markdown.NET library is quite old now (not updated since Nov 2004). Are you aware of a newer version, or is that version still the definitive one?Bullfighter

© 2022 - 2024 — McMap. All rights reserved.