EmojiText icon indicating copy to clipboard operation
EmojiText copied to clipboard

Allow URLs to be embedded in emoji (as markdown)

Open yamanetaisei opened this issue 1 year ago β€’ 3 comments

@divadretlaw Thanks for developing such a great library!

I have one request.

This library doesn't allow to embed URLs in emoji with Markdown notation. When I convert the following String, it looks like this image.

[hoge](https://sample.com)
[:test:](https://sample.com)

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ 2024-01-24 0 18 52

The ideal behavior would be for the URL to be embedded in the emoji.

Is there any way to implement this? I can't come up with any good ideas. πŸ˜…

yamanetaisei avatar Jan 23 '24 15:01 yamanetaisei

Hello, sadly no this is definitely a current limitation.

The way EmojiText works is by using AttributedString(markdown:options:baseURL:) and splitting the runs of the AttributedString into Image and Text parts then merging them into a single Text via LocalizedStringKey.StringInterpolation & Text concatenation .

There are two main issues:

  1. The runs in AttributedString(markdown:options:baseURL:) doesn't contain the image information of the emoji. Seems like Apple's Markdown Renderer for AttributedString will simply drop this information
:test: [:test:](https://sample.com)

becomes the following AttributedString

test {
	NSImageURL = custom-emoji://test
}
  {
}
test {
	NSLink = https://sample.com
}

Here you can see that the 'emoji with a link' lost the NSImageURL as part of its attributes. I assume this is a limitation of AttributedString

  1. Even if I had the information, the link would possibly span multiple Text elements that then get concatenated together. Not sure if you could merge the Link for all of them into one or if it simply would result in multiple links.

divadretlaw avatar Jan 23 '24 21:01 divadretlaw

Also which version of EmojiText is this? With 3.3.0 the render should look different. At least when I try this

EmojiText(
    markdown: "[hoge](https://sample.com)\n[:test:](https://sample.com)",
    emojis: [
        RemoteEmoji(
            shortcode: "test",
            url: URL(string: "https://dummyimage.com/64x64/00f/fff&text=A")!
        )
    ]
)

it renders it like this

divadretlaw avatar Jan 23 '24 21:01 divadretlaw

Thanks for the detailed explanation! I will update to the latest version :+1:

which version of EmojiText is this?

I was using 3.0.2 by the way. 🀣 It's important to check the library for updates.γ€€

yamanetaisei avatar Jan 24 '24 13:01 yamanetaisei