# Concatenate markdown strings

**URL:** <https://discourse.julialang.org/t/concatenate-markdown-strings/59385>\
**Category:** General Usage\
**Tags:** markdown\
**Created:** [April 16, 2021, 5:25am UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385 "2021-04-16T05:25:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilipDLoewen](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@PhilipDLoewen](https://discourse.julialang.org/u/PhilipDLoewen)\
**Post date:** [April 16, 2021, 5:25am UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385/1 "2021-04-16T05:25:26Z")

</div>

For ordinary strings, `"as"*"df"` produces `"asdf"`. For markdown strings, `md"as"*md"df"` produces an error. So does `md_str("as"*"df")`. Is there any way to reinterpret a string with a complicated history as markdown?

Eventually I would like to generate markdown strings programmatically (for automatic display in a Pluto notebook). Resolution of the simplified question above would probably get me on the right track. Thanks!

---

<div class="post-metadata">

**Author:** ![HenrikM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrikm/32/17975_2.png) [@HenrikM](https://discourse.julialang.org/u/HenrikM)\
**Post date:** [April 16, 2021, 6:54am UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385/2 "2021-04-16T06:54:18Z")

</div>

This was an interesting question! After reading the source of `Markdown.jl` that is located in `julia/stdlib/v1.6/Markdown/src` I came up with this solution:

```julia
using Markdown
Markdown.parse("a"*"b")
str = "a"*"b"
Markdown.parse(str)

```

That is, we bypass the macro and call the underlying function directly.

---

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike/32/39_2.png) [@mike](https://discourse.julialang.org/u/mike)\
**Post date:** [April 16, 2021, 7:01am UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385/3 "2021-04-16T07:01:43Z")

</div>

> [@PhilipDLoewen](#):
>
> Eventually I would like to generate markdown strings programmatically (for automatic display in a Pluto notebook).

If you’re going to be generating a lot of text programmatically you may want to use an `IOBuffer` instead of string concatenation:

```julia
julia> io = IOBuffer();

julia> print(io, "a")

julia> print(io, "b")

julia> Markdown.parse(seekstart(io))
  ab

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [April 16, 2021, 7:18am UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385/4 "2021-04-16T07:18:04Z")

</div>

This isn’t quite right but maybe you can combine the `content` attributes of the objects.

```julia

julia> let x = md"hello"; y = md"world"; 
Markdown.MD(vcat(x.content[1].content , y.content[1].content)) 
end
"hello"

"world"

```

---

<div class="post-metadata">

**Author:** ![PhilipDLoewen](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@PhilipDLoewen](https://discourse.julialang.org/u/PhilipDLoewen)\
**Post date:** [April 16, 2021, 2:39pm UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385/5 "2021-04-16T14:39:25Z")

</div>

Perfect: two working methods in 4 lines total. Thank you! See also the contribution from `mike` below.

---

<div class="post-metadata">

**Author:** ![PhilipDLoewen](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@PhilipDLoewen](https://discourse.julialang.org/u/PhilipDLoewen)\
**Post date:** [April 16, 2021, 2:43pm UTC](https://discourse.julialang.org/t/concatenate-markdown-strings/59385/6 "2021-04-16T14:43:30Z")

</div>

Thank you. The earlier solution from `HenrikM` covers my needs completely, but this one includes extra info with no computational overhead. I’m marking this one as the solution go give impatient future searchers the fullest possible story.
