diff --git a/novel_stats/novel_stats.py b/novel_stats/novel_stats.py index 5181d06..7d660ca 100755 --- a/novel_stats/novel_stats.py +++ b/novel_stats/novel_stats.py @@ -10,6 +10,7 @@ STATUS_MARKER = '[status]: # ' ACT_MARKER = '[act]: # ' # Standard markdown comment marker, supported by Pandoc and Calibre's ebook-convert. COMMENT_MARKER = '[//]: # ' +TITLE_MARKER = '# ' def count_words(line): @@ -74,6 +75,7 @@ def main(): word_count_by_act = collections.defaultdict(int) status_by_chapter = {} current_status = None + title = None for line in mdfile.readlines(): if line.startswith(CHAPTER_MARKER): @@ -97,6 +99,10 @@ def main(): elif line.startswith(ACT_MARKER): act_heading = line[len(ACT_MARKER) :].strip('()\n') word_count_by_act[act_heading] = count_words(act_heading) + elif line.startswith(TITLE_MARKER): + title = line[len(TITLE_MARKER):].strip() + line_word_count = count_words(line) + word_count_by_chapter[chapter_heading] += line_word_count elif line.startswith(COMMENT_MARKER): # Don't count the words in a comment. pass else: @@ -113,6 +119,9 @@ def main(): word_count_by_act[act_heading] += word_count_by_chapter[chapter_heading] total_word_count += word_count_by_chapter[chapter_heading] + if title: + print(f'Novel Stats for {title.upper()}') + # -c or --chapter to give a chapter-by-chapter word count summary. if arguments.chapter: for chapter_heading, chapter_word_count in word_count_by_chapter.items():