gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.53k stars 318 forks source link

Inline image in text in Markdown not shown #185

Closed huber-florian closed 1 year ago

huber-florian commented 1 year ago

Describe the bug Prior to the newest major release, it was possible to embed images directly in the text. Since the major update it does not work any more.

Checklist

Steps to reproduce Markdown("2.\n\n This is \n\nContext Class (2 of 2 tests passing) ").markdownImageProvider(.asset) Markdown("2.\n This is \n\nContext Class (2 of 2 tests passing) ").markdownImageProvider(.asset) Markdown("2.\n\n This is \nContext Class (2 of 2 tests passing) ").markdownImageProvider(.asset) Markdown("2. This is Context Class (2 of 2 tests passing) ").markdownImageProvider(.asset) Markdown("2. This is Context Class (2 of 2 tests passing) ").markdownImageProvider(.asset) Markdown("2. This is Context Class (2 of 2 tests passing) ").markdownImageProvider(.asset)

(The "This is" part from above: ! [This is] (TestFailedSymbol) )(without spaces!) (The last 3 statements have a different amount of whitespaces to test if that changes something.)

Expected behavior The expected behavior would be that in all six cases the TestFailedSymbol is shown. (Works also with the dog image of the given example.) But only in the first two cases the image is shown. The second screenshot shows that it was possible to embed an image within the text prior to this major update.

Screenshots Experiments now (version 2.0.0):

image

Well working solution before (version 1.x): image

Version information

gonzalezreal commented 1 year ago

Hi @huber-florian,

Thanks for reporting this issue. It is a side-effect of re-implementing the Markdown rendering with SwiftUI primitives. I have some ideas to fix it for this particular use case. Unfortunately, other use cases, like images inside links with inline text, are impossible to fix until Apple correctly supports images in AttributedString.

https://swiftpackageindex.com/gonzalezreal/swift-markdown-ui/2.0.0/documentation/markdownui/inlineimage

gonzalezreal commented 1 year ago

Hi @huber-florian,

The fix for this issue is now available in the main branch. Please take a look at the Demo project in the Images and Image Providers screens for the inline image support and the new markdownInlineImageProvider modifier.

huber-florian commented 1 year ago

Thank you @gonzalezreal ! It works like a charm.