Hi,
I'm having trouble getting list item ("li") element properties ignored using the HtmlFormatProvider export settings. In the following example "h1" properties are ignored correctly, but the "li" ones still come through in the output.
settings.PropertiesToIgnore["h1"].AddRange(new List<string>()
{
"margin-top", "margin-bottom"
});
settings.PropertiesToIgnore["li"].AddRange(new List<string>()
{
"margin-right", "font-family", "font-size", "color"
});
I notice, looking at HtmlDocumentExporter.ExportBlockContainer, that the call to HtmlHelper.IsPropertyForbiddenForExport passes in "value" as the propertykey rather than a css property name (see below). Is that correct or am I doing something wrong here?
this.writer.StartTag("li");
if (!HtmlHelper.IsPropertyForbiddenForExport(this.Settings, "li", "value"))
{
HtmlWriter htmlWriter = this.writer;
int listItemIndex = this.GetDocumentListForParagraph(paragraph).GetListItemIndex(paragraph);
htmlWriter.AddAttribute("value", listItemIndex.ToString());
}
Many thanks
John
6 Answers, 1 is accepted
Hello John,
This is a known issue with this functionality. It is logged on our feedback portal. You can track its progress, subscribe to status changes and add your comment to it here: RichTextBox: PropertiesToIgnore can't be used to control how the properties of a list will be exported.
Unfortunately due to the nature of the issue, I cannot provide you with a workaround.
Thank you for your understanding.
Regards,
Dimitar
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hello Dimitar,
Thanks very much for your reply. That's a shame. One of the key reasons that I picked UI for WPF was to use the two way html capability that I thought RichTextBox and the format providers offered, but it's really hard work to get around all of the edge cases where it doesn't want to do this. Do you have any recommendations for hosting a wysiwyg editor in WPF that supports native html?
Many thanks
John
Hello John,
I do not have any recommendations for other controls that you can use for this case. I was thinking of a workaround and I can suggest the following. You can use the CssClassExporting event to alter the classes before they are exported. Here is an example of this:
private void radButton_Click(object sender, RoutedEventArgs e)
{
HtmlExportSettings htmlExportSettings = new HtmlExportSettings();
HtmlFormatProvider provider = new HtmlFormatProvider();
htmlExportSettings.CssClassExporting += ExportSettings_CssClassExporting;
htmlExportSettings.StylesExportMode = StylesExportMode.Classes;
provider.ExportSettings = htmlExportSettings;
using (Stream output = File.Create(@"..\..\Sample.html"))
{
provider.Export(radRichTextBox.Document, output);
}
}
private void ExportSettings_CssClassExporting(object sender, CssClassExportingEventArgs e)
{
if (e.ClassName == "Heading1")
{
e.ClassDefinition = RemoveProperty("margin-top", e.ClassDefinition);
e.ClassDefinition = RemoveProperty("margin-bottom", e.ClassDefinition);
}
if (e.ClassName == "ListParagraph" || e.ClassName.StartsWith("li"))
{
e.ClassDefinition = RemoveProperty("margin-right", e.ClassDefinition);
e.ClassDefinition = RemoveProperty("font-family", e.ClassDefinition);
e.ClassDefinition = RemoveProperty("font-size", e.ClassDefinition);
e.ClassDefinition = RemoveProperty("background-color", e.ClassDefinition);
e.ClassDefinition = RemoveProperty("color", e.ClassDefinition);
}
Console.WriteLine(e.ClassName);
}
private string RemoveProperty(string property, string definition)
{
int propIndex = definition.IndexOf(property);
if (propIndex != -1)
{
int nextItemIndex = definition.IndexOf(';', propIndex);
int count = nextItemIndex - propIndex;
string result = definition.Remove(propIndex, count + 1);
return result;
}
return definition;
}
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hello Dimitar,
Thanks very much for putting this together. That's very helpful. In terms of order, can you say which happens first? Can you set the PropertiesToIgnore settings and then just catch the 'li' items in the event as you describe above?
Best regards
John
Hi John,
In the event handler, you will have the classes without the excluded properties. In the event handler, you will have the classes just before they are exported and you can make the final changes here.
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.