How can I remove or hide HTML tags
from the text so that links are not removed? I tried a lot of ways, the most effective at the bottom. but they do not fit, I now use html2AttributedString
and it fits almost all the criteria except one I did not find a way to resize the photo. Who knows how to remove all tags from the text except the links? I will be very thankful for the solution.
example string:
<p class=\"entry\">\r\n\t 24-й Форум книгоиздателей Украины во Львове определил лауреатов конкурса «Лучшая книга-2017».\r\n</p>\r\n<p>\r\n\t В номинации «Город – Киев» победила книга «Бабий Яр: история и память».
<img width=\"600\" alt=\"№39---11.jpg\" src=\"http://---.com/upload/medialibrary/35f/35f50dc1765f977140baa604c30be7a.jpg\" height=\"465\" title=\"№39---11.jpg\"> \r\n</p>\r\n<p>\r\n\t
Сборник статей под редакцией Вячеслава Гриневича и Павла-Роберта Магочия стал результатом сотрудничества ученых из разных стран – Украины, Канады, Нидерландов, США, Израиля, Франции, которых объединило осознание важности сохранения памяти о Бабьем Яре как символе Холокоста и других трагедий XX столетия.\r\n</p>\r\n<p>\r\n\t Книга вышла в свет в киевском издательстве «Дух и Литера».\r\n</p>
<br>Источник: <a href=http://---.org/page16/news58701.html>Сайт</a>`
code:
extension String {
var html2AttributedString: NSAttributedString? {
do {
return try NSAttributedString(data: Data(utf8), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch {
print(error)
return nil
}
}
var html2String: String {
return html2AttributedString?.string ?? ""
}
}
override func viewDidLoad() {
super.viewDidLoad()
textView.attributedText = detail?.text?.html2AttributedString
textView.font = UIFont(name: "roboto-light", size: 19)
}