开发者

Replace surrounding markdown tags using jQuery

开发者 https://www.devze.com 2023-03-14 13:46 出处:网络
I\'m working on a commenting system that uses Markdown and I want to have a live preview area where people can see what the final text will look like, like StackOverflow\'s editor.

I'm working on a commenting system that uses Markdown and I want to have a live preview area where people can see what the final text will look like, like StackOverflow's editor.

I'm currently using the following code to render the text inputted by the user:

$('#response_text').bind('blur keyup',function() {
$('.comment_preview').text($('#response_text').val());
$('.comment_preview').html($('.comment_preview').html().replace(/\n/g,'<br /开发者_开发知识库>').replace('* * *', '<hr />'));
});

And I don't know how to replace stuff like **text** into <b>text</b>.

If you have any suggestions I would love to hear them.

Thanks!


There is a jquery plugin that will do this for you: http://plugins.jquery.com/project/markdown


I would also recommend using a plugin for this, but to answer your question:

markdown.replace(/[*][*](.*?)[*][*]/gm,"<b>$1</b>");
0

精彩评论

暂无评论...
验证码 换一张
取 消