【问题标题】:How to retrieve BOTH the markdown and html using the wmd-editor control?如何使用 wmd-editor 控件同时检索 markdown 和 html?
【发布时间】:2010-11-08 13:08:55
【问题描述】:

我正在使用 WMD-Editor 并希望存储输入文本的 Markdown 和 HTML 版本。

我似乎只能以 Markdown 或 HTML 的形式访问输出,但不能同时访问两者。

我正在使用 ASP.NET MVC,并试图让类似下面的代码工作......只是不知道如何获取 HTML。

这是 HTML 代码的 sn-p:

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

这是我想在控制器中执行的操作:

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

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

        ...
    }

任何关于如何实现这一点的想法都将非常感谢

【问题讨论】:

  • StackOverflow 不做类似的事情吗?

标签: asp.net-mvc markdown wmd-editor


【解决方案1】:

我为此使用Markdown.NET library。使用这个库,您可以在服务器端转换 Markdown 标记。很简单:

[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;

    ...
}

希望对你有帮助

【讨论】:

  • 那个 Markdown.NET 库现在已经很老了(自 2004 年 11 月以来没有更新)。您是否知道较新的版本,或者该版本仍然是最终版本?
猜你喜欢
  • 2011-01-10
  • 2010-11-04
  • 2010-11-14
  • 2011-04-06
  • 2011-09-04
  • 2010-11-13
  • 1970-01-01
  • 2010-12-22
  • 1970-01-01
相关资源
最近更新 更多