Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML string not render #113

Open
TrungKhanhNguyen opened this issue Apr 9, 2020 · 5 comments
Open

HTML string not render #113

TrungKhanhNguyen opened this issue Apr 9, 2020 · 5 comments

Comments

@TrungKhanhNguyen
Copy link

TrungKhanhNguyen commented Apr 9, 2020

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

@petkrein
Copy link

petkrein commented May 5, 2020

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)

@rizwan95
Copy link

rizwan95 commented Jun 1, 2020

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

@altagir
Copy link

altagir commented Jun 4, 2020

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

@screenworker
Copy link

@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
Copy link

@rizwan9 because of:

public typealias AttributedString = NSMutableAttributedString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants