diff --git a/kanken_online/__init__.py b/kanken_online/__init__.py
index 1ba085a..0ee952b 100644
--- a/kanken_online/__init__.py
+++ b/kanken_online/__init__.py
@@ -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. 選: えら-ぶ --> えらぶ. For reading strings which don't have any "-" character in them,
+ one is added to the end and the entire reading is emboldened.
+ Example: 簡: かん --> かん
+ """
+ if "-" not in reading:
+ reading += "-"
+
+ okurigana_position = reading.index("-")
+ emboldened_part = reading[:okurigana_position]
+ return f"{emboldened_part}{reading[okurigana_position+1:]}"
+
@app.route("/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
diff --git a/kanken_online/templates/kanji.html b/kanken_online/templates/kanji.html
index de90383..c3a18a7 100644
--- a/kanken_online/templates/kanji.html
+++ b/kanken_online/templates/kanji.html
@@ -29,12 +29,12 @@
- {% if kanji.goon %}{% for reading in kanji.goon %}- {{reading}}
{% endfor %}
{% endif %}
- {% if kanji.kanon %}{% for reading in kanji.kanon %}- {{reading}}
{% endfor %}
{% endif %}
- {% if kanji.kanyoon %}{% for reading in kanji.kanyoon %}- {{reading}}
{% endfor %}
{% endif %}
- {% if kanji.toon %}{% for reading in kanji.toon %}- {{reading}}
{% endfor %}
{% endif %}
- {% if kanji.soon %}{% for reading in kanji.soon %}- {{reading}}
{% endfor %}
{% endif %}
- {% if kanji.kun %}{% for reading in kanji.kun %}- {{reading}}
{% endfor %}
{% endif %}
+ {% if kanji.goon %}{% for reading in kanji.goon %}- {{reading|safe}}
{% endfor %}
{% endif %}
+ {% if kanji.kanon %}{% for reading in kanji.kanon %}- {{reading|safe}}
{% endfor %}
{% endif %}
+ {% if kanji.kanyoon %}{% for reading in kanji.kanyoon %}- {{reading|safe}}
{% endfor %}
{% endif %}
+ {% if kanji.toon %}{% for reading in kanji.toon %}- {{reading|safe}}
{% endfor %}
{% endif %}
+ {% if kanji.soon %}{% for reading in kanji.soon %}- {{reading|safe}}
{% endfor %}
{% endif %}
+ {% if kanji.kun %}{% for reading in kanji.kun %}- {{reading|safe}}
{% endfor %}
{% endif %}