diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js
index a32d05e4ff..ee679391cc 100644
--- a/src/HtmlUtils.js
+++ b/src/HtmlUtils.js
@@ -84,7 +84,8 @@ export function charactersToImageNode(alt, useSvg, ...unicode) {
}
-export function stripParagraphs(html: string): string {
+export function processHtmlForSending(html: string): string {
+
const contentDiv = document.createElement('div');
contentDiv.innerHTML = html;
@@ -97,6 +98,13 @@ export function stripParagraphs(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 "\n" within `
` tags because the
is + // redundant. 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(/'; } else { const temp = document.createElement('div'); temp.appendChild(element.cloneNode(true)); diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index b05beb2571..aa6f3f2ac5 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -507,7 +507,7 @@ export default class MessageComposerInput extends React.Component { } if (this.state.isRichtextEnabled) { - contentHTML = HtmlUtils.stripParagraphs( + contentHTML = HtmlUtils.processHtmlForSending( RichText.contentStateToHTML(contentState), ); } else {
\n/g, '\n').trim() + + '