SimpleWysiwyg
This server-side class provides methods that convert data from HTML to WYSIWYG-JSON format. The data in this format can be used in the fields of the WYSIWYG type.
The data in WYSIWYG-JSON format contains the following keys:
display_value– the field content in the text form without formatting.lexical_json_value– the field content in WYSIWYG-JSON format based on the Lexical library.
note
The error messages that are returned by the methods of this server class contain links to the Lexical library documentation. Use them to get detailed information about the problem.
convertFromHtml(html)
Use this method to convert content from HTML to WYSIWYG-JSON format.
Parameter(s):
| Name | Type | Mandatory | Default value |
|---|---|---|---|
| html | String | Y | N |
Return:
| Type | Description |
|---|---|
| String | The method returns data in WYSIWYG-JSON format. |
Example:
convertFromHtml()
const sw = new SimpleWysiwyg();
const content = sw.convertFromHtml("<html><head><title></title></head><body><p>Click <a href=\"https://simpleone.ru\">here</a></p></body></html>");
convertToHtml(wysiwyg)
Use this method to convert WYSIWYG content to HTML while preserving font styles, images, tables, and links.
Parameter(s):
| Name | Type | Mandatory | Default value |
|---|---|---|---|
| wysiwyg | String | Y | N |
Return:
| Type | Description |
|---|---|
| String | The method returns the data in HTML format. |
Example:
convertToHtml()
const current = new SimpleRecord('table_name');
current.get('id');
const sw = new SimpleWysiwyg();
const html = sw.convertToHtml(current.wysiwyg_field);
current.html_field = html;
current.update();