I'd suggest that you're overcomplicating this. If you want to gloss a romanisation for each word, wrap each word in its own ruby element. It will always appear above the correct word, even if there's line wrapping. If, on the other hand, you want to add a semantic gloss, for example to writeحَوّامتي مُمْتِلئة بِأَنْقَلَيْسون with "my hovercraft is full of eels" above, then you'd wrap the whole sentence in a ruby element