From 75989e2aefab7015cc629e2193858e21179951c1 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Tue, 23 Jun 2020 13:05:27 -0700 Subject: [PATCH] Fixed tts:rubyReserve on lines starting with a ruby container (#184) --- src/main/js/html.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/js/html.js b/src/main/js/html.js index 87280800..44d7307a 100644 --- a/src/main/js/html.js +++ b/src/main/js/html.js @@ -786,10 +786,34 @@ } - var e = lineList[i].elements[0].node.parentElement.insertBefore( - ruby, - lineList[i].elements[0].node - ); + /* add in front of the first ruby element of the line, if it exists */ + + var sib = null; + + for (var j = 0; j < lineList[i].rbc.length; j++) { + + if (lineList[i].rbc[j].localName === 'ruby') { + + sib = lineList[i].rbc[j]; + + /* copy specified style properties from the sibling ruby container */ + + for(var k = 0; k < sib.style.length; k++) { + + ruby.style.setProperty(sib.style.item(k), sib.style.getPropertyValue(sib.style.item(k))); + + } + + break; + } + + } + + /* otherwise add before first span */ + + sib = sib || lineList[i].elements[0].node; + + sib.parentElement.insertBefore(ruby, sib); }