Format non-okurigana part of kanji readings in bold
This commit is contained in:
parent
e6be4107f5
commit
ae7501bb2e
@ -67,6 +67,19 @@ def create_app(test_config=None):
|
|||||||
else:
|
else:
|
||||||
return update_settings(request.form)
|
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>")
|
@app.route("/kanji/<kanji>")
|
||||||
def kanji_page(kanji: str):
|
def kanji_page(kanji: str):
|
||||||
kanji_obj = get_kanji_by_character(kanji)
|
kanji_obj = get_kanji_by_character(kanji)
|
||||||
@ -81,12 +94,12 @@ def create_app(test_config=None):
|
|||||||
out.strokes = kanji_obj.stroke_count
|
out.strokes = kanji_obj.stroke_count
|
||||||
out.radical = kanji_obj.radical
|
out.radical = kanji_obj.radical
|
||||||
out.added_strokes = kanji_obj.radical_added_stroke_count
|
out.added_strokes = kanji_obj.radical_added_stroke_count
|
||||||
out.goon = [str(obj.reading) for obj in kanji_obj.goon]
|
out.goon = [format_reading(obj.reading) for obj in kanji_obj.goon]
|
||||||
out.kanon = [str(obj.reading) for obj in kanji_obj.kanon]
|
out.kanon = [format_reading(obj.reading) for obj in kanji_obj.kanon]
|
||||||
out.toon = [str(obj.reading) for obj in kanji_obj.toon]
|
out.toon = [format_reading(obj.reading) for obj in kanji_obj.toon]
|
||||||
out.soon = [str(obj.reading) for obj in kanji_obj.soon]
|
out.soon = [format_reading(obj.reading) for obj in kanji_obj.soon]
|
||||||
out.kanyoon = [str(obj.reading) for obj in kanji_obj.kanyoon]
|
out.kanyoon = [format_reading(obj.reading) for obj in kanji_obj.kanyoon]
|
||||||
out.kun = [str(obj.reading) for obj in kanji_obj.kun]
|
out.kun = [format_reading(obj.reading) for obj in kanji_obj.kun]
|
||||||
out.meanings = kanji_obj.meanings
|
out.meanings = kanji_obj.meanings
|
||||||
out.glyph_origin = kanji_obj.glyph_origin
|
out.glyph_origin = kanji_obj.glyph_origin
|
||||||
|
|
||||||
|
@ -29,12 +29,12 @@
|
|||||||
<div id="readings-and-glyph-origin">
|
<div id="readings-and-glyph-origin">
|
||||||
<div id="reading-box">
|
<div id="reading-box">
|
||||||
<ul id="reading-list-list">
|
<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.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}}</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}}</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}}</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}}</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}}</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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="glyph-origin-box">
|
<div id="glyph-origin-box">
|
||||||
|
Loading…
Reference in New Issue
Block a user