Forum Discussion
Migrating HTML to Modern Pages - Looks great until page is edited, then content is lost
- Aug 01, 2018
The easiest way to understand what's valid HTML is to create a piece of text using all the layout and formatting options you need. Once you've that you can grab the page list item and look at the canvascontent1 field to obtain the generated HTML. You'll see that only a limited number of styles are supported and fixed set of classes for color and size information. Anything else you use can be initially displayed but will be lost during edit.
May be worth trying to add the same content via the classic UI and see if it works in the same way.
By adding it via code, you could potentially be avoiding some client side sanitizing that is applied before saving it?
Yes, it that is certainly the case.
I am finding that if I change:
<div class="{custom-class">
<table {stuff1}>
{stuff2}
</table>
</div>
to:
<div class="canvasRteResponsiveTable">
<div class="tableWrapper">
<table title="Table" {stuff1}>
{stuff2}
</table>
</div>
</div>
That my tables are now preserved.
I have also found Bert Jansen has created the following which may help: https://github.com/SharePoint/PnP-Tools/blob/master/Solutions/SharePoint.Modernization/SharePointPnP.Modernization.Framework/Transform/HtmlTransformator.cs
I'd really like to know what other edges he has found...