SwiftRichString icon indicating copy to clipboard operation
SwiftRichString copied to clipboard

HTML string not render

Open TrungKhanhNguyen opened this issue 5 years ago • 5 comments

I want display some HTML String for UITextView but its only display raw text. I dont know why Screenshot at Apr 09 16-01-39 Screenshot at Apr 09 16-03-02 Can you help me? Thanks I'm using xcode 11.4 & catalina 10.15.4

TrungKhanhNguyen avatar Apr 09 '20 09:04 TrungKhanhNguyen

extension String {
    func convertHtml() -> AttributedString {
        guard let data = data(using: .utf8) else { return AttributedString() }
        
        if let attributedString = try? AttributedString(data: data, options: [.documentType: AttributedString.DocumentType.html,
        .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) {
            return attributedString
        } else {
            return AttributedString()
        }
    }
}

example: self.textView.attributedText = tempText.convertHtml().set(style: style)

petkrein avatar May 05 '20 15:05 petkrein

@petkrein Why would you want to convert HTML to NSAttributedString using AttributedString's method? Doesn't the library do automatically?

rizwan95 avatar Jun 01 '20 12:06 rizwan95

using convertHtml is extremely slow I have a page with hundred html titles, and loading time went from 2s to 100s I was hoping this library was doing just that

altagir avatar Jun 04 '20 14:06 altagir

@altagir altagir:

using convertHtml is extremely slow I have a page with hundred html titles, and loading time went from 2s to 100s I was hoping this library was doing just that

As @TrungKhanhNguyen reported, the library does not appear to support this. I ran into the same problem and helped myself with the extension. And yes, it's very slow.

screenworker avatar Jun 04 '20 14:06 screenworker

@rizwan9 because of: https://github.com/malcommac/SwiftRichString/blob/a24bdce43b8d77eb845d0a3c605faf88e411eb8b/Sources/SwiftRichString/Style/StyleProtocol.swift#L33

screenworker avatar Jun 04 '20 14:06 screenworker