From e9cbd8fe4e67ca32826435ed13ec0b54b850e1f3 Mon Sep 17 00:00:00 2001 From: stephenmk Date: Sun, 23 Apr 2023 12:31:02 -0500 Subject: [PATCH] Add conditions for displaying term reading in entry headword line --- bot/yomichan/glossary/jitenon.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bot/yomichan/glossary/jitenon.py b/bot/yomichan/glossary/jitenon.py index 1b58da5..7060566 100644 --- a/bot/yomichan/glossary/jitenon.py +++ b/bot/yomichan/glossary/jitenon.py @@ -65,7 +65,7 @@ def __decompose_table_rows(soup, entry): elif tr.th.text in ["四字熟語", "言葉"]: tr.decompose() elif tr.th.text == "読み方": - if re.match(r"^[ぁ-ヿ、]+$", entry.yomikata): + if __do_display_yomikata_in_headword(entry): tr.decompose() elif tr.th.text == "意味": imi = tr.td @@ -78,5 +78,17 @@ def __decompose_table_rows(soup, entry): def __insert_headword_line(soup, entry): headword_line = soup.new_tag("span") - headword_line.string = f"{entry.get_first_reading()}【{entry.expression}】" + if __do_display_yomikata_in_headword(entry): + headword_line.string = f"{entry.yomikata}【{entry.expression}】" + else: + headword_line.string = f"【{entry.expression}】" soup.body.insert(0, headword_line) + + +def __do_display_yomikata_in_headword(entry): + if not re.match(r"^[ぁ-ヿ、]+$", entry.yomikata): + return False + elif len(entry.yomikata) > 15: + return False + else: + return True