How performant is this compared to the the native decoding of html?
Closed this issue · 1 comments
freesuraj commented
You can convert html String
to NSAttributedString
the native way like this:
let htmlString = "some html string"
guard let data = htmlString.data(using: String.Encoding.utf16, allowLossyConversion: false) else {
return nil
}
guard let attributedString = try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) else {
return nil
}
let attributedString = NSAttributedString(attributedString: attributedString)
Have you done any benchmark of Ashton vs this method?
schwmi commented
Hi, for the supported subset of html tags, Ashton is substantially faster than the AppKit/UIKit alternatives. But keep in mind that Ashton handles only a very limited amount of HTML tags (as our decoding direction (used in MindNode) is like this: AttributedString -> HTML -> AttributedString). Basically, we support only tags which we need to encode our AttributedStrings. For the supported tags please refer to https://github.com/IdeasOnCanvas/Ashton/blob/master/README.md