I have been using JSoup to parse lyrics and it has been great until now, but have run into a problem.
I can use Node.html()
to return the full HTML of the desired node, which retains line breaks as such:
Glóandi augu, silfurnátt
<br />Blóð alvöru, starir á
<br />Óður hundur er í vígamóð, í maga... mér
<br />
<br />Kolniður gref, kvik sem dreg hér
<br />Kolniður svart, hvergi bjart né
But has the unfortunate side-effect, as you can see, of retaining HTML entities and tags.
However, if I use Node.text()
, I can get a better looking result, free of tags and entities:
Glóandi augu, silfurnátt Blóe alv?ru, starir á óeur hundur er í vígamóe, í maga... mér Kolnieur gref, kvik sem dreg hér Kolnieur svart,
Which has another unfortunate side-effect of removing the line breaks and compressing into a single line.
Simply replacing <br />
from the node before calling Node.text()
yields the same result, and it seems that that method is compressing the text onto a single line in the method itself, ignoring newlines.
Is it possible to have the best of both worlds, and have tags and entities replaced correctly which preserving the line breaks, or is there another method or way of decoding entities and removing tags without having to replace them manually?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…