From 93b3af2c3bd224c0acda763dfa5677a26d02d39d Mon Sep 17 00:00:00 2001 From: Dmytro Yeroshkin Date: Fri, 22 Oct 2021 11:37:33 +0200 Subject: [PATCH] Added mdpp support --- novel_stats/novel_stats.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/novel_stats/novel_stats.py b/novel_stats/novel_stats.py index b390794..51a10c8 100755 --- a/novel_stats/novel_stats.py +++ b/novel_stats/novel_stats.py @@ -3,6 +3,7 @@ import collections import sys +import os CHAPTER_MARKER = '## ' @@ -26,6 +27,14 @@ def count_words(line): def main(): arguments = sys.argv[1:] filename = arguments[0] + tmpfilename = None + + if '-pp' in arguments: + import MarkdownPP + tmpfilename = f'.tmp-{os.getpid}.md' + MarkdownPP.MarkdownPP(input=open(filename), output=open(tmpfilename,'w'), modules=list(MarkdownPP.modules)) + filename = tmpfilename + chapter_heading = None act_heading = None total_word_count = 0 @@ -101,6 +110,9 @@ def main(): print('{}: {:,} words (~{}%)'.format(status, status_word_count, status_word_count * 100 // total_word_count)) print('total: {:,} words'.format(total_word_count)) + + if tmpfilename: + os.remove(tmpfilename) if __name__ == '__main__':