Как убрать ненужные символы из атрибутного текста, преобразованного из html? - PullRequest
0 голосов
/ 25 апреля 2020

Я использую этот код для преобразования html -текстовой строки в attributeString.

if let description = article.description {
    let data = Data(description.utf8)
    if let attributedString = try? NSMutableAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil) {
        attributedString.addAttributes([NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18), NSAttributedString.Key.foregroundColor: UIColor.subtitleColor], range: NSRange(location: 0, length: attributedString.length))
        articleView.contentTextView.attributedText = attributedString
     }
}

и странные символы, выходящие , как здесь . Как их удалить?

описание это

<p>Greece prepares to end lockdown; Bill Gates vows to fund vaccine production; Australia and New Zealand mark Anzac Day from driveways</p><ul><li><a href="https://www.theguardian.com/world/2020/apr/24/revealed-leader-group-peddling-bleach-cure-lobbied-trump-coronavirus">Leader of group peddling bleach as‘cure’ wrote to Trump this week</a><br></li><li><a href="https://www.theguardian.com/world/2020/apr/24/sweden-queries-basis-of-lockdowns-as-germany-keeps-its-guard-up">Global report: Sweden queries lockdowns as Germany keeps guard up</a></li><li><a href="https://www.theguardian.com/world/2020/apr/25/coronavirus-latest-at-a-glance-25-april">Coronavirus latest: at a glance</a></li><li><a href="https://www.theguardian.com/world/live/2020/apr/24/coronavirus-us-live-news-trump-cuomo-georgia-cases-latest">US coronavirus updates– live</a><br></li><li><a href="https://www.theguardian.com/world/coronavirus-outbreak">See all our coronavirus coverage</a></li></ul><p class="block-time published-time"><time datetime="2020-04-25T14:09:45.760Z">3.09pm<span class="timezone">BST</span></time></p><p>Today is World Malaria Day. As we approach 200,000 deaths so far this year from Covid-19, it’s worth remembering that the World Health Organization has warned that<a href="https://www.theguardian.com/global-development/2020/apr/23/pandemic-could-turn-back-the-clock-20-years-on-malaria-deaths-warns-who">deaths from malaria could double to 700,000 this year</a>as a result of the disruption caused by the new disease.</p><p lang="en" dir="ltr">As we work on tackling<a href="https://twitter.com/hashtag/COVID19?src=hash&amp;ref_src=twsrc%5Etfw">#COVID19</a>, we can't afford to lose ground on the gains we have made against other diseases like malaria.<br><br>On<a href="https://twitter.com/hashtag/WorldMalariaDay?src=hash&amp;ref_src=twsrc%5Etfw">#WorldMalariaDay</a>I join<a href="https://twitter.com/WHO?ref_src=twsrc%5Etfw">@WHO</a>'s call for maintained malaria prevention&amp; treatment services during the<a href="https://twitter.com/hashtag/coronavirus?src=hash&amp;ref_src=twsrc%5Etfw">#coronavirus</a>crisis to save lives.<a href="https://twitter.com/vtm3X6twva">pic.twitter.com/vtm3X6twva</a></p><p><span>Related:</span><a href="https://www.theguardian.com/global-development/2020/apr/23/pandemic-could-turn-back-the-clock-20-years-on-malaria-deaths-warns-who">Pandemic could 'turn back the clock' 20 years on malaria deaths, warns WHO</a></p><p class="block-time published-time"><time datetime="2020-04-25T13:53:37.287Z">2.53pm<span class="timezone">BST</span></time></p><p>Dozens of doctors and nurses in<strong>Pakistan</strong>have launched a hunger strike over a lack of protective masks and other equipment for treating patients with Covid-19.</p><p>More than 150 doctors in Pakistan have tested positive for coronavirus, according to the Young Doctors Association in Punjab, the country’s worst-hit province.<br tabindex="-1"></p><a href="https://www.theguardian.com/world/live/2020/apr/25/coronavirus-live-news-brazils-health-system-on-verge-of-collapse-medics-warn">Continue reading...</a>
...