gonzalezreal / swift-markdown-ui

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

Add support for asset catalog images #48

Closed markiv closed 2 years ago

markiv commented 3 years ago

Using the asset scheme, you can now load images from your bundled asset catalog. This lets you use vector formats (PDF and SVG), specify appearance, scale and device variants, etc.

Markdown(
    #"""
    This is a local asset image:
    ![Dog](resource:///dog)    
    """#
)

To load all images from an assset catalog by default, set the base URL like this:

.markdownBaseURL(.mainBundleResources)
markiv commented 3 years ago

¡Buena idea! I'll update my PR.

gonzalezreal commented 2 years ago

Hey @markiv, I already merged asset catalog images support in the release-1.0 branch, together with other breaking changes I am making for the upcoming 1.0 release, which is still a work in progress. I came up with an API that it's more flexible and allows the library user to choose the bundle and URL scheme for asset catalog images. Here is an example:

Markdown(
  #"""
  ![Puppy](asset:///puppy)

  Photo by André Spieker.
  """#
)
.setImageHandler(.assetImage(in: .module), forURLScheme: "asset")

Thanks for proposing this change; it truly makes the library better.