Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for images in Markdown previews #16192

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

dovakin0007
Copy link
Contributor

@dovakin0007 dovakin0007 commented Aug 14, 2024

Closes #13246

Release Notes:
added image preview for markdown

mark_down_img_preview.-.Made.with.Clipchamp.mp4

Release Notes:

  • Added support for images to the markdown preview

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Aug 14, 2024
@dovakin0007 dovakin0007 changed the title add markdown image preview Markdown: Image preview Aug 14, 2024
@Angelk90
Copy link

@dovakin0007 : Does it also work using the img tag?

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/200px-HTML5_logo_and_wordmark.svg.png" alt="Image description" width="300"/>

@dovakin0007
Copy link
Contributor Author

@dovakin0007 : Does it also work using the img tag?

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/200px-HTML5_logo_and_wordmark.svg.png" alt="Image description" width="300"/>

no sir

@Angelk90
Copy link

@dovakin0007 : What is displayed in case of the alt message?

@dovakin0007
Copy link
Contributor Author

dovakin0007 commented Aug 14, 2024

@dovakin0007 : What is displayed in case of the alt message?

the alt text like zed gpui image doesn't have a way to display the alt text so for now I am displaying alt text directly
image this text will be shown if image fails or unable to find the image in path
image
else we display image
interactive image needs to be added though

@maxdeviant maxdeviant changed the title Markdown: Image preview markdown: Add image preview Aug 20, 2024
@maxdeviant maxdeviant changed the title markdown: Add image preview Add support for images in Markdown previews Aug 20, 2024
crates/markdown_preview/src/markdown_parser.rs Outdated Show resolved Hide resolved
crates/markdown_preview/src/markdown_parser.rs Outdated Show resolved Hide resolved
@dovakin0007
Copy link
Contributor Author

I want to raise one more issue it seems like the image is not rendering in same line
image like the above example any ideas and contributions will be helpful here

@mikayla-maki
Copy link
Contributor

mikayla-maki commented Aug 29, 2024

Seems like there's some test failures as well. I'm going to mark this as draft for now, once things are ready to go feel free to mark it as ready :)

As for your issues with the layout, perhaps you need to add some more styling rules on the img perhaps usingblock() (equivalent to display: block)?

@mikayla-maki mikayla-maki marked this pull request as draft August 29, 2024 17:37
@bennetbo
Copy link
Collaborator

bennetbo commented Aug 30, 2024

I haven't looked at the PR in the detail, but I assume that we will run into the same issues I encountered in #10565.
In particular there are these two issues:

  1. Gpui cannot handle images in the middle of a paragraph, I think there are two ways we can address this:
  • Split up paragraph's that contain images and render each text and image as their own block (This is what I did in markdown preview: Image support #10565)
  • Add support for this in gpui (seems like a lot of work though)
  1. The img element needs better error handling, right now if a link is malformed or does not return an image, we fetch it over and over again. This wastes unnecessary resources and network bandwidth.

Rendering images in separate lines feels like a good enough workaround for now, but 2. definitely feels like a blocker to me.

@dovakin0007
Copy link
Contributor Author

Seems like there's some test failures as well. I'm going to mark this as draft for now, once things are ready to go feel free to mark it as ready :)

As for your issues with the layout, perhaps you need to add some more styling rules on the img perhaps usingblock() (equivalent to display: block)?

yeah that should work. regarding the layout we have to render the image within text StyledText can't handle images for now

@dovakin0007
Copy link
Contributor Author

I haven't looked at the PR in the detail, but I assume that we will run into the same issues I encountered in #10565. In particular there are these two issues:

  1. Gpui cannot handle images in the middle of a paragraph, I think there are two ways we can address this:
  • Split up paragraph's that contain images and render each text and image as their own block (This is what I did in markdown preview: Image support #10565)
  • Add support for this in gpui (seems like a lot of work though)
  1. The img element needs better error handling, right now if a link is malformed or does not return an image, we fetch it over and over again. This wastes unnecessary resources and network bandwidth.

Rendering images in separate lines feels like a good enough workaround for now, but 2. definitely feels like a blocker to me.

yeah I am running into the same issues that you have mentioned.

@dovakin0007
Copy link
Contributor Author

dovakin0007 commented Aug 31, 2024

I haven't looked at the PR in the detail, but I assume that we will run into the same issues I encountered in #10565. In particular there are these two issues:

  1. Gpui cannot handle images in the middle of a paragraph, I think there are two ways we can address this:
  • Split up paragraph's that contain images and render each text and image as their own block (This is what I did in markdown preview: Image support #10565)
  • Add support for this in gpui (seems like a lot of work though)
  1. The img element needs better error handling, right now if a link is malformed or does not return an image, we fetch it over and over again. This wastes unnecessary resources and network bandwidth.

Rendering images in separate lines feels like a good enough workaround for now, but 2. definitely feels like a blocker to me.
Maybe we can split the text into multiple blocks which will allow us to render image between text that can fix 1?

@dovakin0007 dovakin0007 marked this pull request as ready for review September 7, 2024 11:46
@dovakin0007
Copy link
Contributor Author

still img() doesn't return error for bad request

@dovakin0007
Copy link
Contributor Author

dovakin0007 commented Sep 8, 2024

I was able to render the image within

markdown_preview_2.mp4

text

crates/markdown_preview/src/markdown_elements.rs Outdated Show resolved Hide resolved
crates/markdown_preview/src/markdown_elements.rs Outdated Show resolved Hide resolved
crates/markdown_preview/src/markdown_parser.rs Outdated Show resolved Hide resolved
@MatinAniss
Copy link
Contributor

MatinAniss commented Sep 13, 2024

Support for inline elements in the text system is probably the better choice if the text and inline elements needs to wrap properly. Splitting the text and images into their own blocks is just avoiding the problem that will eventually be needed to be implemented. It may be fine for now.

I've tried to implement it myself, but there are some changes and some decisions which I'm not sure what is best.

I have had a issue up to track this #10916

@dovakin0007
Copy link
Contributor Author

Support for inline elements in the text system is probably the better choice if the text and inline elements needs to wrap properly. Splitting the text and images into their own blocks is just avoiding the problem that will eventually be needed to be implemented. It may be fine for now.

I've tried to implement it myself, but there are some changes and some decisions which I'm not sure what is best.

I have had a issue up to track this #10916

Yeah I did try to do it but I wasn't on the right track so I scrapped it then for now implemented to render image as its separate own block rather than a part of interactive text yeah you are right once interactive text supports inline images this has to be changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support images in Markdown preview
5 participants