|
1 | 1 | --- |
2 | 2 | layout: post |
3 | | -title: Paste Cleanup in ##Platform_Name## Rich Text Editor Component |
| 3 | +title: Paste Cleanup in ##Platform_Name## Syncfusion Rich Text Editor Component |
4 | 4 | description: Learn here all about Paste Cleanup in Syncfusion ##Platform_Name## Rich Text Editor component of Syncfusion Essential JS 2 and more. |
5 | 5 | platform: ej2-asp-core-mvc |
6 | 6 | control: Paste Cleanup |
7 | 7 | publishingplatform: ##Platform_Name## |
8 | 8 | documentation: ug |
9 | 9 | --- |
10 | 10 |
|
11 | | - |
12 | 11 | # Paste Cleanup in ##Platform_Name## Rich Text Editor Control |
13 | 12 |
|
14 | | -The Rich Text Editor simplifies the conversion of Microsoft Word content to HTML format, preserving formatting and styles. The `PasteCleanup` settings property allows you to control the formatting and styles when pasting content into the editor. The following settings are available to clean up the content: |
| 13 | +The Rich Text Editor simplifies the conversion of Microsoft Word content to HTML format, preserving formatting and styles. The `pasteCleanup` settings property (see [pasteCleanupSettingsModel](https://help.syncfusion.com/cr/aspnetmvc-js2/syncfusion.ej2.richtexteditor.richtexteditor.html#Syncfusion_EJ2_RichTextEditor_RichTextEditor_PasteCleanupSettings)) allows you to control the formatting and styles when pasting content into the editor. The following settings are available to clean up the content: |
15 | 14 |
|
16 | 15 | | API | Description | Default Value | Type | |
17 | 16 | |:----------------:|:---------:|:-----------------------------:|:---------:| |
18 | | -| [Prompt](#Prompt) | Invokes a Prompt dialog with paste options when pasting content into the editor| false | boolean | |
19 | | -| [PlainText](#plain-text) | Paste the content as plain text| false | boolean | |
20 | | -| [KeepFormat](#keep-format) | Maintains the same format as the copied content| true | boolean | |
21 | | -| [DeniedTags](#denied-tags) | Ignores specified tags when pasting HTML content| null | string[] | |
22 | | -| [DeniedAttrs](#denied-attributes) | Filters out specified attributes from the pasted content| null | string[] | |
23 | | -| [AllowedStyleProps](#allowed-style-properties) | Accepts specified style attributes and removes others from the pasted content| ['background', 'background-color', 'border', 'border-bottom', 'border-left', 'border-radius', 'border-right', 'border-style', 'border-top', 'border-width', 'clear', 'color', 'cursor', 'direction', 'display', 'float', 'font', 'font-family', 'font-size', 'font-weight', 'font-style', 'height', 'left', 'line-height', 'margin', 'margin-top', 'margin-left', 'margin-right', 'margin-bottom', 'max-height', 'max-width', 'min-height', 'min-width', 'overflow', 'overflow-x', 'overflow-y', 'padding', 'padding-bottom', 'padding-left', 'padding-right', 'padding-top', 'position', 'right', 'table-layout', 'text-align', 'text-decoration', 'text-indent', 'top', 'vertical-align', 'visibility', 'white-space', 'width'] | string[] | |
| 17 | +| [Prompt](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_Prompt) | Displays a dialog box when content is pasted, allowing users to choose how the content should be inserted—either as plain text, with formatting, or cleaned HTML. | false | boolean | |
| 18 | +| [PlainText](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_PlainText) | Paste the content as plain text| false | boolean | |
| 19 | +| [KeepFormat](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_KeepFormat) | Retains the original formatting of the pasted content, including styles, fonts, and structure.| true | boolean | |
| 20 | +| [DeniedTags](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_DeniedTags) | Specifies a list of HTML tags to be removed from the pasted content, such as `<script>`, `<iframe>`, or `<style>`. Helps eliminate unwanted or unsafe elements. | null | string[] | |
| 21 | +| [DeniedAttrs](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_DeniedAttrs) | Filters out specified attributes from the pasted content| null | string[] | |
| 22 | +| [AllowedStyleProps](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_AllowedStyleProps) | Accepts specified style attributes and removes others from the pasted content| ['background', 'background-color', 'border', 'border-bottom', 'border-left', 'border-radius', 'border-right', 'border-style', 'border-top', 'border-width', 'clear', 'color', 'cursor', 'direction', 'display', 'float', 'font', 'font-family', 'font-size', 'font-weight', 'font-style', 'height', 'left', 'line-height', 'margin', 'margin-top', 'margin-left', 'margin-right', 'margin-bottom', 'max-height', 'max-width', 'min-height', 'min-width', 'overflow', 'overflow-x', 'overflow-y', 'padding', 'padding-bottom', 'padding-left', 'padding-right', 'padding-top', 'position', 'right', 'table-layout', 'text-align', 'text-decoration', 'text-indent', 'top', 'vertical-align', 'visibility', 'white-space', 'width'] | string[] | |
24 | 23 |
|
25 | | -## Understanding Paste Options in the Prompt Dialog |
| 24 | +## Paste options in the prompt dialog |
26 | 25 |
|
27 | 26 | When `Prompt` is set to true, pasting the content in the editor will open a dialog box that contains three options `Keep`, `Clean`, and `Plain Text` as radio buttons: |
| 27 | + |
| 28 | + |
| 29 | + |
28 | 30 | 1. `Keep`: Maintains the same format as the copied content. |
29 | 31 | 2. `Clean`: Clears all style formats from the copied content. |
30 | 32 | 3. `Plain Text`: Pastes the copied content as plain text without any formatting or style. (including the removal of all tags). |
31 | 33 |
|
32 | | -> When `Prompt` value is set true, the API properties [PlainText](#plain-text) and [KeepFormat](#keep-format) will not be considered for processing when pasting the content. |
| 34 | +> When `Prompt` value is set true, the API properties [PlainText](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_PlainText) and [KeepFormat](https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.RichTextEditor.RichTextEditorPasteCleanupSettings.html#Syncfusion_EJ2_RichTextEditor_RichTextEditorPasteCleanupSettings_KeepFormat) will not be considered for processing when pasting the content. |
33 | 35 |
|
34 | | -## How to Paste as Plain Text |
| 36 | +## Plain text pasting |
35 | 37 |
|
36 | 38 | Setting `PlainText` to true converts the copied content to plain text by removing all HTML tags and styles. Only the plain text is pasted into the editor. |
37 | 39 |
|
38 | 40 | >When `PlainText` is set to true, set `Prompt` to false. The `KeepFormat` property will not be considered. |
39 | 41 |
|
40 | | -## Maintaining Formatting with Keep Format Option |
| 42 | +## Keep format |
| 43 | + |
| 44 | +When `KeepFormat` is set to `true`, the pasted content retains its original formatting, including styles, fonts, and structure. However, the formatting is still subject to filtering based on the `AllowedStyleProps`, `DeniedTags`, and `DeniedAttrs` settings: |
| 45 | + |
| 46 | +* Only the style properties listed in `AllowedStyleProps` will be preserved. |
| 47 | +* Any HTML tags listed in `DeniedTags` will be removed. |
| 48 | +* Any attributes listed in `DeniedAttrs` will be stripped from the pasted content. |
41 | 49 |
|
42 | | -When `KeepFormat` is set to true, the copied content maintains all style formatting allowed in the `AllowedStyleProps` when pasted into the editor. |
| 50 | +This ensures that while the formatting is retained, it remains clean, safe, and consistent with your application's styling rules. |
43 | 51 |
|
44 | | -If `KeepFormat` is set to false, all styles in the copied content are removed, regardless of the `AllowedStyleProps` settings. |
| 52 | +>When `keepFormat` is set to true, set both `Prompt` and `PlainText` to false. |
45 | 53 |
|
46 | | ->When `KeepFormat` is set to true, set both `Prompt` and `PlainText` to false. |
| 54 | +## Clean Formatting |
47 | 55 |
|
48 | | -## Cleaning Formatting During Paste |
| 56 | +When the `Prompt`, `PlainText`, and `keepFormat` options are all set to false, the Rich Text Editor performs clean format paste cleanup. In this mode, all inline styles from the pasted content are removed, eliminating any custom or external styling. This ensures a consistent and uniform appearance within the editor. |
49 | 57 |
|
50 | | -Setting `CleanFormat` to true removes all applied styles from the pasted content while retaining all other HTML tags in the editor. |
| 58 | +Despite the removal of styling, essential structural HTML tags such as `<p>`, `<ul>`, `<table>`, and others are preserved. This maintains the original layout and semantic integrity of the content, allowing it to remain well-structured and readable.However, the formatting is still subject to filtering based on the `DeniedTags`, and `DeniedAttrs` settings: |
51 | 59 |
|
52 | | ->When `CleanFormat` is set to true, set `Prompt`, `PlainText`, and `KeepFormat` to false. |
| 60 | +- **`DeniedTags`**: Tags listed here will still be removed from the pasted content. |
| 61 | +- **`DeniedAttrs`**: Attributes listed here will also be stripped from the pasted content. |
53 | 62 |
|
54 | | -## Managing Denied Tags for Paste Cleanup |
| 63 | +> The `AllowedStyleProps` setting only applies if `KeepFormat` is enabled. |
| 64 | +
|
| 65 | +## Denied tags |
55 | 66 |
|
56 | 67 | When `DeniedTags` values are set, the specified tags will be removed from the pasted content. For example, |
57 | 68 |
|
58 | 69 | * `'a'`: Removes all anchor tags. |
59 | 70 | * `'a[!href]'`: Removes anchor tags without the 'href' attribute. |
60 | 71 | * `'a[href, target]'`: Removes anchor tags with both 'href' and 'target' attributes. |
61 | 72 |
|
| 73 | +> This setting is ignored when `PlainText` is set to `true`. <br> |
| 74 | +It only works when either `KeepFormat` is set to `true`, or when `Prompt`, `PlainText`, and `KeepFormat` are all set to `false`, which triggers clean format behavior. |
| 75 | + |
62 | 76 | ## Configuring Denied Attributes in Paste Settings |
63 | 77 |
|
64 | 78 | When `DeniedAttrs` values are set, the specified attributes will be removed from all tags in the pasted content. For example, |
65 | 79 |
|
66 | 80 | `'id', 'title'`: Removes 'id' and 'title' attributes from all tags. |
67 | 81 |
|
| 82 | +> This setting is ignored when `PlainText` is set to `true`. <br> |
| 83 | +It only works when either `KeepFormat` is set to `true`, or when `Prompt`, `PlainText`, and `KeepFormat` are all set to `false`, which triggers clean format behavior. |
| 84 | + |
68 | 85 | ## Allowing Specific Style Properties for Pasted Content |
69 | 86 |
|
70 | | -By default, the following basic styles are allowed on pasting the content to the editor. |
| 87 | +By default, a predefined set of basic style properties are allowed when content is pasted into the Rich Text Editor. |
71 | 88 |
|
72 | 89 | ['background', 'background-color', 'border', 'border-bottom', 'border-left', 'border-radius', 'border-right', 'border-style', 'border-top', 'border-width', 'clear', 'color', 'cursor', 'direction', 'display', 'float', 'font', 'font-family', 'font-size', 'font-weight', 'font-style', 'height', 'left', 'line-height', 'margin', 'margin-top', 'margin-left', 'margin-right', 'margin-bottom', 'max-height', 'max-width', 'min-height', 'min-width', 'overflow', 'overflow-x', 'overflow-y', 'padding', 'padding-bottom', 'padding-left', 'padding-right', 'padding-top', 'position', 'right', 'table-layout', 'text-align', 'text-decoration', 'text-indent', 'top', 'vertical-align', 'visibility', 'white-space', 'width'] |
73 | 90 |
|
74 | | -When you configure allowedStyleProps, the styles, which matches the ‘allowed style properties’ list are allowed, all other style properties will be removed on pasting the content in the editor. |
| 91 | +> This setting works only when `KeepFormat` is set to true. If `KeepFormat` is `false` or `PlainText` is `true`, style filtering via `AllowedStyleProps` will not be applied. |
75 | 92 |
|
76 | 93 | For Example, |
77 | 94 |
|
78 | 95 | `AllowedStyleProps: ['color', 'margin']'`: This will allow only the style properties ‘color’ and ‘margin’ in each pasted element. |
79 | 96 |
|
| 97 | +In the following example, the paste cleanup related settings are explained with its module configuration: |
| 98 | + |
80 | 99 | {% if page.publishingplatform == "aspnet-core" %} |
81 | 100 |
|
82 | 101 | {% tabs %} |
@@ -127,4 +146,4 @@ In the following example, the `AfterPasteCleanUp` event is configured to remove |
127 | 146 | {% include code-snippet/rich-text-editor/paste-cleanup-customize/controller.cs %} |
128 | 147 | {% endhighlight %} |
129 | 148 | {% endtabs %} |
130 | | -{% endif %} |
| 149 | +{% endif %} |
0 commit comments