import Foundation
import UIKit
extension String {
func convertHtml(using font: UIFont?) -> NSAttributedString {
var str = self
if let font = font {
str = "<div style=\"font-family: '\(font.familyName)'\">\(self)</div>"
}
guard let data = str.data(using: .unicode) else { return NSAttributedString() }
do {
return try NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
}