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)》中,你会发现这部分 comments :

//
// 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相关问答推荐

无法通过单击从元素获取数据

如何在不使用点击事件 bootstrap 程序模式的情况下使用弹出窗口 bootstrap 程序显示用户详细信息?

从 React 到 Node 服务器的 ajax 调用中的数据未定义

如何获取将在不提交的情况下提交的所有表单值

JSLint 错误:将调用移动到包含函数的括号中

document.querySelector 一个元素中的多个数据属性

何时执行 $(document).ready 回调?

用jquery查找div底部的位置

如何使用jQuery找到元素顶部的垂直距离(以px为单位)

jQuery淡出不显示无?

在 JQuery .trigger 上传递参数

在jQuery中添加ID?

为什么使用 jQuery on() 而不是 click()

使用 jQuery 按字母顺序对选项元素进行排序

延迟jquery悬停事件?

将多个 JavaScript 文件合并为一个 JS 文件

如何使用 jQuery 取消设置元素的 CSS 属性?

你如何记录jQuery中一个元素触发的所有事件?

如何复制 pinterest.com 的绝对 div 堆叠布局

添加到数组 jQuery