How to insert the non breaking space entity  ?

Hi,

when I try to insert the   character in the content by clicking a command button, it is displayed as a string in the text. I’m using Transaction.insertText(' ', from).

How can I insert it as the true   entity ?

thank you

What I ended up doing is to take the CP value (found on the unicode homepage) for all of our special chars and insert it with a little helper. This seems to do the trick.

const cp = '00A0';
const tr = view.state.tr;
const d = document.createElement('span');
d.innerHTML = '&#x' + cp;
tr.insertText(d.textContent);
view.dispatch(tr);

It works great ! thank you.

ProseMirror documents are not HTML, so just like you can’t put arbitrary tags in them, HTML entities have no meaning there.

Or you could just directly put it in a string like "\u00a0". Going through the DOM to convert a character code to a character seems unnecessary.

1 Like