psharanda / Atributika

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.
MIT License
1.45k stars 155 forks source link

Support for parsing links with custom attribute for a tag #84

Closed LoileeBooz closed 5 years ago

LoileeBooz commented 5 years ago

My HTML string is this:


let text = "<a target=\"_blank\" data-mobile-use=\"form://formTermsOfUse\" href=\"https://www.google.com\">Terms of use</a>"

let links = Style("a")
            .font(UIFont.customFont(size: 12)(.regular))
            .foregroundColor(CXColor.linkBlue(), .normal)
            .foregroundColor(CXColor.linkBlue(), .highlighted)
print(text.style(tags: links).styleLinks(links).styleAll(defaultStyle).attributedString)

OUTPUT: Terms of use{ NSColor = "UIExtendedSRGBColorSpace 0.0588235 0.454902 0.560784 1"; NSFont = "<UICTFont: 0x7b500000fe00> font-family: \"AktivGrotesk-Regular\"; font-weight: normal; font-style: normal; font-size: 12.00pt"; }

EXPECTED: Terms of use{ NSColor = "UIExtendedSRGBColorSpace 0.298039 0.298039 0.298039 1"; NSFont = "<UICTFont: 0x7b500000f600> font-family: \"AktivGrotesk-Regular\"; font-weight: normal; font-style: normal; font-size: 12.00pt"; NSLink = "https://www.google.com/"; }

I am not able to parse the string that should be set to NSLink = "https://www.google.com" Is it because of the custom attribute inside the a tag?