Special symbols in wysihtml5 editor

629 views Asked by At

I use wysihtml5 editor on my site and I would like to have the following functionality - if user inserts text with special characters they are transformed to html entities.

For example, user inserts:

"Sample text, sample text, sample text ©"

I need to transform it to:

"Sample text, sample text, sample text ©"

I didn't find any information related to special symbols in editor docs. One of the method I think about is to create listener for paste event and process special characters at this step.

Could you advice what is the best way to add this functionality to the editor?

1

There are 1 answers

0
dandavis On

you can use a RegExp character range to replace() them using a dynamic function:

strNew=strOld.replace(
  /([\u00A0-\u00FF])/g,  
  function(j,a){
             return "&#" + parseInt(a.charCodeAt(0), 16) + ";" ;
  }
);

live demo : http://pagedemos.com/27w7n4n58qpk

this could be applied from the string you get back from your editor, or i guess, on the innerHTML of the editor's contenteditable tag.