Programmatic Markdown in Pluto

I want to programmatically generate markdown for a cell in a Pluto notebook to display a series of images. The following hard-coded markdown works. src is a list of local image files.


If I do this programmatically it interprets the image as text.

str = "\n $(LocalResource(src[1]))\n "
str = "\n $(LocalResource(src[1]))\n "

What am I doing wrong?

I don’t know the specifics, but it could be that the type of LocalResource has different show methods for String and Markdown.
When you write "$(something)" then Julia tries to make sense of something as a String and when you write md"$(something)" then Julia tries to make sense of something as a Markdown string.

In your case, it is probably this method PlutoUI.jl/Resource.jl at dd099bce24dbe7d1eddbeac8d1dd3a1c6d230643 · fonsp/PlutoUI.jl · GitHub which is called in the Markdown case (since it can embed HTML).

You could try
repr(MIME"text/html"(), LocalResource(srr[1]))
and see if that output helps you.

How is the md""" Something """ syntax parsed? It only partially interprets the contained text. md"""\n$(LocalResource(src[1]))""" will load the resource but the \n will show up as \n.

julia> str1 = md"""
julia> typeof(str1.content[1])
julia> str2 = Markdown.MD("\n $(LocalResource(src[1]))\n ")
"\n Resource(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB9AAAASwCAYAAACjJNG+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiw
AAAAAkijQAQAAAAAAACBJ8heDUIYySuCIoAAAAABJRU5ErkJggg==\", MIME type image/png, ())\n "
julia> typeof(str2.content[1])
julia> str3 = Markdown.parse("\n $(LocalResource(src[1]))\n ")
  MIME type image/png, ())
julia> typeof(str3.content[1])