chrisdhaan / CDMarkdownKit

An extensive Swift framework providing simple and customizable markdown parsing.
MIT License
254 stars 65 forks source link

CDMarkdownTextView: Load local images #2

Closed karstengresch closed 6 years ago

karstengresch commented 6 years ago

What did you do?

Tried to use a local image (added to main bundle) referencing it via:

![my image](my-image.png)
![my image](./my-image.png)
![my image](file://my-image.png)
![my image](file://./my-image.png)

What did you expect to happen?

The image should at least once be loaded like an external image e.g.

![my external image](http://www.christopherdehaan.me/public/img/circle-hover.png)

which works fine.

What happened instead?

No image loaded.

Instead, console told about a NSURLConnection finished with error - code -1002 error. IIUC this is a not supported protocol.

CDMarkdownKit Environment

CDMarkdownKit version: 0.9.7
Xcode version: 9.2 (9C40b) Swift version: 4.0.3 Platform(s) running CDMarkdownKit: iOS Simulator w/ iOS 11.2 (15C107) macOS version running Xcode:: 10.13.2 (17C205)

I used CDMarkdownTextView and could successfully load a local image with:


let myImage = UIImage(named: "my-image.png")
let attachment: NSTextAttachment = NSTextAttachment()
attachment.image = thumbnailImage
let attributedImageString: NSAttributedString = NSAttributedString(attachment: attachment)
cdMarkdownTextView.textStorage.append(attributedImageString)

Rough guess it's related to CDMarkdownImage's url handling.

Demo Project

TBD, matter of time...

chrisdhaan commented 6 years ago

@karstengresch this is a good find. I see you opened a PR with a proposed solution. I'll get it happy so it works with the tests and hopefully have a new version up this weekend.

karstengresch commented 6 years ago

Hi @chrisdhaan - thanks very much!

chrisdhaan commented 6 years ago

@karstengresch the local image loading has been pushed to master.