سؤال

I have this very simple br2nl function that I use to take a string and stick it in a textarea. For some reason it's cropping some of the characters off of the ends of some of the lines. Here's my example: http://jsfiddle.net/byZnE/

In this example you will see that the "." (period) is being removed from the sentence in the textarea ("Test about information can go here."). Why is this happening and what can I change in my function to stop it?

هل كانت مفيدة؟

المحلول

This line in your code is problematic:

return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, breakTag);

What you do here is replacing both the symbol before line terminators, if it's not '>', and line terminator itself.

It's really easy to fix, though: just change it to...

return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag);

And, in my opinion, str + '' is redundant here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top