Skip to content

Commit c280d6a

Browse files
Merge pull request #650 from Syncfusion-Content/hotfix/hotfix-v31.1.17
DOCINFRA-2341_merged_using_automation
2 parents 1c7e96d + cbfd211 commit c280d6a

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed
18.7 KB
Loading

ej2-javascript/rich-text-editor/paste-cleanup.md

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: Paste cleanup in ##Platform_Name## Rich text editor control | Syncfusion
4-
description: Learn here all about Paste cleanup in Syncfusion ##Platform_Name## Rich text editor control of Syncfusion Essential JS 2 and more.
4+
description: Learn how to configure Paste Cleanup in the Syncfusion ##Platform_Name## Rich text editor control of Syncfusion Essential JS 2 and more.
55
platform: ej2-javascript
66
control: Paste cleanup
77
publishingplatform: ##Platform_Name##
@@ -11,75 +11,94 @@ domainurl: ##DomainURL##
1111

1212
# Paste Cleanup in ##Platform_Name## Rich Text Editor control
1313

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:
14+
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://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/)) allows you to control the formatting and styles when pasting content into the editor. The following settings are available to clean up the content:
1515

1616
| API | Description | Default Value | Type |
1717
|:----------------:|:---------:|:-----------------------------:|:---------:|
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[] |
18+
| [prompt](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#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 |
19+
| [plainText](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#plaintext) | Paste the content as plain text | false | boolean |
20+
| [keepFormat](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#keepformat) | Retains the original formatting of the pasted content, including styles, fonts, and structure.| true | boolean |
21+
| [deniedTags](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#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[] |
22+
| [deniedAttrs](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#deniedattrs) | Filters out specified attributes from the pasted content| null | string[] |
23+
| [allowedStyleProps](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#allowedstyleprops) | See the full list of allowed properties in the [documentation link here](https://ej2.syncfusion.com/documentation/api/rich-text-editor/#pastecleanupsettings) | string[] |
2424

2525
> Rich Text Editor features are segregated into individual feature-wise modules. To use paste cleanup, inject PasteCleanup module using the `RichTextEditor.Inject(PasteCleanup)`.
2626
2727
## Paste options in the prompt dialog
2828

2929
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:
30+
31+
![Rich Text Editor Paste options prompt dialog ](./images/richtexteditor-paste-prompt.png)
32+
3033
1. `Keep`: Maintains the same format as the copied content.
3134
2. `Clean`: Clears all style formats from the copied content.
3235
3. `Plain Text`: Pastes the copied content as plain text without any formatting or style. (including the removal of all tags).
3336

34-
> 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.
37+
> When `prompt` value is set true, the API properties [plainText](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#plaintext) and [keepFormat](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#keepformat) will not be considered for processing when pasting the content.
3538
36-
## How to paste as plain text
39+
## Plain text pasting
3740

3841
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.
3942

4043
>When `plainText` is set to true, set `prompt` to false. The `keepFormat` property will not be considered.
4144
42-
## Keep format option
45+
## Keep format
4346

44-
When `keepFormat` is set to true, the copied content maintains all style formatting allowed in the `allowedStyleProps` when pasted into the editor.
47+
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:
4548

46-
If `keepFormat` is set to false, all styles in the copied content are removed, regardless of the `allowedStyleProps` settings.
49+
* Only the style properties listed in `allowedStyleProps` will be preserved.
50+
* Any HTML tags listed in `deniedTags` will be removed.
51+
* Any attributes listed in `deniedAttrs` will be stripped from the pasted content.
52+
53+
This ensures that while the formatting is retained, it remains clean, safe, and consistent with your application's styling rules.
4754

4855
>When `keepFormat` is set to true, set both `prompt` and `plainText` to false.
4956
50-
## Cleaning formatting during paste
57+
## Clean formating
58+
59+
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.
5160

52-
Setting `cleanFormat` to true removes all applied styles from the pasted content while retaining all other HTML tags in the editor.
61+
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:
5362

54-
>When `cleanFormat` is set to true, set `prompt`, `plainText`, and `keepFormat` to false.
63+
- **`deniedTags`**: Tags listed here will still be removed from the pasted content.
64+
- **`deniedAttrs`**: Attributes listed here will also be stripped from the pasted content.
5565

56-
## Denied tags during paste
66+
> The `allowedStyleProps` setting only applies if `keepFormat` is enabled.
67+
68+
## Denied tags
5769

5870
When `deniedTags` values are set, the specified tags will be removed from the pasted content. For example,
5971

6072
* `'a'`: Removes all anchor tags.
6173
* `'a[!href]'`: Removes anchor tags without the 'href' attribute.
6274
* `'a[href, target]'`: Removes anchor tags with both 'href' and 'target' attributes.
6375

64-
## Denied attributes during paste
76+
> This setting is ignored when `plainText` is set to `true`. <br>
77+
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.
78+
79+
## Denied attributes
6580

6681
When `deniedAttrs` values are set, the specified attributes will be removed from all tags in the pasted content. For example,
6782

6883
`'id', 'title'`: Removes 'id' and 'title' attributes from all tags.
6984

85+
> This setting is ignored when `plainText` is set to `true`. <br>
86+
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.
87+
7088
## Allowing specific style properties
7189

72-
By default, the following basic styles are allowed on pasting the content to the editor.
90+
By default, a predefined set of basic style properties are allowed when content is pasted into the Rich Text Editor.
7391

74-
['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']
92+
When you configure the [allowedStyleProps](https://ej2.syncfusion.com/documentation/api/rich-text-editor/pasteCleanupSettingsModel/#allowedstyleprops) setting, only the styles that match the specified list of allowed properties will be retained. All other style properties will be removed from the pasted content.
93+
You can find the full list of allowed style properties in the [official Syncfusion documentation](https://ej2.syncfusion.com/angular/documentation/api/rich-text-editor/#pastecleanupsettings).
7594

76-
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.
95+
> 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.
7796
7897
For Example,
7998

8099
`allowedStyleProps: ['color', 'margin']'`: This will allow only the style properties ‘color’ and ‘margin’ in each pasted element.
81100

82-
In the following example, the paste cleanup related settings are explained with its module configuration:
101+
In the following example, the paste cleanup related settings are explained with its module configuration:
83102

84103
{% if page.publishingplatform == "typescript" %}
85104

@@ -139,9 +158,9 @@ You can get the pasted text as HTML using the [afterPasteCleanup](https://helpej
139158
{% previewsample "page.domainurl/code-snippet/rich-text-editor/get-pasted-content-cs1" %}
140159
{% endif %}
141160

142-
## Customization of pasted content
161+
## Customizing pasted content
143162

144-
The Rich Text Editor enables the customization of copied content prior to pasting it into the editor. By configuring the [afterPasteCleanUp](https://helpej2.syncfusion.com/documentation/api/rich-text-editor/#afterpastecleanup) event, users can exercise precise control over formatting and content modifications after the paste action is executed.
163+
The Rich Text Editor enables the customization of copied content prior to pasting it into the editor. By configuring the [afterPasteCleanUp](https://ej2.syncfusion.com/documentation/api/rich-text-editor/#afterpastecleanup) event, users can exercise precise control over formatting and content modifications after the paste action is executed.
145164

146165
In the following example, the `afterPasteCleanUp` event is configured to remove images from the copied content. To understand this feature better, try pasting content that includes an image into the editor.
147166

0 commit comments

Comments
 (0)