From eeb1c3386827f24ef2484eb665b05000f0957852 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 28 Jun 2017 14:27:24 +0100 Subject: [PATCH] Do the less invasive fix of replacing `
\n` with `\n` but only within `
`

---
 src/HtmlUtils.js | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js
index cc302e24e5..13b3f3094f 100644
--- a/src/HtmlUtils.js
+++ b/src/HtmlUtils.js
@@ -85,11 +85,6 @@ export function charactersToImageNode(alt, useSvg, ...unicode) {
 
 
 export function processHtmlForSending(html: string): string {
-    // Replace "
\n" with "
" because the \n is redundant and causes an - // extra newline per line within `
` tags.
-    // This is a workaround for a bug in draft-js-export-html:
-    //   https://github.com/sstur/draft-js-export-html/issues/62
-    html = html.replace(/\\n/g, '
'); const contentDiv = document.createElement('div'); contentDiv.innerHTML = html; @@ -103,6 +98,14 @@ export function processHtmlForSending(html: string): string { const element = contentDiv.children[i]; if (element.tagName.toLowerCase() === 'p') { contentHTML += element.innerHTML + '
'; + } else if (element.tagName.toLowerCase() === 'pre') { + // Replace "
\n" with "
" because the \n is redundant and causes an + // extra newline per line within `
` tags.
+            // This is a workaround for a bug in draft-js-export-html:
+            //   https://github.com/sstur/draft-js-export-html/issues/62
+            contentHTML += '
' +
+                element.innerHTML.replace(/
\n/g, '\n').trim() + + '
'; } else { const temp = document.createElement('div'); temp.appendChild(element.cloneNode(true));