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.

md"""
$(LocalResource(src[1]))
"""

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

str = "\n $(LocalResource(src[1]))\n "
Markdown.MD(str)
str = "\n $(LocalResource(src[1]))\n "
Markdown.parse(str)

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 https://github.com/fonsp/PlutoUI.jl/blob/dd099bce24dbe7d1eddbeac8d1dd3a1c6d230643/src/Resource.jl#L34 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"""
               $(LocalResource(src[1]))
               """
julia> typeof(str1.content[1])
Resource
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])
String
julia> str3 = Markdown.parse("\n $(LocalResource(src[1]))\n ")
  Resource("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB9AAAASwCAYAAACjJNG+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaH
...
AAkijQAQAAAAAAACBJ8heDUIYySuCIoAAAAABJRU5ErkJggg==",
  MIME type image/png, ())
julia> typeof(str3.content[1])
Markdown.Paragraph