保存WMD编辑器控件的内容 [英] Saving contents of the WMD Editor Control

查看:84
本文介绍了保存WMD编辑器控件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现用于StackOverflow的WMD编辑器,以创建一些基本的Wiki样式的功能.我已经准备好保存到数据库了,但是我不确定应该保存什么.

I'm trying to implement the WMD editor used on StackOverflow to create some basic Wiki-style functionality. I'm up to the point where it's time to save to the database, but I'm unsure as to what I should be saving.

如果我保存生成的HTML,则可以正确地检索和显示它,但是在重新编辑时,我将面临编辑HTML而不是Markdown的麻烦.但是,如果保存Markdown,则看不到将其转换回HTML进行显示的任何方式,并且查看StackOverflow会发送浏览器HTML.

If I save the produced HTML then I can retrieve and display it correctly, but on re-edit I'm faced with editing HTML, not Markdown. However, if I save the Markdown I can't see any way of converting this back to HTML to display, and looking at StackOverflow it sends the browser HTML.

我猜我不需要同时保存两者,那么我错过了什么简单的事情?

I'm guessing that I don't need to save both, so what simple thing am I missing?

推荐答案

绝对保存用户输入的降价代码.

Absolutely save the Markdown code as entered by the user.

然后,您将需要一个Markdown转换器,将其转换为HTML以显示它.

Then you'll need a Markdown converter that will convert it to HTML for displaying it.

您会在
找到很多这样的东西 http://en.wikipedia.org/wiki/Markdown#Converters

http://markdown.infogami.com/

You'll find a bunch of these at
http://en.wikipedia.org/wiki/Markdown#Converters
and
http://markdown.infogami.com/

在您的情况下,我反对使用JS.似乎有一个 .NET实现,但我不能告诉您它的效果如何

I'd vote against using JS in your case. There appears to be a .NET implementation but I can't tell you how good it is.

呈现页面时,您必须将Markdown代码传递给上述转换器,然后输出返回的HTML.

While rendering your page you'll have to pass the Markdown code to a converter like the above and then output the returned HTML.

如果性能问题,您可能还考虑在数据库中保存Markdown代码(供以后编辑)和HTML代码(供显示).这样,它将仅转换一次.

If performance is an issue you might also consider saving both the Markdown code (for later editing) AND the HTML code (for displaying) inthe database. That way it will only be converted once.

这篇关于保存WMD编辑器控件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆