AttributedTextView icon indicating copy to clipboard operation
AttributedTextView copied to clipboard

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

Open vgupt122 opened this issue 3 years ago • 2 comments

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.

vgupt122 avatar Dec 02 '20 12:12 vgupt122

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.

evermeer avatar Jan 10 '21 08:01 evermeer

Sure! I will try.

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


From: Edwin Vermeer [email protected] Sent: Sunday, January 10, 2021 2:18:16 PM To: evermeer/AttributedTextView [email protected] Cc: Gupta, Vivek N [email protected]; Author [email protected] 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.

vgupt122 avatar Jan 10 '21 08:01 vgupt122