简体   繁体   中英

Markdown: Convert multiple paragraphs into blockquote?

I'm building a forum inside a Laravel 4 application. While viewing a thread, users can quote previous posts. A common feature.

Here's the basic setup I have now...

A user clicks on the quote icon above a post. The post's content is stored inside data-content, an attribute of the quote link.

<a class="quote" data-content="{{ $post->content }}" href="#">Quote</a>

Using jQuery, I populate a textarea for new posts with the data-content value:

$('.quote').click(function() {
    $('#new-post textarea').val($(this).data('content'));
});

And here lies the problem...

I would like to use Markdown's blockquote for displaying quoted data. I need to somehow add ">" to the beginning of each paragraph before populating the textarea.

Here's an example of a post and how it is stored in the DB (as you can see, there are no HTML tags etc, it is just raw paragraphs) - http://paste.laravel.com/12KO

Does anyone have any suggestions for how I can solve this?

Thanks.

I couldn't think of anything more simple than .replace("\\n\\n", ">\\n\\n")

$('.quote').click(function() {
    var quote = $(this).data('content');
    var quotedText = quote.replace("\n\n", ">\n\n");
    $('#new-post textarea').val(quotedText);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM