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()) {