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);
});
Fiddle.
However, I still have no clue on how to make a paragraph starting with >
wrapped into <blockquote>
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…