From 89faad1b2be6550851a03474eb64aa196341416f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 5 Jan 2024 21:00:37 -0800 Subject: [PATCH] Add flag to format the whole document including the title page (if any). --- format_novel/format_novel.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/format_novel/format_novel.py b/format_novel/format_novel.py index 5cbbbdf..5dea44a 100755 --- a/format_novel/format_novel.py +++ b/format_novel/format_novel.py @@ -83,7 +83,7 @@ def right_align_header(document): header_paragraph.paragraph_format.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.RIGHT -def double_space_and_indent(paragraphs): +def double_space_and_indent(paragraphs, format_all): previous_paragraph = None this_paragraph_plaintext = False previous_paragraph_plaintext = None @@ -100,7 +100,7 @@ def double_space_and_indent(paragraphs): reached_first_heading = True # Skip past the title page until we reach the first chapter/other heading. - if not reached_first_heading: + if not reached_first_heading and not format_all: continue paragraph.paragraph_format.line_spacing = 2 @@ -150,6 +150,13 @@ def parse_arguments(unparsed_arguments): '--title', help='Project title to show in page headers, defaults to the manuscript filename without the file extension', ) + parser.add_argument( + '-f', + '--format-all', + help='Format the whole document, even the title page (if any)', + action='store_true', + default=False, + ) return parser.parse_args(unparsed_arguments) @@ -170,7 +177,7 @@ def main(): skip_page_number_on_first_page(document) right_align_header(document) - double_space_and_indent(document.paragraphs) + double_space_and_indent(document.paragraphs, arguments.format_all) document.save(arguments.document_filename)