indragiek / CocoaMarkdown

Markdown parsing and rendering for iOS and OS X
MIT License
1.2k stars 158 forks source link

Supporting URLRequest in inline image download #59

Open rizwan95 opened 4 years ago

rizwan95 commented 4 years ago

Hi, is there any way to add URLRequest in the inline image download method? @indragiek

jlj commented 4 years ago

Hi @rizwan95, Currently the image download is handled by a simple download task and only a base URL can be configured (typically for images using relative links).

Could you provide more information about your use case, and about the type of URLRequest customization you would need?

rizwan95 commented 4 years ago

@jlj Sometimes we might need to send additional headers like user-agent and authorization headers for downloading images from authenticated services. So, it would be very helpful if there is a way to send them.

rizwan95 commented 4 years ago

@jlj Any update on this?

jlj commented 4 years ago

A possible option could be to add a imageURLSession property of type NSURLSession in CMAttributedStringRenderer. If set, this imageURLSession property would then be used to retrieve every remote image referenced by the current document.

At creation time, the imageURLSession property could receive any desired NSURLSessionConfiguration, providing thus a high level of customizability to image download.

@rizwan95 Would this solution respond to your needs?

rizwan95 commented 4 years ago

@jlj : Yes, that would solve the problem! Infact it will open up a lot of opportunities for customizability.

jlj commented 4 years ago

@rizwan95 I have implemented this imageURLSession property change in my CocoaMarkdown fork at https://github.com/jlj/CocoaMarkdown/tree/5512cf52d292288e1748e7bde097e5b28a7e52b6

Can you test it with your specific server configuration? If it is ok, I will issue a pull request.

rizwan95 commented 4 years ago

@jlj Yes sure!

jlj commented 4 years ago

@rizwan95 Have you made tests of this imageURLSession property?

rizwan95 commented 4 years ago

Not yet, I will test it today and let you know @jlj Sorry for the delay!

jlj commented 4 years ago

@rizwan95 Any test result?

rizwan95 commented 4 years ago

Hi @jlj I tested the given patch. It is not rendering basic markdown content itself. :( I suppose something is broken..