From f73fa4b49b0eb6709d6784e1ea32eb406d42fb3f Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 28 Jun 2017 11:49:50 +0100 Subject: [PATCH] Move processing into renamed function processHtmlforSending And explain why this fix is necessary --- src/HtmlUtils.js | 8 +++++++- src/components/views/rooms/MessageComposerInput.js | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js index a32d05e4ff..cc302e24e5 100644 --- a/src/HtmlUtils.js +++ b/src/HtmlUtils.js @@ -84,7 +84,13 @@ export function charactersToImageNode(alt, useSvg, ...unicode) { } -export function stripParagraphs(html: string): string { +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; diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index cca0a9899c..aa6f3f2ac5 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -507,9 +507,9 @@ export default class MessageComposerInput extends React.Component { } if (this.state.isRichtextEnabled) { - contentHTML = HtmlUtils.stripParagraphs( + contentHTML = HtmlUtils.processHtmlForSending( RichText.contentStateToHTML(contentState), - ).replace(/\\n/g, '
'); + ); } else { const md = new Markdown(contentText); if (md.isPlainText()) {