What would be the best practise to ensure that every table added by an editor in any HTML property got decorated with a couple of CSS classes?
From what I understand there's no way to get editor.css to expose more than one class name to a selectable style, and in my case I need three different classes.
Is this even possible to handle by code without to much work or should the approach instead be to try to adjust the CSS-framework used in order to combine the different classes in one?
*bump* due to massive spam in older threads
Thank you for the feedback!
Then could you use HtmlAgilityPack to parse the XHtmlString, select all tables without any classes and add these classes (you could cache this too)? Then instead of using Html.PropertyFor(m => m.CurrentPage.Text), you would use Html.PropertyFor(m => m.ReplacedText).
You would also add a connection for edit mode between Text and ReplacedText.
It would look something like this (untested):
private static XhtmlString AddClassesToTables(XhtmlString xhtmlString)
var doc = new HtmlDocument();
var tablesWithoutClasses = doc.DocumentNode.SelectNodes("//table[not(@class)]");
if (tablesWithoutClasses != null && tablesWithoutClasses.Any())
foreach (var table in tablesWithoutClasses)
table.Attributes.Add("class", "one two three");
var outerHtml = doc.DocumentNode.OuterHtml;
return new XhtmlString(outerHtml);
You would need this: https://www.nuget.org/packages/HtmlAgilityPack
In controller, you would add:
var editHints = ViewData.GetEditHints<TextPageViewModel, TextPage>();
editHints.AddConnection(m => m.ReplacedText, page => page.Text);
I will give it a try. Thank you very much! :)