# Programmatic Markdown in Pluto

**URL:** <https://discourse.julialang.org/t/programmatic-markdown-in-pluto/68936>\
**Category:** Pluto\
**Tags:** images, pluto, pluto-markdown\
**Created:** [September 29, 2021, 2:38pm UTC](https://discourse.julialang.org/t/programmatic-markdown-in-pluto/68936 "2021-09-29T14:38:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [September 29, 2021, 2:38pm UTC](https://discourse.julialang.org/t/programmatic-markdown-in-pluto/68936/1 "2021-09-29T14:38:23Z")

</div>

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.

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

```

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

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

```

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

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [September 29, 2021, 3:11pm UTC](https://discourse.julialang.org/t/programmatic-markdown-in-pluto/68936/2 "2021-09-29T15:11:52Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Daneel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneel/32/175_2.png) [@Daneel](https://discourse.julialang.org/u/Daneel)\
**Post date:** [September 30, 2021, 8:20am UTC](https://discourse.julialang.org/t/programmatic-markdown-in-pluto/68936/3 "2021-09-30T08:20:22Z")

</div>

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
julia> str1 = md"""
               $(LocalResource(src[1]))
               """
julia> typeof(str1.content[1])
Resource

```

```julia
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
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

```
