flip flipping words flip

This commit is contained in:
Nitsud Yarg 2026-06-25 20:39:53 -07:00
parent 2c4d95fb8d
commit e888384af1
2 changed files with 20 additions and 11 deletions

View File

@ -131,23 +131,24 @@ def get_card_proficiency(query="deck:current"):
# Anki queue mappings:
# 0 = New, 1 = Learning, 2 = Review, 3 = Relearning
# https://www.w3.org/TR/webvtt1/#default-text-color
if queue_state == 0:
status = "New"
color = ''
color = 'red'
elif queue_state == 1:
status = "Learning"
color = 'orangered'
color = 'yellow'
elif queue_state == 3:
status = "Relearning"
color = 'yellow'
color = 'lime'
elif queue_state == 2:
# Review card split by 21-day threshold
if interval >= 21:
status = "Mature"
color = 'cyan'
color = 'magenta'
else:
status = "Young"
color = 'lime'
color = 'cyan'
elif queue_state < 0:
status = "Suspended"
color = ''
@ -216,9 +217,15 @@ def should_ruby(surface, reading_hiragana):
return True
def build_ruby(surface: str, reading: str) -> str:
if not reading or surface == reading or not has_japanese(surface):
if not reading or not has_japanese(surface):
return html.escape(surface)
return f"<ruby>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>"
style_attr = ''
if proficiency_stats.get(surface):
if proficiency_stats[surface]['Color'] != '':
style_attr = f"style=\"color:{proficiency_stats[surface]['Color']}\""
if surface == reading:
return f"<span {style_attr}>{html.escape(surface)}</span>"
return f"<ruby {style_attr}>{html.escape(surface)}<rt>{html.escape(reading)}</rt></ruby>"
def build_sub_cue(surface: str, reading: str) -> str:
if not reading or not has_japanese(surface):
@ -417,6 +424,7 @@ def analyze(text: str, vocab: Dict[str, Dict]):
tokens: List[TokenReading] = []
ruby_parts = []
subtitle_parts = []
kana_parts = []
vocab_link_parts = []
@ -452,6 +460,7 @@ def analyze(text: str, vocab: Dict[str, Dict]):
tokens.append(token)
ruby_parts.append(build_ruby(surface, reading))
subtitle_parts.append(build_sub_cue(surface, reading))
kana_parts.append(build_kana(surface, reading))
predicate_chunks = chunk_predicates(tokens)
@ -461,6 +470,7 @@ def analyze(text: str, vocab: Dict[str, Dict]):
"original_text": text,
"kana_reading": "".join(kana_parts),
"ruby_html": "".join(ruby_parts),
"sub_cue": "".join(subtitle_parts),
"notes_link":"".join(vocab_link_parts),
"token_readings": [asdict(t) for t in tokens],
"predicate_chunks" : predicate_chunks,

View File

@ -70,11 +70,10 @@ def main():
if has_japanese(lines[i]):
print(lines[i])
result = analyze(lines[i],vocab)
print(result['kana_reading'])
notes_lines.append(result["ruby_html"] + "\n" )
notes_lines.append(result["sub_cue"] + "\n" )
notes_lines.append (result['notes_link'] + "\n")
if lines[i] != result['ruby_html']:
lines[i] = result['ruby_html'] + "\n" # lost the new line
if lines[i] != result['sub_cue']:
lines[i] = result['sub_cue'] + "\n" # lost the new line
# if lines[i] != result['kana_reading']:
# lines[i] = result['kana_reading'] + "\n" # lost the new line
else: