Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving HTML entities while preserving line breaks with JSoup
    primarykey
    data
    text
    <p>I have been using <a href="http://jsoup.org/" rel="nofollow">JSoup</a> to parse lyrics and it has been great until now, but have run into a problem.</p> <p>I can use <code>Node.html()</code> to return the full HTML of the desired node, which retains line breaks as such:</p> <pre><code>Gl&amp;oacute;andi augu, silfurn&amp;aacute;tt &lt;br /&gt;Bl&amp;oacute;&amp;eth; alv&amp;ouml;ru, starir &amp;aacute; &lt;br /&gt;&amp;Oacute;&amp;eth;ur hundur er &amp;iacute; v&amp;iacute;gam&amp;oacute;&amp;eth;, &amp;iacute; maga... m&amp;eacute;r &lt;br /&gt; &lt;br /&gt;Kolni&amp;eth;ur gref, kvik sem dreg h&amp;eacute;r &lt;br /&gt;Kolni&amp;eth;ur svart, hvergi bjart n&amp;eacute; </code></pre> <p>But has the unfortunate side-effect, as you can see, of retaining HTML entities and tags.</p> <p>However, if I use <code>Node.text()</code>, I can get a better looking result, free of tags and entities:</p> <pre><code>Glóandi augu, silfurnátt Blóð alvöru, starir á Óður hundur er í vígamóð, í maga... mér Kolniður gref, kvik sem dreg hér Kolniður svart, </code></pre> <p>Which has another unfortunate side-effect of removing the line breaks and compressing into a single line.</p> <p>Simply replacing <code>&lt;br /&gt;</code> from the node before calling <code>Node.text()</code> yields the same result, and it seems that that method is compressing the text onto a single line in the method itself, ignoring newlines.</p> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload