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

Images do not nest in html #118

Closed
daslu opened this issue Mar 22, 2022 · 8 comments
Closed

Images do not nest in html #118

daslu opened this issue Mar 22, 2022 · 8 comments

Comments

@daslu
Copy link

daslu commented Mar 22, 2022

The following example:

(ns images
  (:require [nextjournal.clerk :as clerk]))

(import javax.imageio.ImageIO
        java.net.URL)

(clerk/html
 [:div
  [:h1 "image1"]
  (ImageIO/read (URL. "https://images.unsplash.com/photo-1532879311112-62b7188d28ce?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8"))
  [:h1 "image2"]
  (ImageIO/read (URL. "https://images.unsplash.com/photo-1532879311112-62b7188d28ce?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8"))])

results in the following:
clerk-example

Thanks!

@jackrusher
Copy link
Collaborator

I have no idea what you had expected to happen in this case.

@daslu
Copy link
Author

daslu commented Mar 22, 2022

Thanks,

Here is the Slack discussion for reference:
https://clojurians.slack.com/archives/C035GRLJEP8/p1647906226495609

What I was wondering about was how to embed BufferedImage values in a Hiccup block.

@jackrusher
Copy link
Collaborator

The linked Slack thread doesn't make clear what output you might have expected given the semantics of clerk/html, which in turn leaves me unsure how to help you.

@daslu
Copy link
Author

daslu commented Mar 24, 2022

I might have expected to see the corresponding images inside the div, since typically, Clerk viewer types nest.

Edit:
But I was wondering about it too, still new to Clerk semantics.
This is documented as an Issue here simply because I was asked to do that on the Slack thread.

@jackrusher
Copy link
Collaborator

Let me try to refine my question a bit: if you are using the html viewer to build a hiccup representation of some HTML you would like to show the user, what would it mean to dump the binary data of an image in the middle?

I would expect something like [:img {:src (url-for (ImageIO/read ...))}] in this place so that you have control over the CSS applied to the element, can supply click handlers, and so on. (Note that this currently doesn't work! But to come up with a good solution that gives the user full power and no magic, we need to consider what should happen.)

@daslu
Copy link
Author

daslu commented Mar 25, 2022

Thanks, yes, I'm not sure about the desired API.

So, maybe the ticket title should have been: "What is the recommended practice for showing a few images in a div?".

A few thoughts:

  • Currently, a top-level form returning a BufferedImage just renders as an image in the Clerk notebook, without asking the user to care about serving it through a URL, etc.
  • This is quite useful. Example use cases:
    • The user is doing some image processing and wants to just see the resulting image.
    • The user is getting an image from a plotting library (e.g., cljplot) and just wants to see it.
  • I think that Clerk tends to render things (e.g., Vega plots) the same when nested inside a div and when not.
  • I think this kind of consistency is nice. That is probably what made me assume some desired behavior here.

@jackrusher
Copy link
Collaborator

I agree that serving BufferedImages as visible images is useful, that's why we made that feature! In this case, it's not clear what we want to do inside html blocks, so there's going to be some design work around what feels right. :)

mk added a commit that referenced this issue Feb 21, 2023
Until now `present*` took a `:path` and `:current-path` argument would have a code path to descend into the nested data structure when resolving an elision. This drops this code path and uses a continuation function for a path instead.

We also add support for customizing the per-result budget using the `:nextjournal.clerk/budget` param and support using images inside `clerk/html`, fixing #118.
@mk
Copy link
Member

mk commented Feb 21, 2023

@daslu it took a while but it's now working with a8c5102:
Screen Shot 2023-02-21 at 15 43 58

@mk mk closed this as completed Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants