/*
 * SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software. 
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.unitext.internal.html;

public class UnitextHtmlGen {

    public com.pullenti.unitext.UnitextDocument create(HtmlNode nod, String dirName, java.util.HashMap<String, byte[]> images, com.pullenti.unitext.CreateDocumentParam pars) {
        if (dirName != null && ((new java.io.File(dirName)).exists() && (new java.io.File(dirName)).isDirectory())) 
            m_DirName = dirName;
        m_Images = images;
        com.pullenti.unitext.UnitextDocument doc = com.pullenti.unitext.UnitextDocument._new47(com.pullenti.unitext.FileFormat.HTML);
        this._prepare(nod, false);
        if (pars.loadDocumentStructure) {
            HtmlSectionItem s = HtmlSection.create(nod);
            if (s != null) {
                doc.content = s.generate(this);
                if (s.head.size() > 0 || s.tail.size() > 0) {
                    doc.sections.add(new com.pullenti.unitext.UnitextPagesection());
                    if (s.head.size() > 0) {
                        com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
                        for (HtmlNode n : s.head) {
                            this.getUniText(n, gen, null, 0);
                        }
                        doc.sections.get(0).items.add(com.pullenti.unitext.UnitextPagesectionItem._new48(gen.finish(true, null)));
                    }
                    if (s.tail.size() > 0) {
                        com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
                        for (HtmlNode n : s.tail) {
                            this.getUniText(n, gen, null, 0);
                        }
                        doc.sections.get(0).items.add(com.pullenti.unitext.UnitextPagesectionItem._new49(true, gen.finish(true, null)));
                    }
                }
            }
        }
        if (doc.content == null) {
            com.pullenti.unitext.internal.uni.UnitextGen gen = new com.pullenti.unitext.internal.uni.UnitextGen();
            this.getUniText(nod, gen, null, 0);
            doc.content = gen.finish(true, null);
        }
        HtmlNode h = nod.findSubnode("HEAD", null, null);
        HtmlNode ti = (h != null ? h.findSubnode("TITLE", null, null) : null);
        if (ti != null && ti.text != null && !doc.attrs.containsKey("title")) 
            doc.attrs.put("title", ti.text.trim());
        doc.optimize(false, null);
        return doc;
    }

    public static class MsoListItem {
    
        public int level;
    
        public String listId;
    
        public com.pullenti.unitext.UnitextListitem item;
    
        public static MsoListItem _new64(String _arg1) {
            MsoListItem res = new MsoListItem();
            res.listId = _arg1;
            return res;
        }
        public MsoListItem() {
        }
    }


    private String m_DirName = null;

    private java.util.HashMap<String, byte[]> m_Images = null;

    private java.util.HashMap<String, com.pullenti.unitext.UnitextFootnote> m_Foots = new java.util.HashMap<String, com.pullenti.unitext.UnitextFootnote>();

    private java.util.HashMap<String, com.pullenti.unitext.UnitextComment> m_Anno = new java.util.HashMap<String, com.pullenti.unitext.UnitextComment>();

    private java.util.HashMap<String, com.pullenti.unitext.UnitextContainer> m_Shapes = new java.util.HashMap<String, com.pullenti.unitext.UnitextContainer>();

    private java.util.ArrayList<HtmlNode> m_Ignored = new java.util.ArrayList<HtmlNode>();

    private void _prepare(HtmlNode nod, boolean okFoots) {
        String val = nod.getAttribute("STYLE");
        if (val != null && (((val.indexOf("footnote-list") >= 0) || (val.indexOf("endnote-list") >= 0) || (val.indexOf("comment-list") >= 0)))) {
            okFoots = true;
            m_Ignored.add(nod);
        }
        if (okFoots && com.pullenti.unisharp.Utils.stringsEq(nod.tagName, "P")) {
            val = nod.getAttribute("CLASS");
            if (com.pullenti.unisharp.Utils.stringsEq(val, "MsoFootnoteText") || com.pullenti.unisharp.Utils.stringsEq(val, "MsoEndnoteText") || com.pullenti.unisharp.Utils.stringsEq(val, "MsoCommentText")) {
                String nam = null;
                String val1;
                if ((((val1 = nod.getAttribute("NAME")))) != null) 
                    nam = val1;
                else {
                    HtmlNode ch = nod.findSubnode("A", "NAME", null);
                    if (ch == null && nod.parent != null && com.pullenti.unisharp.Utils.stringsEq(val, "MsoCommentText")) 
                        ch = ((HtmlNode)com.pullenti.unisharp.Utils.cast(nod.parent, HtmlNode.class)).findSubnode("A", "NAME", null);
                    if (ch != null) {
                        nam = (val1 = ch.getAttribute("NAME"));
                        if (nam != null) 
                            m_Ignored.add(ch);
                    }
                }
                if (nam != null) {
                    if ((val.indexOf("Comment") >= 0)) {
                        if (!m_Anno.containsKey(nam)) {
                            com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                            this.getUniText(nod, gg, null, 0);
                            com.pullenti.unitext.UnitextItem it = gg.finish(true, null);
                            if (it != null) {
                                StringBuilder tmp = new StringBuilder();
                                it.getPlaintext(tmp, null);
                                if (tmp.length() > 0) {
                                    if (tmp.toString().indexOf('[') >= 0) {
                                        int ii = tmp.toString().indexOf(']');
                                        if (ii > 0) 
                                            tmp.delete(0, 0 + ii + 1);
                                    }
                                    m_Anno.put(nam, com.pullenti.unitext.UnitextComment._new50(tmp.toString().trim()));
                                }
                            }
                        }
                    }
                    else {
                        com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                        this.getUniText(nod, gg, null, 0);
                        com.pullenti.unitext.UnitextFootnote fn = new com.pullenti.unitext.UnitextFootnote();
                        fn.isEndnote = (val.indexOf("Endnote") >= 0);
                        fn.content = gg.finish(true, null);
                        if (!m_Foots.containsKey(nam)) 
                            m_Foots.put(nam, fn);
                    }
                }
                return;
            }
        }
        for (int ii = 0; ii < nod.children.size(); ii++) {
            this._prepare(nod.children.get(ii), okFoots);
        }
    }

    public void getUniText(HtmlNode nod, com.pullenti.unitext.internal.uni.UnitextGen res, Object blk, int lev) {
        if (lev > 100) 
            return;
        String tagName = nod.tagName;
        if ((com.pullenti.unisharp.Utils.stringsEq(tagName, "SCRIPT") || com.pullenti.unisharp.Utils.stringsEq(tagName, "NOSCRIPT") || com.pullenti.unisharp.Utils.stringsEq(tagName, "STYLE")) || com.pullenti.unisharp.Utils.stringsEq(tagName, "META") || com.pullenti.unisharp.Utils.stringsEq(tagName, "TITLE")) 
            return;
        if (com.pullenti.unisharp.Utils.stringsEq(tagName, "DEL")) 
            return;
        if (com.pullenti.unisharp.Utils.stringsEq(tagName, "TEMPLATE")) 
            return;
        if (m_Ignored.contains(nod)) 
            return;
        HtmlTag tag = HtmlTag.findTag(tagName);
        String st = nod.getAttribute("STYLE");
        if (st != null && (st.toLowerCase().indexOf("page-break-before") >= 0)) 
            res.appendPagebreak();
        if (tag != null && com.pullenti.unisharp.Utils.stringsEq(tag.name, "BR")) {{
                    if (res != null) 
                        res.appendNewline(false, false);
                    return;
                }
        }
        if (tag != null && com.pullenti.unisharp.Utils.stringsEq(tag.name, "TABLE")) {
            com.pullenti.unitext.internal.uni.UnitextGenTable tbl = new com.pullenti.unitext.internal.uni.UnitextGenTable();
            for (int ii = 0; ii < nod.children.size(); ii++) {
                this.getUniText(nod.children.get(ii), null, tbl, lev + 1);
            }
            if (res != null) {
                com.pullenti.unitext.UnitextTable tab = tbl.convert();
                if (tab != null) {
                    if ((((tab.width = nod.getStyleValue("width")))) == null) 
                        tab.width = nod.getAttribute("WIDTH");
                    String vv = nod.getAttribute("BORDER");
                    if (vv != null) {
                        if (vv.startsWith("0")) 
                            tab.hideBorders = true;
                    }
                    else if ((((vv = nod.getStyleValue("border")))) != null) {
                        if (vv.startsWith("0")) 
                            tab.hideBorders = true;
                    }
                    else if ((((vv = nod.getStyleValue("border-width")))) != null) {
                        if (vv.startsWith("0")) 
                            tab.hideBorders = true;
                    }
                    if (com.pullenti.unisharp.Utils.stringsEq(nod.getStyleValue("BORDER"), "none")) {
                        if (nod.getStyleValue("MSO-BORDER-ALT") == null) 
                            tab.hideBorders = true;
                    }
                    if (res.lastChar != '\r') 
                        res.appendNewline(false, false);
                    res.append(tab, null, -1, false);
                }
                res.appendNewline(false, false);
            }
            return;
        }
        if (tag != null && com.pullenti.unisharp.Utils.stringsEq(tag.name, "TR")) {
            com.pullenti.unitext.internal.uni.UnitextGenTable tab = (com.pullenti.unitext.internal.uni.UnitextGenTable)com.pullenti.unisharp.Utils.cast(blk, com.pullenti.unitext.internal.uni.UnitextGenTable.class);
            if (tab == null) 
                return;
            java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell> row = new java.util.ArrayList<com.pullenti.unitext.internal.uni.UniTextGenCell>();
            tab.cells.add(row);
            for (int ii = 0; ii < nod.children.size(); ii++) {
                HtmlNode ch = nod.children.get(ii);
                HtmlTag tag2 = HtmlTag.findTag(ch.tagName);
                if (tag2 == null || ((com.pullenti.unisharp.Utils.stringsNe(tag2.name, "TD") && com.pullenti.unisharp.Utils.stringsNe(tag2.name, "TH")))) 
                    continue;
                com.pullenti.unitext.internal.uni.UniTextGenCell cel = new com.pullenti.unitext.internal.uni.UniTextGenCell();
                row.add(cel);
                int colsp = 1;
                int rowsp = 1;
                if (ch.getAttribute("ROWSPAN") != null) {
                    com.pullenti.unisharp.Outargwrapper<Integer> wraprowsp51 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                    boolean inoutres52 = com.pullenti.unisharp.Utils.parseInteger(ch.getAttribute("ROWSPAN"), 0, null, wraprowsp51);
                    rowsp = (wraprowsp51.value != null ? wraprowsp51.value : 0);
                    if (inoutres52) {
                        if (rowsp > 65534) 
                            rowsp = 65534;
                        cel.rowSpan = rowsp;
                    }
                }
                if (ch.getAttribute("COLSPAN") != null) {
                    com.pullenti.unisharp.Outargwrapper<Integer> wrapcolsp53 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                    boolean inoutres54 = com.pullenti.unisharp.Utils.parseInteger(ch.getAttribute("COLSPAN"), 0, null, wrapcolsp53);
                    colsp = (wrapcolsp53.value != null ? wrapcolsp53.value : 0);
                    if (inoutres54) {
                        if (colsp < 100) 
                            cel.colSpan = colsp;
                    }
                }
                if (colsp <= 1) {
                    String wi = (String)com.pullenti.unisharp.Utils.notnull(ch.getStyleValue("width"), ch.getAttribute("WIDTH"));
                    if (wi != null) 
                        cel.width = wi;
                }
                com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                this.getUniText(ch, gg, null, lev + 1);
                cel.content = gg.finish(true, null);
            }
            return;
        }
        if (tag != null && com.pullenti.unisharp.Utils.stringsEq(tag.name, "COLGROUP")) {
            com.pullenti.unitext.internal.uni.UnitextGenTable tab = (com.pullenti.unitext.internal.uni.UnitextGenTable)com.pullenti.unisharp.Utils.cast(blk, com.pullenti.unitext.internal.uni.UnitextGenTable.class);
            if (tab == null) 
                return;
            for (int ii = 0; ii < nod.children.size(); ii++) {
                HtmlNode ch = nod.children.get(ii);
                HtmlTag tag2 = HtmlTag.findTag(ch.tagName);
                if (tag2 == null || com.pullenti.unisharp.Utils.stringsNe(tag2.name, "COL")) 
                    continue;
                String wi = (String)com.pullenti.unisharp.Utils.notnull(ch.getStyleValue("width"), ch.getAttribute("WIDTH"));
                tab.m_ColWidth.add(wi);
            }
            return;
        }
        if (tag != null && ((com.pullenti.unisharp.Utils.stringsEq(tag.name, "OL") || com.pullenti.unisharp.Utils.stringsEq(tag.name, "UL")))) {
            com.pullenti.unitext.UnitextList li = new com.pullenti.unitext.UnitextList();
            int liNum = 0;
            String liTyp = null;
            if (com.pullenti.unisharp.Utils.stringsEq(tag.name, "OL")) {
                com.pullenti.unisharp.Outargwrapper<Integer> wrapliNum55 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                boolean inoutres56 = com.pullenti.unisharp.Utils.parseInteger((String)com.pullenti.unisharp.Utils.notnull(nod.getAttribute("START"), ""), 0, null, wrapliNum55);
                liNum = (wrapliNum55.value != null ? wrapliNum55.value : 0);
                if (!inoutres56) 
                    liNum = 1;
                liTyp = (String)com.pullenti.unisharp.Utils.notnull(nod.getAttribute("TYPE"), "1");
            }
            else 
                li.unorderPrefix = "";
            for (int ii = 0; ii < nod.children.size(); ii++) {
                HtmlNode ch = nod.children.get(ii);
                HtmlTag tag2 = HtmlTag.findTag(ch.tagName);
                if (tag2 == null || com.pullenti.unisharp.Utils.stringsNe(tag2.name, "LI")) 
                    continue;
                com.pullenti.unitext.UnitextListitem it = new com.pullenti.unitext.UnitextListitem();
                li.items.add(it);
                com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                this.getUniText(ch, gg, null, lev + 1);
                it.content = gg.finish(true, null);
                if (liNum > 0 && liTyp != null && li.unorderPrefix == null) {
                    String pref = HtmlNode._getLiNum(liNum, liTyp);
                    if (pref != null) 
                        it.prefix = com.pullenti.unitext.UnitextPlaintext._new57(pref);
                    liNum++;
                }
            }
            if (res != null) 
                res.append(li, null, -1, false);
            return;
        }
        if (tag != null && ((com.pullenti.unisharp.Utils.stringsEq(tag.name, "SUP") || com.pullenti.unisharp.Utils.stringsEq(tag.name, "SUB")))) {
            StringBuilder tmp = new StringBuilder();
            if (nod.children.size() == 0) 
                tmp.append(nod.text);
            else 
                for (int ii = 0; ii < nod.children.size(); ii++) {
                    nod.children.get(ii)._getFullText(tmp, null, null);
                }
            String tt = tmp.toString().trim();
            if (tt.length() > 0 && (tt.length() < 10)) {
                res.append(com.pullenti.unitext.UnitextPlaintext._new58(tt, (com.pullenti.unisharp.Utils.stringsEq(tag.name, "SUB") ? com.pullenti.unitext.UnitextPlaintextType.SUB : com.pullenti.unitext.UnitextPlaintextType.SUP)), null, -1, false);
                return;
            }
        }
        if (res == null) {
            for (int ii = 0; ii < nod.children.size(); ii++) {
                this.getUniText(nod.children.get(ii), res, blk, lev + 1);
            }
            return;
        }
        if (com.pullenti.unisharp.Utils.stringsEq(tagName, "A")) {
            String val = nod.getAttribute("HREF");
            if (val != null) {
                com.pullenti.unitext.UnitextFootnote fn;
                com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextFootnote> wrapfn60 = new com.pullenti.unisharp.Outargwrapper<com.pullenti.unitext.UnitextFootnote>();
                boolean inoutres61 = com.pullenti.unisharp.Utils.tryGetValue(m_Foots, val.substring(1), wrapfn60);
                fn = wrapfn60.value;
                if (val.startsWith("#") && inoutres61) {
                    res.append(fn, null, -1, false);
                    return;
                }
                if (val.startsWith("#") && m_Anno.containsKey(val.substring(1))) {
                    res.append(m_Anno.get(val.substring(1)), null, -1, false);
                    return;
                }
                if (nod.children.size() > 0) {
                    boolean noTag = false;
                    if (nod.children.size() > 20) 
                        noTag = true;
                    else 
                        for (HtmlNode ch : nod.children) {
                            if (ch.hasTag("A") || ch.hasBlockTag()) {
                                noTag = true;
                                break;
                            }
                        }
                    if (noTag && (nod.parent instanceof HtmlNode)) {
                        int i = ((HtmlNode)com.pullenti.unisharp.Utils.cast(nod.parent, HtmlNode.class)).children.indexOf(nod);
                        if (i >= 0) 
                            com.pullenti.unisharp.Utils.insertToArrayList(((HtmlNode)com.pullenti.unisharp.Utils.cast(nod.parent, HtmlNode.class)).children, nod.children, i + 1);
                        nod.children.clear();
                    }
                }
                com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
                if (nod.text != null) 
                    gg.appendText(nod.text, false);
                for (HtmlNode ch : nod.children) {
                    this.getUniText(ch, gg, null, lev + 1);
                }
                com.pullenti.unitext.UnitextItem it = gg.finish(true, null);
                if (it != null) {
                    com.pullenti.unitext.UnitextHyperlink hr = com.pullenti.unitext.UnitextHyperlink._new59(val);
                    hr.content = it;
                    res.append(hr, null, -1, false);
                    return;
                }
                val = nod.getAttribute("CLASS");
                if (com.pullenti.unisharp.Utils.stringsCompare((val != null ? val : ""), "MSOCOMANCHOR", true) == 0) 
                    return;
            }
        }
        if (com.pullenti.unisharp.Utils.stringsEq(tagName, "V:TEXTBOX")) {
        }
        if (com.pullenti.unisharp.Utils.stringsEq(tagName, "V:IMAGEDATA") || com.pullenti.unisharp.Utils.stringsEq(tagName, "IMG")) {
            String shapes = nod.getAttribute("V:SHAPES");
            if (shapes != null) {
                String[] ids = com.pullenti.unisharp.Utils.split(shapes, String.valueOf(' '), false);
            }
            com.pullenti.unitext.UnitextImage img = new com.pullenti.unitext.UnitextImage();
            if ((((img.id = nod.getAttribute("SRC")))) != null) {
                try {
                    if (m_DirName != null) {
                        if (img.id != null && !img.id.startsWith("http")) {
                            String fname = (new java.io.File(m_DirName, (new java.io.File(((img.id != null ? img.id : "")))).getPath())).getPath();
                            if (!((new java.io.File(fname)).exists() && (new java.io.File(fname)).isFile())) 
                                fname = fname.replace('/', '\\');
                            if (((new java.io.File(fname)).exists() && (new java.io.File(fname)).isFile())) 
                                img.content = com.pullenti.unitext.internal.uni.UnitextHelper.loadDataFromFile(fname, 0);
                        }
                    }
                    else if (m_Images != null) {
                        for (java.util.Map.Entry<String, byte[]> kp : m_Images.entrySet()) {
                            if (kp.getKey().endsWith(img.id)) {
                                img.content = kp.getValue();
                                break;
                            }
                        }
                    }
                    res.append(img, null, -1, false);
                    for (HtmlNode hh = nod; hh != null; hh = (HtmlNode)com.pullenti.unisharp.Utils.cast(hh.parent, HtmlNode.class)) {
                        String val;
                        if ((((val = hh.getStyleValue("WIDTH")))) != null) 
                            img.width = com.pullenti.unitext.internal.uni.UnitextGen.convertToPt(val, "px");
                        if ((((val = hh.getStyleValue("HEIGHT")))) != null) 
                            img.height = com.pullenti.unitext.internal.uni.UnitextGen.convertToPt(val, "px");
                        if (img.width != null || img.height != null) 
                            break;
                        if ((((val = hh.getAttribute("WIDTH")))) != null) 
                            img.width = com.pullenti.unitext.internal.uni.UnitextGen.convertToPt(val, "px");
                        if ((((val = hh.getAttribute("HEIGHT")))) != null) 
                            img.height = com.pullenti.unitext.internal.uni.UnitextGen.convertToPt(val, "px");
                    }
                    if (img.width == null || img.height == null) 
                        img.width = (img.height = null);
                } catch (Exception ex62) {
                }
                return;
            }
        }
        boolean isBlock = false;
        if (tag != null && ((tag.isBlock() || tag.isTable()))) 
            isBlock = true;
        boolean isH = false;
        if (isBlock) {
            res.appendNewline(false, false);
            if ((((tagName != null ? tagName : ""))).length() == 2) {
                if (((tagName.charAt(0) == 'H' || tagName.charAt(0) == 'h')) && Character.isDigit(tagName.charAt(1))) {
                    isH = true;
                    res.appendNewline(false, false);
                    if (tagName.charAt(0) == '1') 
                        res.appendNewline(false, false);
                }
            }
        }
        if (!com.pullenti.unisharp.Utils.isNullOrEmpty(nod.text)) {
            int cou = 0;
            boolean wingdings = false;
            boolean webdings = false;
            boolean symbols = false;
            for (HtmlNode pp = nod; pp != null && (cou < 2); pp = (HtmlNode)com.pullenti.unisharp.Utils.cast(pp.parent, HtmlNode.class),cou++) {
                String ff = (String)com.pullenti.unisharp.Utils.notnull(pp.getStyleValue("font-family"), pp.getStyleValue("font"));
                if (ff != null) {
                    if ((ff.toUpperCase().indexOf("WINGDINGS") >= 0)) 
                        wingdings = true;
                    else if ((ff.toUpperCase().indexOf("WEBDINGS") >= 0)) 
                        webdings = true;
                    else if ((ff.toUpperCase().indexOf("SYMBOL") >= 0)) 
                        symbols = true;
                    break;
                }
            }
            if (wingdings) 
                res.appendText(com.pullenti.unitext.internal.misc.WingdingsHelper.getUnicodeString(nod.text), false);
            else if (webdings) 
                res.appendText(com.pullenti.unitext.internal.misc.WebdingsHelper.getUnicodeString(nod.text), false);
            else if (symbols) 
                res.appendText(com.pullenti.unitext.internal.misc.SymbolHelper.getUnicodeString(nod.text), false);
            else 
                res.appendText(nod.text, false);
        }
        else if (nod.children.size() == 1) {
            int cou = 0;
            HtmlNode nn = nod;
            for (; nn != null; ) {
                if (nn.children.size() != 1) 
                    break;
                if (nn.children.get(0).text != null) 
                    break;
                cou++;
                nn = nn.children.get(0);
            }
            if (cou > 100 && nn != null) 
                nod = nn;
            else 
                nod = nod.children.get(0);
            this.getUniText(nod, res, null, lev + 1);
        }
        else {
            boolean first = true;
            java.util.ArrayList<com.pullenti.unitext.UnitextList> lists = null;
            String listId = null;
            for (int ii = 0; ii < nod.children.size(); ii++) {
                HtmlNode ch = nod.children.get(ii);
                MsoListItem li = this.tryParseList(ch, lev + 1);
                if (li != null && li.item.content == null && com.pullenti.unisharp.Utils.stringsEq(nod.tagName, "TD")) 
                    li = null;
                if (li == null) {
                    if (lists != null) {
                        if (ch.children.size() == 0 && (((ch.text != null ? ch.text : ""))).trim().length() == 0) 
                            continue;
                        lists = null;
                        listId = null;
                    }
                }
                else if (com.pullenti.unisharp.Utils.stringsNe(li.listId, listId) && listId != null) {
                    listId = null;
                    lists = null;
                }
                if (li != null) {
                    if (lists == null) {
                        com.pullenti.unitext.UnitextList list = new com.pullenti.unitext.UnitextList();
                        if (res.lastChar != '\r') 
                            res.appendNewline(false, false);
                        res.append(list, null, -1, false);
                        res.appendNewline(false, false);
                        lists = new java.util.ArrayList<com.pullenti.unitext.UnitextList>();
                        lists.add(list);
                        listId = li.listId;
                    }
                    if (li.level == 3) {
                    }
                    if (li.level == lists.size()) {
                        lists.get(0).items.add(li.item);
                        continue;
                    }
                    if (li.level < lists.size()) {
                        while (li.level < lists.size()) {
                            lists.remove(0);
                        }
                        lists.get(0).items.add(li.item);
                        continue;
                    }
                    if (li.level == (lists.size() + 1) && lists.get(0).items.size() > 0) {
                        com.pullenti.unitext.UnitextListitem last = lists.get(0).items.get(lists.get(0).items.size() - 1);
                        if (last.sublist == null) 
                            last.sublist = com.pullenti.unitext.UnitextList._new63(li.level - 1);
                        lists.add(0, last.sublist);
                        last.sublist.items.add(li.item);
                        continue;
                    }
                }
                if (first) 
                    first = false;
                else if (!ch.whitespacePreserve) {
                    if (ch.whitespaceBefore) 
                        res.appendText(" ", false);
                }
                this.getUniText(ch, res, null, lev + 1);
            }
        }
        if (isH) {
            res.appendNewline(false, false);
            if (tagName.charAt(0) == '1') 
                res.appendNewline(false, false);
        }
    }

    private MsoListItem tryParseList(HtmlNode nod, int lev) {
        if (com.pullenti.unisharp.Utils.stringsNe(nod.tagName, "P")) 
            return null;
        String val = nod.getAttribute("STYLE");
        if (val == null) 
            return null;
        int i = val.indexOf("mso-list:");
        if (i < 0) 
            return null;
        val = val.substring(i + 9).trim();
        String[] fi = com.pullenti.unisharp.Utils.split(val, String.valueOf(' '), false);
        if (fi.length < 3) 
            return null;
        if (!com.pullenti.unisharp.Utils.startsWithString(fi[2], "LFO", true)) 
            return null;
        MsoListItem res = MsoListItem._new64(fi[2]);
        com.pullenti.unisharp.Outargwrapper<Integer> wrapi66 = new com.pullenti.unisharp.Outargwrapper<Integer>();
        boolean inoutres67 = com.pullenti.unisharp.Utils.parseInteger(fi[1].substring(5), 0, null, wrapi66);
        i = (wrapi66.value != null ? wrapi66.value : 0);
        if (!com.pullenti.unisharp.Utils.startsWithString(fi[1], "level", true) || !inoutres67) 
            return null;
        res.level = i;
        if (i < 1) 
            return null;
        if (nod.children.size() == 1 && com.pullenti.unisharp.Utils.stringsEq(nod.children.get(0).tagName, "A")) 
            nod = nod.children.get(0);
        for (i = 0; i < nod.children.size(); i++) {
            HtmlNode ch = nod.children.get(i);
            if (com.pullenti.unisharp.Utils.stringsNe(ch.tagName, "SPAN")) 
                continue;
            if ((((val = ch.getAttribute("STYLE")))) != null && (val.indexOf("Ignore") >= 0)) {
            }
            else if (ch.findSubnode("SPAN", "STYLE", "mso-list:Ignore") != null) {
            }
            else if (i == 0) {
            }
            else 
                continue;
            StringBuilder tmp = new StringBuilder();
            ch._getFullText(tmp, new com.pullenti.unitext.GetPlaintextParam(), null);
            res.item = new com.pullenti.unitext.UnitextListitem();
            if (tmp.length() > 0) 
                res.item.prefix = com.pullenti.unitext.UnitextPlaintext._new57(tmp.toString().trim());
            com.pullenti.unitext.internal.uni.UnitextGen gg = new com.pullenti.unitext.internal.uni.UnitextGen();
            com.pullenti.unisharp.Utils.putArrayValue(nod.children, i, new HtmlNode());
            nod.tagName = "PPP";
            this.getUniText(nod, gg, null, lev + 1);
            com.pullenti.unisharp.Utils.putArrayValue(nod.children, i, ch);
            nod.tagName = "P";
            res.item.content = gg.finish(true, null);
            return res;
        }
        return null;
    }
    public UnitextHtmlGen() {
    }
    public static UnitextHtmlGen _globalInstance;
    
    static {
        try { _globalInstance = new UnitextHtmlGen(); } 
        catch(Exception e) { }
    }
}
