- Understanding Paste Options in the Prompt Dialog
- How to Paste as Plain Text
- Maintaining Formatting with Keep Format Option
- Cleaning Formatting During Paste
- Managing Denied Tags for Paste Cleanup
- Configuring Denied Attributes in Paste Settings
- Allowing Specific Style Properties for Pasted Content
- Manual Customization of Pasted Content
Contact Support
Paste Cleanup in ASP.NET CORE Rich Text Editor Control
4 Mar 202510 minutes to read
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:
API | Description | Default Value | Type |
---|---|---|---|
prompt | Invokes a prompt dialog with paste options when pasting content into the editor | false | boolean |
plainText | Paste the content as plain text | false | boolean |
keepFormat | Maintains the same format as the copied content | true | boolean |
deniedTags | Ignores specified tags when pasting HTML content | null | string[] |
deniedAttrs | Filters out specified attributes from the pasted content | null | string[] |
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[] |
Understanding Paste Options in the Prompt Dialog
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:
-
Keep
: Maintains the same format as the copied content. -
Clean
: Clears all style formats from the copied content. -
Plain Text
: Pastes the copied content as plain text without any formatting or style. (including the removal of all tags).
When
prompt
value is set true, the API properties plainText and keepFormat will not be considered for processing when pasting the content.
How to Paste as Plain Text
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.
When
plainText
is set to true, setprompt
to false. ThekeepFormat
property will not be considered.
Maintaining Formatting with Keep Format Option
When keepFormat
is set to true, the copied content maintains all style formatting allowed in the allowedStyleProps
when pasted into the editor.
If keepFormat
is set to false, all styles in the copied content are removed, regardless of the allowedStyleProps
settings.
When
keepFormat
is set to true, set bothprompt
andplainText
to false.
Cleaning Formatting During Paste
Setting cleanFormat
to true removes all applied styles from the pasted content while retaining all other HTML tags in the editor.
When
cleanFormat
is set to true, setprompt
,plainText
, andkeepFormat
to false.
Managing Denied Tags for Paste Cleanup
When deniedTags
values are set, the specified tags will be removed from the pasted content. For example,
-
'a'
: Removes all anchor tags. -
'a[!href]'
: Removes anchor tags without the ‘href’ attribute. -
'a[href, target]'
: Removes anchor tags with both ‘href’ and ‘target’ attributes.
Configuring Denied Attributes in Paste Settings
When deniedAttrs
values are set, the specified attributes will be removed from all tags in the pasted content. For example,
'id', 'title'
: Removes ‘id’ and ‘title’ attributes from all tags.
Allowing Specific Style Properties for Pasted Content
By default, the following basic styles are allowed on pasting the content to the editor.
[‘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’]
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.
For Example,
allowedStyleProps: ['color', 'margin']'
: This will allow only the style properties ‘color’ and ‘margin’ in each pasted element.
<ejs-richtexteditor id="pasteCleanup" showCharCount="true" maxLength="1000" value="@ViewBag.value">
<e-richtexteditor-pastecleanupsettings Prompt="true"></e-richtexteditor-pastecleanupsettings>
</ejs-richtexteditor>
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.value = @"<p>RichTextEditor is a WYSIWYG editing control which will reduce the effort for users while trying to express their formatting word content as HTML format.</p>
<p><b>Paste Cleanup properties:</b></p>
<ul>
<li>
<p>prompt - specifies whether to enable the prompt when pasting in Rich Text Editor.</p>
</li>
<li>
<p>plainText - specifies whether to paste as plain text or not in Rich Text Editor.</p>
</li>
<li>
<p>keepFormat- specifies whether to keep or remove the format when pasting in Rich Text Editor.</p>
</li>
<li>
<p>deniedTags - specifies the tags to restrict when pasting in Rich Text Editor.</p>
</li>
<li>
<p>deniedAttributes - specifies the attributes to restrict when pasting in Rich Text Editor.</p>
</li>
<li>
<p>allowedStyleProperties - specifies the allowed style properties when pasting in Rich Text Editor.</p>
</li>
</ul>";
return View();
}
}
Manual Customization of Pasted Content
The Rich Text Editor enables the customization of copied content prior to pasting it into the editor. By configuring the afterPasteCleanUp event, users can exercise precise control over formatting and content modifications after the paste action is executed.
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.
<ejs-richtexteditor id="pasteCleanup" showCharCount="true" maxLength="1000" value="@ViewBag.value" afterPasteCleanup="afterPasteCleanup">
<e-richtexteditor-pastecleanupsettings Prompt="true"></e-richtexteditor-pastecleanupsettings>
</ejs-richtexteditor>
<script>
function afterPasteCleanup(args){
const divElement = document.createElement('div');
divElement.innerHTML = args.value;
const pasteCleanupImage = divElement.querySelector('.pasteContent_Img');
if (pasteCleanupImage) {
ej.base.detach(pasteCleanupImage);
args.value = divElement.innerHTML;
}
}
</script>
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.value = @"<p>RichTextEditor is a WYSIWYG editing control which will reduce the effort for users while trying to express their formatting word content as HTML format.</p>
<p><b>Paste Cleanup properties:</b></p>
<ul>
<li>
<p>prompt - specifies whether to enable the prompt when pasting in Rich Text Editor.</p>
</li>
<li>
<p>plainText - specifies whether to paste as plain text or not in Rich Text Editor.</p>
</li>
<li>
<p>keepFormat- specifies whether to keep or remove the format when pasting in Rich Text Editor.</p>
</li>
<li>
<p>deniedTags - specifies the tags to restrict when pasting in Rich Text Editor.</p>
</li>
<li>
<p>deniedAttributes - specifies the attributes to restrict when pasting in Rich Text Editor.</p>
</li>
<li>
<p>allowedStyleProperties - specifies the allowed style properties when pasting in Rich Text Editor.</p>
</li>
</ul>";
return View();
}
}