mirror of https://github.com/vector-im/riot-web
Do the less invasive fix of replacing `<br>\n` with `\n` but only within `<pre>`
parent
f73fa4b49b
commit
eeb1c33868
|
@ -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 New Issue