Rendering image tags
rizwan95 opened this issue · 9 comments
Hello @zhgchgli0718
First of all thanks for making this wonderful framework. The framework works great with almost all html tags.
My question is what about Image tags?
Image tags are the most widely used in HTML.
Hi, thanks for using ZMarkupParser
We are currently considering and researching the possibility of supporting <img>
rendering. Rendering images requires an asynchronous job to download the image data, and displaying the image data directly using NSTextAttachment may cause out-of-memory issues. This is because the native NSTextAttachment does not support reuse, so all image data will be kept in memory. We need to conduct further research on TextKit or rely on third-party libraries like XLYTextKitExtension to find the best solution.
Thanks for the reply @zhgchgli0718
You are right. NSTextAttachment is not efficient when rendering images.
I have been researching this problem for a while. I would love to share my knowledge and help you find a solution.
Hi, it's actually very convenient to extend ZMarkupParser. I'll make ZMarkupParser support rendering <img>
tags first, and add a delegate, such as a resource downloader, to let users handle image URLs and convert them to data.
I'm considering creating a new method using Combine to allow users to retrieve the downloaded image NSAttachment asynchronously.
It'll be released first, we will handle the NSAttachment out-of-memory problem later.
next stage,
If you could provide some assistance with NSAttachment out-of-memory problem, it would be very helpful!
Hi,
That's a wonderful news!
Okay I can help you out with NSAttachment out-of-memory issue.
Also, instead of Combine, you can also use AsyncStream if you want :)
thanks for your information! @rizwan95
Hi, @rizwan95
I've created a new module called ZNSTextAttachment, which can handle the operation of downloading images from remote URLs. This module can be used to implement any image-loading optimization ideas we may have.
and I have already created branch #7 that supports rendering the tag. Please feel free to review it and leave any comments if you have any questions or concerns.
@zhgchgli0718 Amazing work! I will look into the possibilities to improve the loading time.
resolved in 1.3.0