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 from SharePoint to Word.
MIT License
297 stars 106 forks source link

UL is appearing with numbers instead of bullet markers #143

Closed PatrickKelsch closed 3 weeks ago

PatrickKelsch commented 2 months ago

Describe the bug

RFlipper commented 3 weeks ago

@PatrickKelsch I tried to reproduce the issue but failed. In my case everything is OK:

using DocumentFormat.OpenXml.Packaging;
using HtmlToOpenXml;

namespace Html2Word
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var html = """
            <ul style="list-style-type:disc"><li value="1" style="margin-top: 0px;margin-bottom: 12px;line-height: 1.15;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">test</span></li><li value="2" style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.15;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">test2</span></li><li value="3" style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.15;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">test3</span></li></ul><p style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.15;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">&nbsp;</span></p><ol start="1" style="list-style-type:decimal"><li value="1" style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.15;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">test4</span></li><li value="2" style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.15;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">test5</span></li><li value="3" style="margin-top: 0px;margin-right: 0px;margin-bottom: 12px;line-height: 1.15;font-family: 'Verdana';font-style: Normal;font-weight: normal;font-size: 16px;color: #000000;"><span style="font-family: 'Times New Roman';font-style: Normal;font-weight: normal;font-size: 12px;color: #000000;">test6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li></ol>
            """;

            using WordprocessingDocument package = WordprocessingDocument.Create(@"c:\temp\4\result2.docx", DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
            MainDocumentPart mainPart = package.MainDocumentPart ?? package.AddMainDocumentPart();

            HtmlConverter converter = new(mainPart);

            converter.ParseHtml(html);

            package.Save();
        }
    }
}

The result: image

onizet commented 3 weeks ago

I did a serious refactoring for v3 and have worked hard on numbering. Thanks for confirming this is working fine