onizet / html2openxml

Html2OpenXml is a small .Net library that convert simple or advanced HTML to plain OpenXml components. This program has started in 2009, initially to convert user's comments into templated Word.
MIT License
313 stars 107 forks source link

Nested List Numbering Not Working #11

Closed onizet closed 2 months ago

onizet commented 6 years ago

[copied from codeplex]

I am currently trying to convert an HTML with ordered lists that is like this:

<ol>
    <li>&nbsp;Prior to Visit:
        <ul>
            <li>Site Personal Protective Equipment Requirements</li>
            <li>Review Network Diagram</li>
            <li>Review Asset Inventory</li>
        </ul>
    </li>
    <li>&nbsp;On-Site
        <ul>
            <li>Physically Inspect Computer Systems
                <ol>
                    <li>Understand Network Connection</li>
                    <li>Removable Media Controls</li>
                </ol>
            </li>
            <li>Request the following information, per device
                <ol>
                    <li>Operating System or Firmware Version
                        <ul style="list-style-type: square;">
                            <li>Patching Cadence</li>
                        </ul>
                    </li>
                    <li>Primary ICS Applications &amp; Versions</li>
                    <li>Host Based Protection &amp; Version
                        <ul style="list-style-type: square;">
                            <li>Last Signature Update Date</li>
                        </ul>
                    </li>
                    <li>Services &amp; Open Ports</li>
                    <li>User Accounts
                        <ul style="list-style-type: square;">
                            <li>Last Log-on</li>
                            <li>Last Password Change</li>
                        </ul>
                    </li>
                    <li>Firewall Configuration</li>
                    <li>Log Management Configuration</li>
                </ol>
            </li>
            <li>Passive Wireless Scanning Site Perimeter</li>
            <li>Understand Any Additional Controls or Technology</li>
        </ul>
    </li>
</ol>

When in the browser it numbers correctly for order list under "Request the following information, per device". However when converted, it puts all child items in the order list as just a bullet. I have removed the sub child items that had the unique styling, and this did not have any effect. Has anyone else seen this? Is there a solution as to how to get order lists to use numbering when converted in a nested list?

Thanks James

onizet commented 6 years ago

Hi Paul,

After your message, I take a fresh look on the code. I wrote this code so many years ago and I don't remember exactly the reason 😞

The fact that it's the half (or roughly) makes me think that due to level not starting at 0 but 1, the snippet avoids a special condition for the 1st level which mustn't have an indentation.

I did a try with:

prop.Indentation = level < 2? null : new Indentation() { Left = (level * 780).ToString(CultureInfo.InvariantCulture) }

and this seems ok. Note, since latest commit, I now push missing styles... including ListParagraph. So this ease also the Indentation (so to respond to your question, yes the style can also influence the indentation). I drop Hanging property which doesn't seem necessary.

I have committed that version. Feel free to come back if you found a better test case that fails. Thanks!


De : Paul Bentley notifications@github.com Envoyé : jeudi 4 janvier 2018 16:17:20 À : onizet/html2openxml Cc : Olivier Nizet; Mention Objet : Re: [onizet/html2openxml] Nested List Numbering Not Working (#11)

Hi @onizethttps://github.com/onizet,

Related to this - I notice that lists don't have an initial indent as they would if created in Word directly.

I just wondered if this was by design?

You have Hanging = "357", Left = (level 357) - in Word directly this would be Hanging = "360", Left = (level 720) to give an initial indentation from level 1.

Unless there is another way to have the initial indentation?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/onizet/html2openxml/issues/11#issuecomment-355308334, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AGZInEippJT_14wVqkK44witLZ43iSSFks5tHOuAgaJpZM4QBUY7.

taishmanov commented 6 years ago

I face some issues when converting such a nested numbered list. `

  1. Issue 1 solutions
    1. Solution 1
    2. Solution 2
  2.     <li>
            Issue 2 solutions
            <ol start="3" style="list-style-type: lower-roman;">
                <li>Solution X</li>
                <li>Solution XX</li>
                <li>Solution asdf</li>
            </ol>
        </li>
        <li>
            Issue 3 solutions
            <ol start="6" style="list-style-type: lower-roman;">
                <li>some solution</li>
            </ol>
        </li>
    </ol>`

    Issues:

    1. Roman style is not applied for the 2nd, 3rd nested lists.
    2. Then after the 2nd nested list numbering is destroyed.

    I found some bugs on leveling, but I couldn't resolve it. How to keep level styles and numbering according to "start" attribute?

    Thanks Baur

onizet commented 6 years ago

Hello Baur,

I'm afraid that the startattribute is not supported but any PR is welcome :-)

In BeginList, you can see that I force the list to restart to 1 (StartOverrideNumberingValue). You can additionally check for the existence of the start attribute and acts accordingly. https://github.com/onizet/html2openxml/blob/f227f35f4f91b089855ceec7ddbd9e3fbe388883/src/Html2OpenXml/Collections/NumberingListStyleCollection.cs#L209

onizet commented 2 months ago

This is now supported in v3. Thanks for having shared with me this attribute.