ActiveLabel.swift icon indicating copy to clipboard operation
ActiveLabel.swift copied to clipboard

HTML tags not working properly

Open zubingala opened this issue 2 years ago • 1 comments

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 avatar Nov 24 '21 13:11 zubingala

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

zubingala avatar Dec 23 '21 22:12 zubingala