Richtext set allow html tags

Hello everyone,

I have implemented the richtext editor from you and I send the content to an interface to the backend of our application. This interface checks the content (alos the string) against an XML schema, which only allows the following HTML tags without style attributes:

* <p>
* <strong>
* <h4>
* <em>
* <ul>
* <ol>
* <li>
* <dl>
* <dt>
* <dd>

Is there a way to tell the component to use only the HTML tags listed above?

3 Replies

VJ Vinitha Jeyakumar Syncfusion Team February 7, 2024 07:38 AM UTC

Hi Denis Kirchner,


Your requirement to restrict some set of HTML tags from the RichTextEditor can be achieved by using the beforeSanitizeHtml event arguments, where you can add the tags which you want to avoid within the Editor and also to restrict Html tags while pasting contents into the Editor can be achieved by using the deniedTags property in pasteCleanupSettings. Please check the code and  sample below,


Code snippet:

<ejs-richtexteditor
    id="defaultRTE"
    (beforeSanitizeHtml)="beforeSanitizeHtml($event)"
    [pasteCleanupSettings]="pasteCleanupSettings"
  >
  </ejs-richtexteditor>

 public beforeSanitizeHtml(args) {
// here we have denied <a> tag for your example and you can add all the tags here to restrict like below,
    args.selectors.tags.push('a');
  }
  public pasteCleanupSettingsPasteCleanupSettingsModel = {
    prompt: false,
    deniedTags: ['a''img'],
    keepFormat: true,
    plainText: false,
  };






Regards,
Vinitha




DK Denis Kirchner February 8, 2024 01:49 PM UTC

Hello  Vinitha ,

thank you for your quick reply and for your code example. I will try it out in the next few days. If it doesn't work, I will share the code of the shared component (in coordination with the team).


Best regards

Denis



VJ Vinitha Jeyakumar Syncfusion Team February 9, 2024 04:37 AM UTC

Hi Denis Kirchner,



Sure, We will wait until we get an update from you.


Regards,

Vinitha


Loader.
Up arrow icon