Please add the support for Outline to Headings Tag of Html's Conversion

1 Answer 119 Views
WordsProcessing
Xu
Top achievements
Rank 1
Xu asked on 27 Aug 2021, 01:51 PM

Dear Telerik Developers,

 

Since the Xamarin Platform realize the Rich Text Editor by a webview control, I have to convert my Rtf files into html format before loading.

According to the Html Conversion document, headings ( h1 - h6 )  styles have nothing to do with the Outline Level,  and would be lost when exporting to other formats.

While in my scenario, the outline data of original Rtf document should be kept while converting back from html format to Rtf code.

My suggestion is adding a "EnableOutlineToHeadingsConversion" option to both HtmlImportSettings and  HtmlExportSettings classes, so that we can decide if the Outline level data should be converted into corresponding Headings Style ( for example, Outline Level 1 -> h1 ) and vice versa.


HtmlFormatProvider provider = new HtmlFormatProvider(); 
HtmlExportSettings exportSettings = new HtmlExportSettings(); 
  
exportSettings.BordersMinimalThickness = 1; 
exportSettings.DocumentExportLevel = DocumentExportLevel.Fragment; 
exportSettings.IndentDocument = true; 
exportSettings.EnableOutlineToHeadingsConversion = true;
 
provider.ExportSettings = exportSettings; 

 

I sincerely hope this could be taken into Telerik's developing consideration.

 

Regards,

Thank you very much. 

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Tanya
Telerik team
answered on 01 Sep 2021, 11:40 AM

Hi Xu,

We have already logged a task for this functionality on our public portal: WordsProcessing: Allow export and import of HTML heading tags (<h1>-<h6>) to and from paragraphs with Heading styles. Please, make sure to cast your vote for the implementation of the request. At this point, it is not scheduled for a particular release, thus I cannot say when it might be available. You can subscribe to track the status of the task using the Follow button on the linked item.

Hope this is useful.

Regards,
Tanya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Xu
Top achievements
Rank 1
commented on 02 Sep 2021, 08:34 AM

Hello Tanya, 

Thank you for the information and I tracked and voted for the thread.

According to the documentation, "Headings" html tags are currently exported as styled paragraph. 

Is it possible to analyze the html code to find out the headings paragraphs by specific style?

 

Tanya
Telerik team
commented on 03 Sep 2021, 04:07 PM

Hi Xu,

In the HTML, such paragraphs are exported with the TelerikHeadingCSS class where N refers to the specific level.

However, if you would like to detect them after importing the HTML into a RadFlowDocument instance, these styles are resolved as local properties and you would need to check these properties and not the style name. Here is an example of how you could detect a heading paragraph according to the foreground applied to it:

System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF2F5496");
ThemableColor themableColor = new ThemableColor(color);
foreach (Paragraph paragraph in this.document.EnumerateChildrenOfType<Paragraph>())
{
    Telerik.Windows.Documents.Flow.Model.Styles.Core.IStyleProperty<ThemableColor> foregroundColor = paragraph.Properties.ParagraphMarkerProperties.ForegroundColor;
    if (foregroundColor.HasLocalValue && foregroundColor.LocalValue.Equals(themableColor))
    {
        // The paragraph has heading foreground
    }
}

Hope this will help you achieve the desired goal.

Xu
Top achievements
Rank 1
commented on 04 Sep 2021, 02:00 AM

Thank you Tanya, for your outstanding explanation,

By your sample code , it seems that heading foreground can be detected, but levels can not.

But I guest writing a regex to replace TelerikHeadingNCSS with corresponding tag properties ( backgroundcolor might be a choice, from TelerikHeading1 - #FF2F5491  to  TelerikHeading6 - #FF2F5496), and detecting specified background colors after the conversion could be a solution.

I'll try it out.

 

Regards,

 

Tanya
Telerik team
commented on 08 Sep 2021, 11:52 AM

Hi Xu,

I couldn't think of something that could potentially block you from doing that. I hope this approach will fit your needs.

Xu
Top achievements
Rank 1
commented on 09 Sep 2021, 01:54 AM

Thank you Tanya, I accepted your reply as the answer and really appreciate it.

 

Regards

Xu
Top achievements
Rank 1
commented on 12 Sep 2021, 03:11 PM

Hello Yana, to provide the best compatibility of multiplatform experience, I am using the original RichTextEditor for Uwp, and Telerik's Xamarin RichTextEditor to reading rtf format files.

After quite a lot of effort, I was able to covert the TelerikHeadingN class to RadFlowDocument with Outline levels, but found the outline data can only be saved for docx files, is there any possibility to keep the outline levels for rtf files ?

As we all know the rtf format does support outline levels.

Tanya
Telerik team
commented on 14 Sep 2021, 10:54 AM

Hi Xu,

I have just tested to convert a DOCX document with heading styles to RTF and it seems like everything is converted as expected. The headings have been imported from the DOCX into a RadFlowDocument and successfully preserved in the RTF document. Can you share more details on the scenario you have? Is there something I am missing?

Tags
WordsProcessing
Asked by
Xu
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or