WMD降价编辑器-HTML到Markdown的转换 [英] WMD markdown editor - HTML to Markdown conversion

查看:95
本文介绍了WMD降价编辑器-HTML到Markdown的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目上使用 wmd markdown编辑器,并且有一个问题:

I am using wmd markdown editor on a project and had a question:

当我发布包含markdown文本区域的表单时,它(如预期的那样)将html发布到服务器.但是,说在服务器端验证时失败了,我需要将用户送回去编辑他们的条目,是否仍然只用markdown而不是html来填充textarea?既然我已经设置好了,那么服务器只能访问post数据(以html的形式),所以我似乎想不出办法.有任何想法吗?最好是非基于JavaScript的解决方案.

When I post the form containing the markdown text area, it (as expected) posts html to the server. However, say upon server-side validation something fails and I need to send the user back to edit their entry, is there anyway to refill the textarea with just the markdown and not the html? Since as I have it set up, the server only has access to the post data (which is in the form of html) so I can't seem to think of a way to do this. Any ideas? Preferably a non-javascript based solution.

更新:我找到了一个HTML到Markdown转换器,名为 markdownify .我想这可能是向用户显示降价促销的最佳解决方案……欢迎其他更好的选择!

Update: I found an html to markdown converter called markdownify. I guess this might be the best solution for displaying the markdown back to the user...any better alternatives are welcome!

更新2:我发现 a ,我想有一个选项可以将数据作为markdown而不是html发送到服务器.将数据简单地存储为markdown是否有不利之处?将其显示给用户(在编辑器之外)怎么办?也许最好将两个版本(html和markdown)都发布到服务器上...

Update 2: I found this post on SO and I guess there is an option to send the data to the server as markdown instead of html. Are there any downsides to simply storing the data as markdown in the database? What about displaying it back to the user (outside of an editor)? Maybe it would be best to post both versions (html AND markdown) to the server...

已解决:我可以简单地使用 php markdown 来将markdown转换为html服务器端.

SOLVED: I can simply use php markdown to convert the markdown to html serverside.

推荐答案

我建议您简单地将文本发送并存储为Markdown.这似乎是您已经解决的问题. IMO,将文本存储为Markdown会更好,因为您可以安全地剥离所有HTML标记,而不必担心格式丢失-这使您的代码更安全,因为使用XSS攻击将更加困难(尽管尽管如此仍然可能-我只是说这部分是saf er ).

I would suggest that you simply send and store the text as Markdown. This seems to be what you have settled on already. IMO, storing the text as Markdown will be better because you can safely strip all HTML tags out without worrying about loss of formatting - this makes your code safer, because it will be harder to use a XSS attack (although it may still be possible though - I am only saying that this part will be safer).

这篇关于WMD降价编辑器-HTML到Markdown的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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