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

Tag links stopped to respond in table view cells #173

Closed flvckx closed 9 months ago

flvckx commented 9 months ago

Hi!

After migrating to 5.0.4 from 4.10.1, tag links stopped to respond in table view cells in particular. I tested by adding it to your demo project and it doesn't respond there either.

I would appreciate your assistance here.

Here's a snippet I added to test on your demo project.

func myStringWithHtml() -> NSAttributedString {
    let all = Attrs()
        .foregroundColor(.black)
    let link = Attrs()
        .foregroundColor(.yellow)
        .font(.boldSystemFont(ofSize: 16))

    let a = TagTuner {
        link.akaLink($0.tag.attributes["href"] ?? "")
    }

    let li = TagTuner(attributes: Attrs().font(.systemFont(ofSize: 12)).foregroundColor(.red),
                      openingTagReplacement: "- ",
                      closingTagReplacement: "\n")
    let em = TagTuner(attributes: Attrs().font(.italicSystemFont(ofSize: 16)).foregroundColor(.brown))

    let str = "<p><strong>About Us</strong><br /><br />Together we’ve created an environment that we’re very proud of.<br />It is in the center of Gothenburg, with the beating heart of the city around the corner.<br />An open space for many of Gothenburgs tech meetups, where we regularly open the doors for interesting topics and workshops. If you’re curious about how we built it check out <a href=\"https://blog.forzafootball.com/the-worlds-best-office/\">our blog</a>!<br /><br />It is a space where we also have a lot of fun working and spending time on weekends; watching football together, playing video games, gathering friends or just hanging out in our great social areas.<br />The office also contains plenty of room for physical activities; sporting a table tennis table and a small football field.<br /></p><ol><li>We do not talk about Fight Club</li><li>We <em>do not</em> talk about Fight Club</li></ol>"
        .style(tags: ["a": a, "li": li, "em": em]).styleBase(all).styleLinks(link).attributedString

    return str
}

...

func allSnippets() -> [NSAttributedString] {
    return [
        myStringWithHtml(),
        stringWithAtributikaLogo(),
        stringWithTagsAndEmoji(),
        stringWithHashTagAndMention(),
        stringWithPhone(),
        stringWithLink(),
        stringWithBoldItalic(),
        stringWithManyDetectables(),
        stringWith3Tags(),
        stringWithGrams(),
        stringWithStrong(),
        stringWithTagAndHashtag(),
        stringWithUnorderedList(),
        stringWithOrderedList(),
        stringWithHref(),
        stringWithBoldItalicUnderline(),
        stringWithImage(),
        stringWithStrikethrough(),
        stringWithColors(),
        stringWithParagraph(),
        stringWithIndentedList(),
    ]
}
psharanda commented 9 months ago

Hi @flvckx,

Thanks a lot for reporting this critical issue! I was able to reproduce it; now it is fixed in 5.0.5 release.

One thing, in your example you tried snippets for the first tab where a vanilla UILabel is used, which doesn't support links highlighting. But again, the issue did present for AttributedLabel / AttributedTextView and was a severe one.

flvckx commented 9 months ago

Hey @psharanda! Thanks for a quick reply and a quick fix. Everything seems to be working now!