1

I'm trying to make a quote function on this forum I'm making, when I press quote I'm simply filling the textarea with the markdown, but the only thing is I need to prefix the markdown on each line with > so that it's a quote.

$('.quotePost').on('click', function(e) {
   let quotePostId = $(this).data('quote-id'); 
   let quoteBlock = rawMarkDown.find(x => (x.id === `quote-id-${quotePostId}`));
   console.log(quoteBlock.md);
   $('#replyBox').val(quoteBlock.md);
});

This is all I have so far.

e.g. of the quoted strings:

> > #HEY
> > 
> > This is a test!

so if I hit quote on this it would turn into

> > > #HEY
> > > 
> > > This is a test!
Shekhar Pankaj
  • 9,065
  • 3
  • 28
  • 46
Datsik
  • 14,453
  • 14
  • 80
  • 121

1 Answers1

1

you can use replace function

quoteBlock.md.replace(/^/gm, '> ')

document.getElementById('r').innerHTML = document.getElementById('t').value.replace(/^/gm, '> ');
<textarea id="t">
> > #HEY 
> > 
> > This is a test!</textarea>
<pre id='r'>
</pre>
Grundy
  • 13,356
  • 3
  • 35
  • 55