Commit a8756a02 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Correction for lists with several paragraphs and no style defined

parent c4d48a3d
Loading
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -964,7 +964,7 @@ def update_unnumbered_lists(docx_input, docx_output):
        if id(para) in processed_paras:
        if id(para) in processed_paras:
            continue
            continue
        
        
        if para.xpath('./w:pPr/w:pStyle[@w:val="Compact"]', namespaces=ns) and para.xpath('./w:pPr/w:numPr', namespaces=ns):
        if (para.xpath('./w:pPr/w:pStyle[@w:val="Compact"]', namespaces=ns) or not para.xpath('./w:pPr/w:pStyle', namespaces=ns)) and para.xpath('./w:pPr/w:numPr', namespaces=ns):
            # Check if it is a numbered list and get the format
            # Check if it is a numbered list and get the format
            is_numbered, num_format = is_numbered_list(para, numbering_root)
            is_numbered, num_format = is_numbered_list(para, numbering_root)
            if is_numbered:  # is_numbered is True if numbered, False if unnumbered, None if cannot determine
            if is_numbered:  # is_numbered is True if numbered, False if unnumbered, None if cannot determine
@@ -979,10 +979,16 @@ def update_unnumbered_lists(docx_input, docx_output):
                pPr.append(pStyle)
                pPr.append(pStyle)
                counter_numbered += 1
                counter_numbered += 1
            else:
            else:
                # Change Compact style to B1, B2 or B3 style
                # Change Compact style if exists to B1, B2 or B3 style
                compact_style = para.xpath('./w:pPr/w:pStyle[@w:val="Compact"]', namespaces=ns)[0]
                # Get pPr element to work with styles/numPr
                # Get pPr element to remove numPr from it
                pPr = para.xpath('./w:pPr', namespaces=ns)[0]
                pPr = para.xpath('./w:pPr', namespaces=ns)[0]
                # Try to get existing Compact style; if not present, create pStyle
                compact_style_elems = pPr.xpath('./w:pStyle[@w:val="Compact"]', namespaces=ns)
                if compact_style_elems:
                    compact_style = compact_style_elems[0]
                else:
                    compact_style = OxmlElement('w:pStyle')
                    pPr.insert(0, compact_style)
                
                
                if para.xpath('./w:pPr/w:numPr/w:ilvl[@w:val="0"]', namespaces=ns):
                if para.xpath('./w:pPr/w:numPr/w:ilvl[@w:val="0"]', namespaces=ns):
                    if para.xpath('ancestor::w:tbl', namespaces=ns):
                    if para.xpath('ancestor::w:tbl', namespaces=ns):