将Markdown / Textile转换为HTML(以及理想情况下,返回Markdown / Textile)的Javascript [英] Javascript to convert Markdown/Textile to HTML (and, ideally, back to Markdown/Textile)

查看:457
本文介绍了将Markdown / Textile转换为HTML(以及理想情况下,返回Markdown / Textile)的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Markdown / Textile有几个优秀的Javascript 编辑(例如: http:// attacklab .net / showdown / ,我现在正在使用的那个),但我只需要一个Javascript函数,它可以转换Markdown / Textile - > HTML和返回的字符串。

There are several good Javascript editors for Markdown / Textile (e.g.: http://attacklab.net/showdown/, the one I'm using right now), but all I need is a Javascript function that converts a string from Markdown / Textile -> HTML and back.

这样做的最佳方式是什么? (理想情况下,它将是jQuery友好的 - 例如, $(#editor)。markdown_to_html()

What's the best way to do this? (Ideally it would be jQuery-friendly -- e.g., $("#editor").markdown_to_html())

编辑:另一种说法是我正在寻找Rails' textilize()和<$ c $的Javascript实现c> markdown()文本助手

Another way to put it is that I'm looking for a Javascript implementation of Rails' textilize() and markdown() text helpers

推荐答案

对于Markdown - > HTML,有摊牌

For Markdown -> HTML, there is Showdown

StackOverflow本身使用Markdown语言提问和答案;你试着看看它是如何工作的吗?

StackOverflow itself uses Markdown language for questions and answers ; did you try to take a look at how it works ?

好吧,似乎它正在使用 PageDown ,可在麻省理工学院许可下获得

Well, it seems it is using PageDown which is available under the MIT License

问题有没有任何好的Markdown Javascript库或控件?及其答案也可能有所帮助:-)

The question Is there any good Markdown Javascript library or control? and its answers might help, too :-)



完整的编辑当然不是你要求的;但是他们必须使用某种函数将Markdown代码转换为HTML;并且,根据这些编辑的许可,您可以重新使用该功能......


A full editor is, of course, not exactly what you asked for ; but they must use some kind of function to transform the Markdown code to HTML ; and, depending on the license of these editors, you might be able to re-use that function...

实际上,如果你仔细看看Showdown,它的代码源(文件showdown.js),你会发现这部分评论:

Actually, if you take a close look at Showdown, in its code source (file showdown.js), you'll find this portion of comment :

//
// Showdown usage:
//
//   var text = "Markdown *rocks*.";
//
//   var converter = new Showdown.converter();
//   var html = converter.makeHtml(text);
//
//   alert(html);
//
// Note: move the sample code to the bottom of this
// file before uncommenting it.
//

这不是jQuery语法,但应该很容易集成到你的应用程序中; - )

It's not jQuery syntax, but should be quite easy to integrate in your application ;-)



关于Textile,找到有用的东西似乎有点困难: - (


About Textile, it seems to be a bit harder to find anything useful :-(



另一方面,HTML - > Markdown,我想事情可能会有点困难......


In the other side, HTML -> Markdown, I guess things might be a bit harder...

我要做的是将Markdown和HTML存储在我的应用程序数据存储(数据库?)中,并使用一个进行编辑,另一个用于渲染...将占用更多空间,但似乎风险低于解密HTML。 ..

What I would do is store both Markdown and HTML in my application data store (database ? ), and use one for editing, and the other for rendering... Would take more space, but it seems less risky than "decrypting" HTML...

这篇关于将Markdown / Textile转换为HTML(以及理想情况下,返回Markdown / Textile)的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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