-
Notifications
You must be signed in to change notification settings - Fork 0
/
commentaries_to_markdown.py
27 lines (20 loc) · 1.02 KB
/
commentaries_to_markdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import List
from database_api.code_verse import verse_id_range_to_str, normalize_book_name
from database_api.commentary_objects import Commentary
def commentaries_to_markdown(commentaries: List[Commentary]) -> str:
mkdown = []
for commentary in commentaries:
title = ""
if 0 < commentary.ts < 9999999:
title += f"# [AD {commentary.ts}]"
elif commentary.ts < 0:
title += f"# [{commentary.ts} BC]"
else:
title += "# [Unknown Year]"
title += f" [{commentary.father_name.strip()}"
if commentary.append_to_author_name.strip():
title += f" {commentary.append_to_author_name.strip()}"
title += f"]({commentary.wiki_url})"
title += f" on {normalize_book_name(commentary.book)} {verse_id_range_to_str(commentary.location_start, commentary.location_end)}"
mkdown.extend((title, commentary.txt, f"`{commentary.source_title}`" if commentary.source_title else "", "\n\n ---"))
return "\n".join(mkdown)