From 7a522f33eff31758d78c4e09d9ba8b9f96219660 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 3 Feb 2023 15:04:03 -0800 Subject: [PATCH] Putting back the paragraph deduplication. --- format_novel/format_novel.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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