mirror of
https://github.com/element-hq/element-web.git
synced 2024-11-30 23:31:28 +03:00
Do the less invasive fix of replacing <br>\n
with \n
but only within <pre>
This commit is contained in:
parent
f73fa4b49b
commit
eeb1c33868
1 changed files with 8 additions and 5 deletions
|
@ -85,11 +85,6 @@ export function charactersToImageNode(alt, useSvg, ...unicode) {
|
|||
|
||||
|
||||
export function processHtmlForSending(html: string): string {
|
||||
// Replace "<br>\n" with "<br>" because the \n is redundant and causes an
|
||||
// extra newline per line within `<pre>` 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(/\<br\>\n/g, '<br>');
|
||||
|
||||
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 + '<br />';
|
||||
} else if (element.tagName.toLowerCase() === 'pre') {
|
||||
// Replace "<br>\n" with "<br>" because the \n is redundant and causes an
|
||||
// extra newline per line within `<pre>` tags.
|
||||
// This is a workaround for a bug in draft-js-export-html:
|
||||
// https://github.com/sstur/draft-js-export-html/issues/62
|
||||
contentHTML += '<pre>' +
|
||||
element.innerHTML.replace(/<br>\n/g, '\n').trim() +
|
||||
'</pre>';
|
||||
} else {
|
||||
const temp = document.createElement('div');
|
||||
temp.appendChild(element.cloneNode(true));
|
||||
|
|
Loading…
Reference in a new issue