Add reat time using preprocessor

This commit is contained in:
Congon4tor 2025-01-03 02:51:33 +01:00
parent 4374a7457b
commit fd207cb6b1

View File

@ -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)