You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-08 21:42:24 +03:00
Only send HTML when using RTE when necessary
When there are no styled blocks or inline styles applied within blocks, just send text instead of HTML. Also, don't add <br /> for the last <p> (the last block). Fixes https://github.com/vector-im/riot-web/issues/3147
This commit is contained in:
@@ -85,7 +85,6 @@ export function charactersToImageNode(alt, useSvg, ...unicode) {
|
||||
|
||||
|
||||
export function processHtmlForSending(html: string): string {
|
||||
|
||||
const contentDiv = document.createElement('div');
|
||||
contentDiv.innerHTML = html;
|
||||
|
||||
@@ -94,10 +93,14 @@ export function processHtmlForSending(html: string): string {
|
||||
}
|
||||
|
||||
let contentHTML = "";
|
||||
for (let i=0; i<contentDiv.children.length; i++) {
|
||||
for (let i=0; i < contentDiv.children.length; i++) {
|
||||
const element = contentDiv.children[i];
|
||||
if (element.tagName.toLowerCase() === 'p') {
|
||||
contentHTML += element.innerHTML + '<br />';
|
||||
contentHTML += element.innerHTML;
|
||||
// Don't add a <br /> for the last <p>
|
||||
if (i !== contentDiv.children.length - 1) {
|
||||
contentHTML += '<br />';
|
||||
}
|
||||
} else if (element.tagName.toLowerCase() === 'pre') {
|
||||
// Replace "<br>\n" with "\n" within `<pre>` tags because the <br> is
|
||||
// redundant. This is a workaround for a bug in draft-js-export-html:
|
||||
|
||||
Reference in New Issue
Block a user