gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.26k stars 267 forks source link

Images not showing up when using Markdown #57

Closed kevoniori closed 2 years ago

kevoniori commented 3 years ago

I'm parsing markdown content from the Contentful CMS into my app. The texts and links are all formatted and displayed as they should (e.g. lists, bold, links, italics, etc.), however, when I insert images, they won't load. The image URL structure is the same as is documented to use with Markdown UI but they won't come up. It will come up in the preview editor from Contentful but inside my app nothing shows. Is this something to do with markdown UI or is there another piece of functionality I need to call from the Module?

kevoniori commented 3 years ago

Attached are two examples. One of how it looks when the app launches and the other from the Contentful backend.

Screen Shot 2021-07-08 at 2 15 30 PM Simulator Screen Shot - iPhone 12 Pro Max - 2021-07-08 at 14 15 13

gonzalezreal commented 2 years ago

Hi, It looks like the image URLs in your example are relative URLs. Therefore, you must use the markdownBaseURL modifier to set a base URL for the images, as demonstrated in the companion demo app:

https://github.com/gonzalezreal/MarkdownUI/blob/890d6341bd5c487df0b1f7dae04173fb9963f565/Examples/MarkdownUIDemo/Shared/ReadMeView.swift#L18

kevoniori commented 2 years ago

This helped so alot. Images are showing up now, thanks much @gonzalezreal