I have a texteditor (div) and there's a function to format the (selected)text inside it. When I mark a part of the text and chose to make it look like this
(code snippet) I have to use
to avoid some bugs and make it user-friendly. However this data is being sent to the server (nodeJS) and it causes a bug where the content splits up into an object and to avoid this issue, I wanted to replace
with a space before sending it to the server.
What I did was the following
// replace by " "
let content = $('.editor').html().replace(/( )/gi, " ");
// replace editor html
$('.editor').html(content);
// print results
console.log("html: ",$('.editor').html());
in console it displays what is expected (text : as <code>dasdasd</code>
):
html: as<span> </span><code>dasdasd</code><span> </span>
however on the serverside i got the following error:
TypeError: Cannot convert object to primitive value
then i decided to print the variable which contains the content from editor (which seems fine?):
{ posterContent: 'as<span> </span><code>dasdasd</code><span> </span>' }
Question: how can I replace
with a space without having to convert html to (string) in order to avoid this error?