“All it takes to turn a grouchy Experience Editor Friendly is a little TLC.” – Mr. Rogers

♬ It’s a beautiful day in the Experience Editor, A beautiful experience for an author, since we’re together, we might as well say, won’t you be my Content Author?

Hi, Sitecore Neighbor, I’m glad we’re together again… discussing new cool ways we can help provide the friendliest authoring experience an author can have while using Sitecore’s Experience Editor! Continue reading ““All it takes to turn a grouchy Experience Editor Friendly is a little TLC.” – Mr. Rogers”

Editor Enhancement Toolkit: Module Overview

The module formally known as “Enhance the Editor Experience” is now known as the “Editor Enhancement Toolkit”; it has been refactored and includes cool new features. The source can be downloaded from GitHub and the module is available on Sitecore’s Marketplace.

The “Editor Enhancement Toolkit” is based on my “MySpace the Content Editor” blog trilogy. The concepts are similar but the code, features, and approach have improved.

What benefits does this module provide you and your Sitecore implementation?

The module was initially created as a tool to improve a content author’s experience editing content in the Content Editor as well as the Experience Editor. It’s useful in disguising architectural mistakes, but shouldn’t be used as an excuse to purposely make poor decisions. Continue reading “Editor Enhancement Toolkit: Module Overview”

Handling Image Dimensions in the Richtext Editor

Something odd happens when an image is added in the rich text editor. Initially, when the image is inserted, the RTE places the width and height properties correctly. However, when we change the properties such as adding a class, the dimensions are now inline styled. Inline styling dimensions isn’t responsive friendly.

Clients should not be expected to edit the HTML. So how do we resolve this issue?

When the client is making changes in the RTE we can fire off code to alter the HTML when the RTE is closed. We can accomplish this by utilizing the saveRichTextContent pipeline.

For content items that haven’t been modified after the new pipeline has been added, we can create a new renderField pipeline.

First we create the code to cycle through the images in the HTML and modify the inline styles.

using System;
using System.Linq;
using HtmlAgilityPack;

namespace Company.Library.Pipelines.RichTextContent
{
    public static class RichText
    {
        public static string Content(string content)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(content);

            if (!doc.DocumentNode.Descendants("img").Any())
                return content;

            foreach (var img in doc.DocumentNode.Descendants("img"))
            {
                var imgAttr = img.Attributes["style"];

                if (imgAttr == null)
                    continue;

                var alteredStyles = string.Empty;
                var inlineStyleList = imgAttr.Value.Split(';');
                var removeImageDimensions = Settings.GetBoolSetting("RTE.Images.RemoveImageDimensions", false);

                foreach (var style in inlineStyleList)
                {
                    var attrList = style.Split(':');

                    if (!attrList.Count().Equals(2))
                        continue;

                    var property = attrList[0].Trim();
                    var val = attrList[1].Trim();

                    if ((property.Equals("width", StringComparison.InvariantCultureIgnoreCase) ||
                        property.Equals("height", StringComparison.InvariantCultureIgnoreCase)) && !removeImageDimensions)
                        img.Attributes.Add(property, val);
                    else
                        alteredStyles += string.Format("{0}:{1}; ", property, val);
                }

                imgAttr.Remove();

                if (!string.IsNullOrWhiteSpace(alteredStyles))
                    img.Attributes.Add("style", alteredStyles);
            }

            return doc.DocumentNode.OuterHtml;
        }
    }
}

saveRichTextContent Pipeline

using Sitecore.Shell.Controls.RichTextEditor.Pipelines.SaveRichTextContent;

namespace Company.Library.Pipelines.RichTextContent
{
    public class Save
    {
        public void Process(SaveRichTextContentArgs args)
        {
            args.Content = RichText.Content(args.Content);
        }
    }
}
Before:
<img style="width: 200px; height: 200px; border: solid 3px #000;" alt="" src="/someimage.png" />
After:
<img width="200" height="200" style="border: solid 3px #000;" alt="" src="/someimage.png" />

Config Settings

Create a custom config file in the App_Config/Include folder if you haven’t done so and add the following:

  
    	 	 
   	 	 
      	 	 
          	 	 
      	 	 
      	 	 
         	 	 
             	 	 
         	 	 
      	 	 
   	 	 


Video Demo


Do you enjoy my oddly themed blogs and wish you had access to even more of me and my ideas? Good news, you’re in luck!

If 140 characters is your thing, follow me on Twitter.


If you hate reading and watching Sitecore videos entertains you, head over to my YouTube channel! Sometimes I entertain, sometime I provide useful Sitecore information and sometimes I can do both in the same video.


I can also be found hanging out on the Sitecore channels on Slack, I like it, although it occasionally triggers AOL chat room flashbacks from the olden days.


You can also find me adding content on LinkedIn and on Reddit.