Customizing rich text fields in Sitecore on accept action


Post process rich text field values entered by content authors when the RTE ‘Accept’ action is triggered (Sitecore 6.5).


Sitecore provides a Rich Text Field which basically lets the content author use either the inbuilt rich text editor or pure HTML to insert rich text content in a given item.

In some scenarios we might want to have some level of control over the entered text programmatically. The following snippet gives you access to the text entered by the content author, when they click on accept from the rich text editor and lets you parse it and then replace the entered text with your processed text.

Please note, the pipeline in use here is not used if the content author uses the ‘Edit Html’ action from the RTF straight up!


But do note that you can edit Html even from the rich text editor itself!



Really the only important thing here is to use the right pipeline, provide accurate assembly / class names and use the right method signature in the class!

Here is the configuration update to add to the saveRichTextContent pipeline.

        	<processor type="Sitecore.Shell.Controls.RichTextEditor.Pipelines.SaveRichTextContent.EmbedInParagraph, Sitecore.Client" />
        	<processor type="Mysite.Global.Classes.SaveRelativeLinks, Mysite" />

Since the content of a rich text editor is primarily Html, you could use the HtmlAgilityPack to access html nodes with ease. In the below example, we are looping to every anchor tag in the rich text field and we could possibly transform it or even remove the anchor tag if the href url didn’t pass through certain filters!

    public class SaveRelativeLinks
        public void Process(SaveRichTextContentArgs args)
            // Load the HTML into the HtmlAgilityPack
            var doc = new HtmlDocument { OptionWriteEmptyNodes = true };

            // Search for all links
            var aTags = doc.DocumentNode.SelectNodes("//a");
            if (aTags == null || aTags.Count == 0)

            foreach (var node in aTags)
                if (node.Attributes["href"] != null
                    && !string.IsNullOrEmpty(node.Attributes["href"].Value))
                    // perform any logic you'd want on the node here!
                    // ...
                    // ...
            // Replace the Rich Text content with the modified content
            args.Content = doc.DocumentNode.OuterHtml;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s