Load RTF content into HTML component

Asked

Viewed 121 times

1

I’m using the API Sceditor to make a text editor available on the page, but I need to fill it (set the value) with the contents of an RTF string. I did it this way, but it was already wrong in the quotation marks...

inserir a descrição da imagem aqui

    var textarea = document.getElementById('example');
    sceditor.create(textarea, {
        format: 'xhtml',
        style: 'minified/themes/content/default.min.css'
    });

1 answer

0


Does not work because the Sceditor plugin creates a iframe for displaying the contents of textarea. You cannot directly change the textarea, or if you do, you should also update the plugin sceditor.

To update the textarea along with the sceditor you must recover the instance that the object creates and use val() to enter the values and updateOriginal() to update the textarea DOM object:

var textarea = document.getElementById('example');
sceditor.create(textarea, {
    format : 'xhtml',
    style: 'minified/themes/content/default.min.css'
});
sceditor.instance(textarea).val("string que você quer inserir aqui");
sceditor.instance(textarea).updateOriginal(); // atualiza o DOM textarea
  • And the "Expected hexadecimal Digit" error refers to what?

  • Which editor are you using? It seems he is interpreting some string value as hexadecimal, this error occurs in the browser too?... Hexadecimals have a Unicod pattern as \uXXXX and some part of the string value must look like this pattern, for example \u82Yu (What would cause the error, because in hexadecimal there is neither Y nor u). This occurs because of backslashes which are used to escape string values.

  • Here you go a more detailed explanation. In highlight, read the part Observing.

  • The string I need to insert into wysiwyg contains RTF. I entered according to the answer, but the result was the string itself, as if wysiwyg had not interpreted the RTF.

  • Maybe you have to convert RTF text to HTML, like in Soen’s reply. I Googled it and there’s a Github library in javascript that can perform this conversion, although I have not tested.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.