kit-nya / anki_furigana

This is an addon for Anki that provides automatic population of a definition and correctly formatted ruby text
GNU General Public License v3.0
1 stars 1 forks source link

Create HTML ordered list for definitions #3

Open HeyyD opened 3 hours ago

HeyyD commented 3 hours ago

Instead of hardcoding the definitions field formatting, the field could be created as an ordered list. This way there user can style the cards more flexibility using own css styles.

diff --git a/kanji_furi.py b/kanji_furi.py
index ad1c799..2ecae15 100644
--- a/kanji_furi.py
+++ b/kanji_furi.py
@@ -64,7 +64,7 @@ def build_dict_from_xml(root):
         for i, sense in enumerate(entry.iter('sense'), start=1):
             glosses = [gloss.text for gloss in sense.iter('gloss')]
             gloss_text = '; '.join(glosses)
-            senses[i] = f"{i}: {gloss_text}"
+            senses[i] = f"{gloss_text}"
         reb = entry.findall('r_ele/reb')[0].text.strip()
         for ke in keb_entries:
             if ke not in output:
@@ -78,7 +78,11 @@ def get_senses(dict_item, limit=5):
     for number in numbers:
         if number in dict_item["senses"]:
             arry.append(dict_item["senses"][number])
-    return "<br>".join(arry)
+    if len(arry) == 1:
+        # Return the single item as plain text
+        return arry[0]
+
+    return f"<ol>{''.join(f'<li>{item}</li>' for item in arry)}</ol>"

 def search_def(root, keb_text, def_limit=0):
     return_val = ""

Example of styled ordered list

image

kit-nya commented 3 hours ago

Hi!

Thanks for the feedback! The hard coding was working for what I wanted, but if there's a better way to do it that works for everyone then I'm all for it!

I'll merge this change tomorrow and publish an update.

Edit:forgot to say thanks for providing the example code!