Sanitizing the data

Some of the articles display HTML tags in the summary. Usually these tags are fine because the summary is displayed in a viewer that supports HTML, but in our case we don't, so it's better to get rid of them.

To do this, we just need to tweak asyncFetchArticles() to cut the description if a div element is found:

.map {
val title = it.getElementsByTagName("title")
.item(0)
.textContent
var summary = it.getElementsByTagName("description")
.item(0)
.textContent

if (!summary.startsWith("<div")
&& summary.contains("<div")) {
summary = summary.substring(0, summary.indexOf("<div"))
}


Article(feed.name, title, summary)
}

Now all the articles look okay – notice that we cut the div only if the summary is not starting with one, to avoid having empty summaries. See updated results below:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.240