Few days back our client reported one issue where any formatting (HTML tags defined inside the MultiLine Text Field) were getting striped-out while saving the page in Experience Editor.
This was interesting as it was only happening in Experience Editor & If we save the page using Content Editor, everything was as expected.
Our research suggested that there is something happening in the CallServerSavePipeline, as it has couple of methods (GetFields, HandleFieldValue) to strip the HTML formatting.
Below is the code:
Regex regex = new Regex("<br.*/*>", RegexOptions.IgnoreCase); value = regex.Replace(value, "\r\n"); value = StringUtil.RemoveTags(value);
As you can see in the above code, first it replace all the <br /> tags with \r\n & after that calls the RemoveTags method.
With all these inputs, we confirmed with Sitecore Support that the above code is responsible for the formatting getting lost.
Sitecore support also suggested that we should use Rich Text field if we need to use the formatting in the content & stripping the HTML tags from MultiLine text field is expected behavior.
Since we have many MultiLine fields with HTML formatting, changing them to RTE was not solution.
We went ahead with another approach & override the CallServerSavePipeline :
<sitecore.experienceeditor.speak.requests> <request name="ExperienceEditor.Save.CallServerSavePipeline" type="Sitecore.ExperienceEditor.Speak.Ribbon.Requests.SaveItem.CallServerSavePipeline, Sitecore.ExperienceEditor.Speak.Ribbon"> <patch:attribute name="type"> Custom Overriden Class,Assembly </patch:attribute> </request> </sitecore.experienceeditor.speak.requests>
Inside this overridden class, we comment-out the code which was causing the loss of formatting.
// Regex regex = new Regex("<br.*/*>", RegexOptions.IgnoreCase); // value = regex.Replace(value, "\r\n"); // value = StringUtil.RemoveTags(value);
This way we were able to keep the HTML formatting inside the MultiLine text fields.
Hope this will help you!!!!!