Format non-okurigana part of kanji readings in bold

This commit is contained in:
Kiril Kovachev 2024-10-16 15:34:03 +01:00
parent e6be4107f5
commit ae7501bb2e
2 changed files with 25 additions and 12 deletions

View File

@ -67,6 +67,19 @@ def create_app(test_config=None):
else:
return update_settings(request.form)
def format_reading(reading: str) -> str:
"""Apply bold to the part of the reading which the kanji represents; for kun, this can be
e.g. : えら- --> <b>えら</b>. For reading strings which don't have any "-" character in them,
one is added to the end and the entire reading is emboldened.
Example: : かん --> <b>かん</b>
"""
if "-" not in reading:
reading += "-"
okurigana_position = reading.index("-")
emboldened_part = reading[:okurigana_position]
return f"<b>{emboldened_part}</b>{reading[okurigana_position+1:]}"
@app.route("/kanji/<kanji>")
def kanji_page(kanji: str):
kanji_obj = get_kanji_by_character(kanji)
@ -81,12 +94,12 @@ def create_app(test_config=None):
out.strokes = kanji_obj.stroke_count
out.radical = kanji_obj.radical
out.added_strokes = kanji_obj.radical_added_stroke_count
out.goon = [str(obj.reading) for obj in kanji_obj.goon]
out.kanon = [str(obj.reading) for obj in kanji_obj.kanon]
out.toon = [str(obj.reading) for obj in kanji_obj.toon]
out.soon = [str(obj.reading) for obj in kanji_obj.soon]
out.kanyoon = [str(obj.reading) for obj in kanji_obj.kanyoon]
out.kun = [str(obj.reading) for obj in kanji_obj.kun]
out.goon = [format_reading(obj.reading) for obj in kanji_obj.goon]
out.kanon = [format_reading(obj.reading) for obj in kanji_obj.kanon]
out.toon = [format_reading(obj.reading) for obj in kanji_obj.toon]
out.soon = [format_reading(obj.reading) for obj in kanji_obj.soon]
out.kanyoon = [format_reading(obj.reading) for obj in kanji_obj.kanyoon]
out.kun = [format_reading(obj.reading) for obj in kanji_obj.kun]
out.meanings = kanji_obj.meanings
out.glyph_origin = kanji_obj.glyph_origin

View File

@ -29,12 +29,12 @@
<div id="readings-and-glyph-origin">
<div id="reading-box">
<ul id="reading-list-list">
{% if kanji.goon %}<li id="goon"><ul class="reading-list">{% for reading in kanji.goon %}<li class="goon-reading">{{reading}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.kanon %}<li id="kanon"><ul class="reading-list">{% for reading in kanji.kanon %}<li class="kanon-reading">{{reading}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.kanyoon %}<li id="kanyoon"><ul class="reading-list">{% for reading in kanji.kanyoon %}<li class="kanyoon-reading">{{reading}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.toon %}<li id="toon"><ul class="reading-list">{% for reading in kanji.toon %}<li class="toon-reading">{{reading}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.soon %}<li id="soon"><ul class="reading-list">{% for reading in kanji.soon %}<li class="soon-reading">{{reading}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.kun %}<li id="kun"><ul class="reading-list">{% for reading in kanji.kun %}<li class="kun-reading">{{reading}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.goon %}<li id="goon"><ul class="reading-list">{% for reading in kanji.goon %}<li class="goon-reading">{{reading|safe}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.kanon %}<li id="kanon"><ul class="reading-list">{% for reading in kanji.kanon %}<li class="kanon-reading">{{reading|safe}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.kanyoon %}<li id="kanyoon"><ul class="reading-list">{% for reading in kanji.kanyoon %}<li class="kanyoon-reading">{{reading|safe}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.toon %}<li id="toon"><ul class="reading-list">{% for reading in kanji.toon %}<li class="toon-reading">{{reading|safe}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.soon %}<li id="soon"><ul class="reading-list">{% for reading in kanji.soon %}<li class="soon-reading">{{reading|safe}}</li>{% endfor %}</ul></li>{% endif %}
{% if kanji.kun %}<li id="kun"><ul class="reading-list">{% for reading in kanji.kun %}<li class="kun-reading">{{reading|safe}}</li>{% endfor %}</ul></li>{% endif %}
</ul>
</div>
<div id="glyph-origin-box">