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));