保存WMD编辑器控件的内容

编程入门 行业动态 更新时间:2024-10-11 05:21:16
本文介绍了保存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.

您会在找到很多这样的东西 en.wikipedia/wiki/Markdown#Converters 和 markdown.infogami/

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

在您的情况下,我反对使用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编辑器控件的内容

本文发布于:2023-11-07 19:12:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567189.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   控件   内容   WMD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!