editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

renderFromHTML removes <br> tags

Open CedricHildbrand opened this issue 1 year ago • 3 comments

renderFromHTML function doesn't seem to keep BR-tags. Same behaviour in pasting, might not be needed for pasting but for renderFromHTML it should work IMO

It doesnt matter how the BR-tag is written in the html-string, all those examples don't work:

renderFromHTML('<p>before<br>after</p>')

renderFromHTML('<p>before<br />after</p>')

renderFromHTML('<p>before<br/>after</p>')

CedricHildbrand avatar Aug 02 '24 13:08 CedricHildbrand

Same issue here. Has anyone found a solution for that?

TomTasche avatar Aug 08 '24 11:08 TomTasche

Anything new on this on ? Or any workaround ?

thecliffparis avatar Jun 05 '25 13:06 thecliffparis

I came up with a workaround. But Oh boy is it ugly 💩

editor?.blocks.renderFromHTML(value.replaceAll('<br>', '##br##'));
await sleep(100);
const temp = await editor?.save()!;
for (const block of temp.blocks) {
  if (block.type === 'paragraph') {
    block.data.text = block.data.text.replaceAll('##br##', '<br>');
  }
}
editor?.blocks.render(temp);

samuba avatar Aug 28 '25 11:08 samuba