yomichan
yomichan copied to clipboard
[Feature Request] Alternative to {cloze-prefix}, {cloze-suffix} and {cloze-body} which uses {sentence-furigana} instead of {sentence}
Using a construction like {cloze-prefix}<span class="word">{furigana}</span>{cloze-suffix}
or {cloze-prefix}<b>{cloze-body}</b>{cloze-suffix}
a nice and easy solution to mark the word in the sentence which is of interest. Unfortunately, there doesn't seem to be an option to combine this with automatic furigana generation for the rest of the sentence.
Hence, I think an alternative to the {cloze-***}
tags, called e.g. {cloze-furigana-***}
which utilise {sentence-furigana}
instead of {sentence}
would be a great help.
I actually wanted something like this myself not too long ago. I ended up just merging {cloze-***}
and {sentence-furigana}
.
This is the result:
{{#*inline "sentence-furigana-plain"}}
{{~#if definition.cloze~}}
{{~#if (op "?:" (hasMedia "textFurigana" definition.cloze.prefix) (hasMedia "textFurigana" definition.cloze.body) (hasMedia "textFurigana" definition.cloze.suffix))~}}
{{#regexReplace "<rt>" "[" "g"~}}
{{#regexReplace "</rt>" "]" "g"~}}
{{#regexReplace "(<ruby>)" " " "g"~}}
{{#regexReplace "(</ruby>)" "" "g"~}}
{{#getMedia "textFurigana" definition.cloze.prefix escape=false}}{{/getMedia}}<b>{{#getMedia "textFurigana" definition.cloze.body escape=false}}{{/getMedia}}</b>{{#getMedia "textFurigana" definition.cloze.suffix escape=false}}{{/getMedia}}
{{~/regexReplace}}
{{~/regexReplace}}
{{~/regexReplace}}
{{~/regexReplace}}
{{~else~}}
{{definition.cloze.prefix}}<b>{{definition.cloze.body}}</b>{{definition.cloze.suffix}}
{{~/if~}}
{{~/if~}}
{{/inline}}
The regex just makes it so that it acts like {furigana-plain}
. Remove the {{regexReplace}}
to make it act like {furigana}
.
You can apply furigana to any text you want by modifying the Anki handlebars templates, similar to what @Skillesss posted. The general form is:
{{~#if (hasMedia "textFurigana" TEXT_VARIABLE)~}}
{{#getMedia "textFurigana" TEXT_VARIABLE escape=false}}{{/getMedia}}
{{~else~}}
{{TEXT_VARIABLE}}
{{~/if~}}
Replace TEXT_VARIABLE
with the variable you want.
Examples: definition.cloze.prefix
, definition.cloze.suffix
, definition.cloze.body
, etc.