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

Fix to append all elements in a bulleted (where lvlText is a space) paragraph...

Fix to append all elements in a bulleted (where lvlText is a space) paragraph to the previous paragraph
parent 73f33497
Loading
Loading
Loading
Loading
Loading
+18 −29
Original line number Diff line number Diff line
@@ -1098,20 +1098,15 @@ def update_lists(docx_input, docx_output):

                            compact_style.set(f"{{{ns['w']}}}val", "B1")
                        else:
                            # Take the text from the paragraph
                            text = get_para_text(para)
                            print(f'Found text belonging to a numbered list item: {text}')
                            #  Insert it as new run to the previous paragraph. New run starting by <w:br/>
                            # Take all elements except pPr (usually only runs and hyperlinks) in this paragraph and append them to the previous paragraph. New run starting by <w:br/>
                            previous_para = para.getprevious()
                            if previous_para is not None:
                                new_run = OxmlElement('w:r')
                                text_t = OxmlElement('w:t')
                                text_t.text = text
                                new_run.append(text_t)
                                break_run = OxmlElement('w:r')
                                break_run.append(OxmlElement('w:br'))
                                previous_para.append(break_run)
                                previous_para.append(new_run)
                                for element in para.xpath('./*', namespaces=ns):
                                    if element.tag != f"{{{ns['w']}}}pPr":
                                        previous_para.append(element)
                            # Remove the original paragraph
                            para.getparent().remove(para)
                            para_removed = True
@@ -1138,18 +1133,15 @@ def update_lists(docx_input, docx_output):

                            compact_style.set(f"{{{ns['w']}}}val", "B2")
                        else:
                            #print(f'Found text belonging to a numbered list item')
                            # Take the text from the paragraph
                            text = get_para_text(para)
                            #  Insert it as new run to the previous paragraph. New run starting by <w:br/>
                           # Take all elements except pPr (usually only runs and hyperlinks) in this paragraph and append them to the previous paragraph. New run starting by <w:br/>
                            previous_para = para.getprevious()
                            if previous_para is not None:
                                new_run = OxmlElement('w:r')
                                new_run.append(OxmlElement('w:br'))
                                text_t = OxmlElement('w:t')
                                text_t.text = text
                                new_run.append(text_t)
                                previous_para.append(new_run)
                                break_run = OxmlElement('w:r')
                                break_run.append(OxmlElement('w:br'))
                                previous_para.append(break_run)
                                for element in para.xpath('./*', namespaces=ns):
                                    if element.tag != f"{{{ns['w']}}}pPr":
                                        previous_para.append(element)
                            # Remove the original paragraph
                            para.getparent().remove(para)
                            para_removed = True
@@ -1176,18 +1168,15 @@ def update_lists(docx_input, docx_output):

                            compact_style.set(f"{{{ns['w']}}}val", "B3")
                        else:
                            #print(f'Found text belonging to a numbered list item')
                            # Take the text from the paragraph
                            text = get_para_text(para)
                            #  Insert it as new run to the previous paragraph. New run starting by <w:br/>
                            # Take all elements except pPr (usually only runs and hyperlinks) in this paragraph and append them to the previous paragraph. New run starting by <w:br/>
                            previous_para = para.getprevious()
                            if previous_para is not None:
                                new_run = OxmlElement('w:r')
                                new_run.append(OxmlElement('w:br'))
                                text_t = OxmlElement('w:t')
                                text_t.text = text
                                new_run.append(text_t)
                                previous_para.append(new_run)
                                break_run = OxmlElement('w:r')
                                break_run.append(OxmlElement('w:br'))
                                previous_para.append(break_run)
                                for element in para.xpath('./*', namespaces=ns):
                                    if element.tag != f"{{{ns['w']}}}pPr":
                                        previous_para.append(element)
                            # Remove the original paragraph
                            para.getparent().remove(para)
                            para_removed = True