Atributika icon indicating copy to clipboard operation
Atributika copied to clipboard

No detection tag for an image's HTML tag in p's HTML tag

Open dmytrostriletskyi opened this issue 3 years ago • 1 comments

Hello,

thank you for the project I found very useful for my needs. However, I got some problems detecting img HTML tag in a p HTML tag.

My string looks like:

<p>Text.</p>
<p><string>Text.</strong></p>
<p><code>Text.</code></p>
<p><a href="http://jamf.com">Text.</a></p>
<p><img src="https://s.dou.ua/storage-files/image6_bCHHBMs.png"></p>

I use the following code (from this issue):

...
for detection in str.detections {
    switch detection.type {
    case .tag(let tag):
        ...
        // expecting tag with this attribute
        if let imageLink = tag.attributes["src"] {
        ...
    }
    default:
        break
    }
}

In the tag variable I can find these values:

Tag(name: "p", attributes: [:])
Tag(name: "code", attributes: [:])
Tag(name: "strong", attributes: [:])
Tag(name: "a", attributes: ["href": "http://jamf.com", "target": "_blank"])

But I won't find a tag for the image's HTML tag.

Just in case, I tried other types from the following class, but it didn't help:

public enum DetectionType {
    case tag(Tag)
    case hashtag(String)
    case mention(String)
    case regex(String)
    case phoneNumber(String)
    case link(URL)
    case textCheckingType(String, NSTextCheckingResult.CheckingType)
    case range
}

Can you please help with that? If it's on the library side, I'd be happy if you even provide instructions on how to adjust the library code itself (as a temporary solution).

Thank you in advance.

dmytrostriletskyi avatar Oct 06 '20 17:10 dmytrostriletskyi

I found the problem, my HTML doesn't have closed tags for images.

So instead of having:

<img src="https://s.dou.ua/storage-files/image6_bCHHBMs.png">

I should have:

<img src="https://s.dou.ua/storage-files/image6_bCHHBMs.png"></img>

What is slightly complicated as I parse HTML from a website dynamically.

dmytrostriletskyi avatar Oct 06 '20 17:10 dmytrostriletskyi

Fixed in V5

psharanda avatar Jun 04 '23 10:06 psharanda