From fd207cb6b1d675d4e8d54f2629847e332ccace9a Mon Sep 17 00:00:00 2001 From: Congon4tor Date: Fri, 3 Jan 2025 02:51:33 +0100 Subject: [PATCH] Add reat time using preprocessor --- hacktricks-preprocessor.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hacktricks-preprocessor.py b/hacktricks-preprocessor.py index fedfdef99..0a916cbfc 100644 --- a/hacktricks-preprocessor.py +++ b/hacktricks-preprocessor.py @@ -69,6 +69,12 @@ def ref(matchobj): return result +def add_read_time(content): + regex = r'(# .*(?=\n))' + new_content = re.sub(regex, lambda x: x.group(0) + "\n\nReading time: {{ #reading_time }}", content) + return new_content + + def iterate_chapters(sections): if isinstance(sections, dict) and "PartTitle" in sections: # Not a chapter section return @@ -99,6 +105,7 @@ if __name__ == '__main__': current_chapter = chapter regex = r'{{[\s]*#ref[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endref[\s]*}}' new_content = re.sub(regex, ref, chapter['content']) + new_content = add_read_time(new_content) chapter['content'] = new_content content = json.dumps(book)