JQuery/JS Markdown plugin?

£可爱£侵袭症+ 提交于 2019-12-18 13:34:06

问题


I'm writing a chat app, and I'd like to add some simple functionality where users use markup to affect text formatting, like bold or italics. I'm envisioning this would be like how it is done on Google Talk or StackOverflow. Does JQuery have any plugins to do this?


回答1:


stackoverflow is using WMD editor. You can use WMD editor code. It's written by javascript.

check

http://blog.stackoverflow.com/2009/01/wmd-editor-reverse-engineered/

For WMD to HTML , you can use ShowDown javascript.

Github source (include showdown.js)

http://github.com/derobins/wmd

Showdown usages

var text = "Markdown *rocks*.";
var converter = new Attacklab.showdown.converter();
var html = converter.makeHtml(text);
alert(html);



回答2:


It’s easy to use Showdown with or without jQuery. Here’s a jQuery example:

// See http://mathiasbynens.be/notes/showdown-javascript-jquery for a plain JavaScript version as well
$(function() {
 // When using more than one `textarea` on your page, change the following line to match the one you’re after
 var $textarea = $('textarea'),
     $preview = $('<div id="preview" />').insertAfter($textarea),
     converter = new Showdown.converter();
 $textarea.keyup(function() {
  $preview.html(converter.makeHtml($textarea.val()));
 }).trigger('keyup');
});



回答3:


FWIW, I wrote a jQuery Markdown Plugin that uses the Showdown converter. It is intended for use as a client-side utility when your server is serving Markdown documents - presumably organized in some meaningful directory structure.

Links to other Markdown documents and images are resolved with respect to your document base directory and document directory structure. Transclusion is also supported using {{include-this}} style tags allowing you to create meta-documents composed of smaller chunks of Markdown or raw text.

Sample usage: $(#mydiv).markdown('mybase/', 'mydir/mydoc.markdown');

Please feel free to download and use without restriction at http://plugins.jquery.com/project/markdown.



来源:https://stackoverflow.com/questions/2604576/jquery-js-markdown-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!