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

How to prevent the HtmlDataProvider from loose a list definitions when importing?

1 Answer 19 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 18 Mar 2018, 08:10 AM

HtmlDataProvider have Export and Import methods. When it exports a RadDocument, the output string value looks like:

<style type="text/css">
p { margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;text-indent: 0px;text-align: justify; }
body { font-family: 'Segoe UI, Lucida Sans Unicode, Verdana';font-size: 14.6666669845581px;color: #000000; }
.Normal { telerik-style-type: paragraph;telerik-style-name: Normal;border-collapse: collapse; }
.TableNormal { telerik-style-type: table;telerik-style-name: TableNormal;border-collapse: collapse; }
.p_6120A7F8 { telerik-style-type: local;font-family: 'Verdana';font-size: 16px;color: #000000; }
.li_8271C7C8 { telerik-style-type: local;margin-left: 24px;text-indent: 0px;font-family: 'Segoe UI, Lucida Sans Unicode, Verdana';font-size: 14.6666669845581px;color: #000000; }
.p_22D3F7F7 { telerik-style-type: local;margin-right: 0px;font-family: 'Verdana';font-size: 16px;color: #000000; }
</style>
<ol start="1" style="list-style-type:decimal">
    <li value="1" class="li_8271C7C8">
        <p class="Normal p_6120A7F8">Lorem</p>
    </li>
    <li value="2" class="li_8271C7C8">
        <p class="Normal p_22D3F7F7">Ipsum</p>
    </li>
    <li value="3" class="li_8271C7C8">
        <p class="Normal p_22D3F7F7">Dolor</p>
    </li>
    <li value="4" class="li_8271C7C8">
        <p class="Normal p_22D3F7F7">Sit</p>
    </li>
    <li value="5" class="li_8271C7C8">
        <p class="Normal p_22D3F7F7">Amet</p>
    </li>
    <li value="6" class="li_8271C7C8">
        <p class="Normal p_22D3F7F7">etc.</p>
    </li>
</ol>

With this settings:

var provider = new HtmlFormatProvider
{
    ExportSettings = new HtmlExportSettings
    {
        DocumentExportLevel = DocumentExportLevel.Fragment,
        StylesExportMode = StylesExportMode.Classes,
        ExportEmptyDocumentAsEmptyString = true,
        ExportLocalOrStyleValueSource = true,
        StyleRepositoryExportMode = StyleRepositoryExportMode.ExportStylesAsCssClasses,
        ExportFontStylesAsTags = true,
    },
    ImportSettings = new HtmlImportSettings
    {
        UseDefaultStylesheetForFontProperties = true,
        UseHtmlHeadingStyles = true
    }
};

 

But when I trying to Import it back, value of RadDocument doesn't contains List definitions and replace it with just simple paragraphs instead of <li> items.

How to prevent it? Crazy logic!

 

P.S.: Why not to make out CSS shorten by replace

the "margin-top: 0px;margin-right: 0px;margin-bottom: 0px;margin-left: 0px;"

with JUST one item: "margin:0"? Even "margin: 10px 10px 10px 10px" will be more compact.

And "font-family: 'Segoe UI, Lucida Sans Unicode, Verdana';font-size: 14.6666669845581px;color: #000000;"

with "font:'Segoe UI, Lucida Sans Unicode, Verdana' 14px #000" ?

And container "li" has unnecessory "p" inside it. Dirty HTML.

 

Telerik for SL version: 2018.1.116.1050

1 Answer, 1 is accepted

Sort by
0
Art
Top achievements
Rank 1
answered on 19 Mar 2018, 07:26 AM

Ok, its not about HtmlFormatProvider. I found that resulting RadDocument has no items in it's List collection and need to work with built-in ListManager instead (call GetAllDocumentLists method). It works perfect with my deep-copy engine, when merging many documents in one.

Note: all source RadDocument lists needs to be remapped with it's IDs to continious List enumeration of output RadDocument. And all paragraph ListId needs to be set with new value.

Remapping hint (_currentListId always starts with 2):

private Dictionary<int, int> CopyListDefinitions(RadDocument sourceDocument)
{
    var listManager = sourceDocument.ListManager;
    var lists = listManager.GetAllDocumentLists().ToList();
    // Old enumeration projection
    var mapping = new Dictionary<int, int>();
    // Copy lists to resulting RadDocument (merged)
    if (lists.Count > 0)
    {
        foreach (var list in lists)
        {
            mapping.Add(list.ID, _currentListId);
            var docList = sourceDocument.ListManager.GetDocumentListById(list.ID);
            if (docList != null)
            {
                var listStyle = docList.Style;
                if (string.IsNullOrEmpty(listStyle.StyleLink))
                    listStyle.StyleLink = string.Concat("ListStyle", _currentListId);
                docList = new DocumentList(listStyle, _document, _currentListId);
            }
            _currentListId++;
        }
    }
    return mapping;
}

 

Output mappind dictionary uses to replace ListId attribute value ("sourceId" -> "targetId") on copied paragraphs from source document.

Tags
RichTextBox
Asked by
Art
Top achievements
Rank 1
Answers by
Art
Top achievements
Rank 1
Share this question
or