使用JavaScript或jQuery自定义降价格式化文本 [英] Formatting text using custom markdown with Javascript or jQuery
问题描述
例如,用户可以添加:
**这应该是大胆的**
文本显示为粗体。或者用户在段落的开头添加>
:
> ;这可能是一个很长的段落
段落被包装在< blockquote> ;
。
请注意,我不希望它被服务器端处理。
如何使用Javascript或jQuery来做到这一点?
编辑:
我发现了一种在asterick中使用以下粗体的方法:
< div class = content>以下是粗体:**我是粗体**< / div>
jQuery:
function markdown(markdownable){
var bold = /\*\*(\S(.*?\S)?)\*\*/克;
markdownable = markdownable.replace(bold,'< span style =font-weight:bold> $ 1< / span>');
返回markdownable;
$ b $('。content')。each(function(){
var markdownable = $(this).html(),$ b $ (内容);
});
小提琴。
然而,我仍然不知道如何制作一个以> $ c $开头的段落c>包装成
< blockquote>
。
看看这个插件 markitUp!
markItUp!是一个基于jQuery库构建的JavaScript插件。它允许你把任何textarea变成一个标记编辑器。 Html,Textile,Wiki Syntax,Markdown,BBcode甚至是你自己的标记系统都可以很容易的实现。
希望这会对你有所帮助。
I run a site where users submit basic news articles. I want to add some formatting features for their submissions, quite similar to the markdown feature used here.
For example, user can add:
**This should be bold**
And the text appears bold. Or user adds >
at the beginning of the paragraph:
> This could be a lengthy paragraph
And the paragraph gets wrapped in <blockquote>
.
Note that I do not want it to be processed server-side.
How can I do this using Javascript or jQuery?
EDIT:
I found a way to make text within astericks bold using the following:
<div class="content">The following will be bold: **I am bold**</div>
jQuery:
function markdown(markdownable) {
var bold = /\*\*(\S(.*?\S)?)\*\*/gm;
markdownable = markdownable.replace( bold, '<span style="font-weight:bold">$1</span>' );
return markdownable;
}
$('.content').each(function() {
var markdownable = $(this).html(),
content = markdown(markdownable);
$(this).html(content);
});
However, I still have no clue on how to make a paragraph starting with >
wrapped into <blockquote>
.
Please have a look at this pluggin markitUp!
markItUp! is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor. Html, Textile, Wiki Syntax, Markdown, BBcode or even your own Markup system can be easily implemented.
Hope this will help you.
这篇关于使用JavaScript或jQuery自定义降价格式化文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!