-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
markdown: Add support for 
syntax for images.
#29300
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
base: main
Are you sure you want to change the base?
Conversation
When writing tests https://spec.commonmark.org/0.18/#images, may be a good source of things to try. Since we're using upstream code, we may not find it easy to match CommonMark on everything, but it should be cheap to at least know where we're diverging. |
zerver/lib/markdown/__init__.py
Outdated
if not any(src.endswith(ext) for ext in IMAGE_EXTENSIONS): | ||
# If the url is not a previewable image, gracefully fall back to a regular link | ||
return self.link_processor.handleMatch(m, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 
syntax indicates that the user knows this is an image. Not all images use an extension. We should give the user the image they asked for, not pretend we know “better”.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd observed the convert-unsupported-image-to-link behavior here in GitHub actually, but I now understand the merits of letting it be as is, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example from GitHub of this detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timabbott On writing something like 
here in github, it renders as a plain link. Example:
I've addressed most of the feedback above, most importantly moved the html wrangling for presentation of inline images to the frontend, but I'm still working on refining things further. I'm yet to add backend tests, write a proper commit message, potentially split this across multiple commits, etc |
05aa2f9
to
ec6644f
Compare
Have added tests and cleaned up the code and commit structure, this is ready for another review! |
The reference style multiline syntax does not work, and any text inside |
55a133c
to
d226bbe
Compare
@zulipbot add "chat.zulip.org. review" |
ERROR: Label "chat.zulip.org. review" does not exist and was thus not added to this pull request. |
@zulipbot add "chat.zulip.org review" |
I merged the first two commits as the series ending with 633d814. |
So if you upload 3 images at once via dragging them or via selecting multiple files in the image picker, one gets two regression-looking outcomes:
|
That is because we always put every upload (whether image or any other allowed format) in it's own line, so that's how they show up. What exact alternative behaviour are you proposing here @timabbott? |
Hm, yeah, the image arrangement might be OK? |
I'm not sure why exactly it is needed currently, but removing the baseline alignment for |
That commit is necessary for the overall grid alignment in the message box. What I think needs to be applied here are the styles introduced in #26942 to the &:has(> .message_inline_image:first-child),
&:has(> p > .message_inline_image:first-child) {
align-self: center;
} It might be possible to tidy up and simplify that selector, but we'd have to watch very carefully for similar regressions that that might introduce. Also, it does appear in testing that the fallback work with |
For image arrangement, I think if you drag multiple images at once or select multiple in your browser in a single operation, it's probably more correct to put the images on a line together. Not sure if that's easy, but it was a major UX improvement when we made multiple linked images wrap on a single line (#20975), and this PR effectively undoes that feature from a practical standpoint. |
@karlstolley Thanks a lot for linking to that PR, I faintly remembered it but couldn't find it. Since the problem was not for inline images that were 1st in their paragraph, but for any 1st paragraph containing an inline image, I've added the selector |
If there's any text at all, that could give you a false negative. Test with just the image by itself, without any text. Your selector looks good to me, but I just want to make sure you're testing under the right/problem circumstances. |
@timabbott I've added a prep commit that puts all uploads made in one go on the same line. This means for all kinds of uploads, not just images, each link text will be inserted inline together all in 1 block, while the previews will be as before (horizontally stacked in another paragraph). For the new Is this okay? |
Hmm, this might be fairly ugly in the case that you upload a mixture of previewable elements and non-previewable elements. |
@timabbott That's true |
Yeah, that rule is probably a solid one. |
@timabbott Made the change! Now only for uploads with multiple image-only type files, are the files all added in their own line, so they render as being stacked horizontally |
The standard markdown syntax for images is now supported in Zulip. Unlike linked image previews (which is the only way images could be added so far), images added using the `` syntax are truly inline, so are placed in the message exactly where the syntax is, not in a separate paragraph. Fixes: zulip#28912.
So far, each file was always inserted on its own line. Now for images uploaded together, they're inserted inline, all in a single block. This is so that images stack horizontally when uploaded together.
Images added using the `` syntax are rendered in a fixed size, expandable via lightbox, exactly like the linked image previews, except inline. For drafts which are only rendered by the frontend markdown processor, images are rendered as a regular link, for now.
Heads up @N-Shar-ma, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
markdown: Render inline images as small lightbox previews in place.
Images added using the

syntax are rendered in a fixed size, expandable via lightbox, exactly like the linked image previews, except inline.For drafts which are only rendered by the frontend markdown processor, images are rendered as a regular link, for now.
markdown: Add support for

syntax for inline images.The standard markdown syntax for images is now supported in Zulip. Unlike linked image previews (which is the only way images could be added so far), images added using the

syntax are truly inline, so are placed in the message exactly where the syntax is, not in a separate paragraph.Fixes: #28912.
upload: Rename variable
filename_url
tosyntax_to_insert
.This variable holds the markdown syntax for a file that's to be inserted into a message, hence the new name.
copy_and_paste: Fix bug where an unlabelled image could be pasted twice.
This commit removes the unnecessary condition for a linked image to have a label when checking whether to skip an image preview if its generating link has already been copied.
Screenshots and screen captures:



Composing:
Previewing:
Drafted:
Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: