Remove <ruby> furigana before generating readings #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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:
<ruby>
removal and bracket notation removal. Use cases:<ruby>
)<rp>
tag. The original implementation required a format of<ruby>日本語<rp>...
in order to work. If you didn't include the<rp>
tag (which is optional in the HTML specification), it would throw errors. It worked in the general flow because this tool always included the<rp>
tag. I've reimplemented this to decouple from a particular structure and to just remove<rp>
and<rt>
tags to arrive at the body instead.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.