One more clue that might be helpful. I am using tidy::repairString() on incoming HTML, and that generates classes like 'tidy-1'. It may be that those classes are affecting this issue. I am going to try and make sure they are integrated into the final doc.