diff --git a/format_novel/format_novel.py b/format_novel/format_novel.py index acf2cb9..4be1cb8 100755 --- a/format_novel/format_novel.py +++ b/format_novel/format_novel.py @@ -68,8 +68,9 @@ def right_align_header(document): def double_space_and_indent(paragraphs): + previous_paragraph = None this_paragraph_plaintext = False - previous_paragraph_plaintext = False + previous_paragraph_plaintext = None for paragraph in paragraphs: paragraph.paragraph_format.line_spacing = 2 @@ -88,6 +89,10 @@ def double_space_and_indent(paragraphs): if this_paragraph_plaintext and previous_paragraph_plaintext: paragraph.paragraph_format.first_line_indent = docx.shared.Inches(0.5) + if previous_paragraph and paragraph.style == previous_paragraph.style and not paragraph.text and not previous_paragraph.text: + previous_paragraph._element.getparent().remove(previous_paragraph._element) + + previous_paragraph = paragraph previous_paragraph_plaintext = this_paragraph_plaintext