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.

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

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

推荐答案

For Markdown -> HTML, there is Showdown

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

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

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


实际上,如果你仔细看看《决战》,在它的《源代码(file showdown.js)》中,你会发现这部分评论:

//
// 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语法,但应该很容易集成到您的应用程序中;-)


关于纺织品,似乎很难找到有用的东西:-(


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

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...

Jquery相关问答推荐

使用jquery将外部代码插入div

虽然未定义变量 - 等待

是否可以在 beforeunload 弹出窗口中显示自定义消息?

如何在 ReactJS 中使用 JQuery

如何禁用在div内单击

Flask,如何为ajax调用返回成功状态码

Twitter Bootstrap css 类的 jQuery show() 隐藏

lodash debounce 在匿名函数中不起作用

调用 e.preventDefault() 后提交表单

具有动态大小图像的马赛克网格画廊

试图检测浏览器关闭事件

如何获取 jQuery 下拉值 onchange 事件

即时替换 css 文件(并将新样式应用于页面)

jquery更改div类的样式属性

将变量的值复制到另一个

如何在 jquery 中切换 attr()

模态中的 Bootstrap 3 和 Youtube

错误“找不到 jquery-2.0.2.min.map”

如何检测 window.print() 完成

如何为基本身份验证发送正确的授权标头