This is a migrated thread and some comments may be shown as answers.

PropertiesToIgnore are ignored for list item

6 Answers 55 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 30 Mar 2020, 03:01 PM

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

Sort by
0
Dimitar
Telerik team
answered on 31 Mar 2020, 10:14 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
John
Top achievements
Rank 1
answered on 06 Apr 2020, 08:45 AM

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

0
Dimitar
Telerik team
answered on 07 Apr 2020, 08:07 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
John
Top achievements
Rank 1
answered on 08 Apr 2020, 01:39 PM

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

0
Dimitar
Telerik team
answered on 09 Apr 2020, 11:02 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
John
Top achievements
Rank 1
answered on 09 Apr 2020, 12:44 PM
That's great.  Thanks again for your help Dimitar.
Tags
RichTextBox
Asked by
John
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
John
Top achievements
Rank 1
Share this question
or