obynio / anki-japanese-furigana

Anki add-on providing support for adding furigana on Japanese text
https://ankiweb.net/shared/info/678316993
GNU General Public License v3.0
17 stars 5 forks source link

Remove <ruby> furigana before generating readings #19

Closed ahlec closed 1 year ago

ahlec commented 1 year ago

Before we run the current field through mecab.reading to attach furigana, line 60 correctly removes the bracket notation furigana already in the input string. This prevents clicking the button multiple times from compounding the readings. However, <ruby> markup is not removed before sending for generation, which compounds additional readings:

image

To fix this, I extracted the code from the "delete furigana" button into a reusable utility function removeFurigana. We then use this to remove readings before sending the text through generation.

In doing this, I fixed a couple of bugs with the furigana deletion logic:

I've added some unit tests to test these behaviors.

I've tested this in both 2.1.54 (M1 Silicon) and 2.1.49 (Mac Intel) and it loads and works as expected.

obynio commented 1 year ago

A very nice work as always. I never paid attention to this behaviour, thank you for the fix and the unit tests. The code is much cleaner this way ! I will merge this and release a 1.3.2 update.