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 tags not working properly #410

Open
zubingala opened this issue Nov 24, 2021 · 1 comment
Open

HTML tags not working properly #410

zubingala opened this issue Nov 24, 2021 · 1 comment

Comments

@zubingala
Copy link

zubingala commented Nov 24, 2021

func htmlAttributed(size: CGFloat) -> NSAttributedString? {
            do {
                let htmlCSSString = "<style>" +
                    "html *" +
                    "{" +
                    "font-size: \(size)pt !important;" +
                "}</style> \(self)"

                guard let data = htmlCSSString.data(using: String.Encoding.utf8) else {
                    return nil
                }

                return try NSAttributedString(data: data,
                                              options: [.documentType: NSAttributedString.DocumentType.html,
                                                        .characterEncoding: String.Encoding.utf8.rawValue],
                                              documentAttributes: nil)
            } catch {
                print("error: ", error)
                return nil
            }
        }


let text = "<b> Bold</b><i> Italic</i> <u>Underline</u>"
 self.activeLabel.attributedText = text.htmlAttributed(size: 15)

Output
Bold Italic Underline

Its returning everything in bold instead of desired output.

@zubingala
Copy link
Author

zubingala commented Dec 23, 2021

@schickling, @maziyarpanahi , @polqf please look into this.

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

1 participant