diff --git a/app/assets/javascripts/discourse/lib/utilities.js.es6 b/app/assets/javascripts/discourse/lib/utilities.js.es6 index a1765cf9c6c..07ada98d4c5 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js.es6 +++ b/app/assets/javascripts/discourse/lib/utilities.js.es6 @@ -102,8 +102,10 @@ export function selectedText() { $div.find("img.emoji").replaceWith(function() { return this.title; }); // replace br with newlines $div.find("br").replaceWith(() => "\n"); + // enforce newline at the end of paragraphs + $div.find("p").append(() => "\n"); - return String($div.text()).trim(); + return String($div.text()).trim().replace(/(^\s*\n)+/gm, "\n"); } // Determine the row and col of the caret in an element