evermeer / AttributedTextView

Easiest way to create an attributed UITextView (with support for multiple links and from html)
Other
440 stars 55 forks source link

<a href> </a> Anchor tags are not clickable (only detected as html link) #35

Closed vgupt122 closed 1 year ago

vgupt122 commented 3 years ago

In The below example Anchor tags are detected as html link but not clickable <a href=\'https://www.someurlink?username=12345'>Vivek Gupta

I used like below

self.descriptionLabel.attributer = text.html.matchHashtags.makeInteract({ [weak self] (hashTag) in
            guard let slf = self else {return}
            slf.delegate?.tappedLink(string: hashTag)
            print(hashTag)
        }).matchMentions.makeInteract({ [weak self] (mentionsText) in
            guard let slf = self else {return}
            slf.delegate?.tappedLink(string: mentionsText)
            print(mentionsText)
        }).matchLinks.font(BrandManager.currentStyle.typography.boldFont(pts: 12)).makeInteract({ [weak self] (linkText) in
            guard let slf = self else {return}
            slf.delegate?.tappedLink(string: linkText)
            print(linkText)
        }).font(UIFont.regularFont(pts: 12)).setLinkColor(.red)

the 'text' variable has html string.

Has anyone got this issue. Please help.

evermeer commented 3 years ago

Do you mean that the hashtags and mentions are working but the links not? Is your HTML using <a href markup? Then if so the matchLinks will only find thelinks inside your HTML tags. In your sample Vivek Gupta it will find the https://www.someurlink?username=12345 and make that clickable. but your html rendering will hide that part and only show Vivek Gupta and that will look like a link because of the HTML rendering, but you won't be able to click it. The .html will use the basic NSAttributedText functionality for parsing html to an NSAttributedTekst. I'm not sure if there is a way to find all links inside that parsed tekst. If you know what text would be inside the link, then you could search for that and make that clickable. So find Vivek Gupta and execute a .makeInteract on that.

vgupt122 commented 3 years ago

Sure! I will try.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Edwin Vermeer notifications@github.com Sent: Sunday, January 10, 2021 2:18:16 PM To: evermeer/AttributedTextView AttributedTextView@noreply.github.com Cc: Gupta, Vivek N vivek.gupta122@optum.com; Author author@noreply.github.com Subject: Re: [evermeer/AttributedTextView] Anchor tags are not clickable (only detected as html link) (#35)

Do you mean that the hashtags and mentions are working but the links not? Is your HTML using <a href markup? Then if so the matchLinks will only find thelinks inside your HTML tags. In your sample Vivek Guptahttps://www.someurlink?username=12345 it will find the https://www.someurlink?username=12345 and make that clickable. but your html rendering will hide that part and only show Vivek Gupta and that will look like a link because of the HTML rendering, but you won't be able to click it. The .html will use the basic NSAttributedText functionality for parsing html to an NSAttributedTekst. I'm not sure if there is a way to find all links inside that parsed tekst. If you know what text would be inside the link, then you could search for that and make that clickable. So find Vivek Gupta and execute a .makeInteract on that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/evermeer/AttributedTextView/issues/35#issuecomment-757440345, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQ5V6ITF5IB27KY4H2RL6IDSZFSVBANCNFSM4UKNJRKQ.

This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.