update japanese sentences

This commit is contained in:
Ren Tatsumoto 2023-03-05 03:48:00 +03:00
parent 32e4c7dc5c
commit 13c95cbbd0

View file

@ -116,7 +116,6 @@ Sun Mar 5 12:08:06 AM UTC 2023
} }
function formatNewRuby(kanji, readings) { function formatNewRuby(kanji, readings) {
console.log(kanji, readings)
if (readings.length > 1) { if (readings.length > 1) {
return `<ruby>${formatNewRuby(kanji, readings.slice(0, -1))}</ruby><rt>${readings.slice(-1)}</rt>` return `<ruby>${formatNewRuby(kanji, readings.slice(0, -1))}</ruby><rt>${readings.slice(-1)}</rt>`
} else { } else {
@ -125,15 +124,19 @@ Sun Mar 5 12:08:06 AM UTC 2023
} }
function reformatMultiFurigana() { function reformatMultiFurigana() {
const separators = /[\s,.、・。]+/iu; const separators = /[\s;,.、・。]+/iu;
document.querySelectorAll("ruby").forEach(ruby => { document.querySelectorAll("ruby").forEach(ruby => {
const kanji = ruby.querySelector("rb").textContent try {
const readings = ruby.querySelector("rt") const kanji = (ruby.querySelector("rb") || ruby.firstChild).textContent.trim()
.textContent.split(separators) const readings = ruby.querySelector("rt").textContent
.map(str => str.trim()) .split(separators)
.filter(str => str.length) .map(str => str.trim())
if (readings.length > 1) { .filter(str => str.length)
ruby.innerHTML = formatNewRuby(kanji, readings) if (readings.length > 1) {
ruby.innerHTML = formatNewRuby(kanji, readings)
}
} catch (error) {
console.error(error);
} }
}) })
} }