# How can I display single spaced, multi-line text in Pluto?

**URL:** <https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483>\
**Category:** General Usage\
**Created:** [August 7, 2020, 8:51am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483 "2020-08-07T08:51:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [August 7, 2020, 8:51am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483/1 "2020-08-07T08:51:49Z")

</div>

Dear Pluto developers and users, I know that with Pluto, “print” goes to console, and that the (best?) way to get text displayed is to have cell result as markdown.  
I wanted to have “versioninfo()” displayed, which prints only, so I cooked the following 🙂 (originally without the commented “replace” line !)

```julia
begin
	iob=IOBuffer()
	versioninfo(iob)
	vinfo=read(seekstart(iob), String)
	# vinfo=replace(vinfo, "\n" => "\n\n")
	vmd=Markdown.parse(vinfo)
end

```

Then I got all concatened text :

```julia
Julia Version 1.5.0 Commit 96786e22cc (2020-08-01 23:44 UTC) Platform Info: OS: Windows (x8664-w64-mingw32) CPU: AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx WORDSIZE: 64 LIBM: libopenlibm LLVM: libLLVM-9.0.1 (ORCJIT, znver1) Environment: JULIA_EDITOR = vim

```

If I uncomment the “replace” line, then I correctly get line breaks, but, two of them for each line !  
Does somebody know I could get single spaced consecutive lines ?

Thanks ,  
JDAD

---

<div class="post-metadata">

**Author:** ![lyonsquark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyonsquark/32/4483_2.png) [@lyonsquark](https://discourse.julialang.org/u/lyonsquark)\
**Post date:** [August 8, 2020, 12:24am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483/2 "2020-08-08T00:24:58Z")

</div>

I’m guessing, but how about…

````julia
vmd=Markdown.parse("```\n$(vinfo)\n```")

````

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [August 8, 2020, 3:18am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483/3 "2020-08-08T03:18:18Z")

</div>

Not exactly elegant, but it does what you want. Ideally, you’d be able to insert `<br>` for this, but Julia’s markdown parser isn’t a superset of html like standard markdown is.

```julia
let io = IOBuffer()
	versioninfo(io)
	seekstart(io)
	vinfo = mapreduce(l -> "- " * l, *, eachline(io; keep=true))
	Markdown.parse(vinfo)
end

```

Alternatively instead of making it an unsorted list, you could wrap it in triple backticks or indent it by 4 spaces to indicate the text is pre-formatted. For some usecases involving preformatted text, this has the downside of generally being displayed in a fixed-width font.

````julia
let io = IOBuffer()
	write(io, "```\n")
	versioninfo(io)
	write(io, "\n```")
	seekstart(io)
	Markdown.parse(io)
end

````

Ideally you wouldn’t have to resort to hacks like this and Pluto would give you some way of a cell outputting plain, unformatted text. If there really isn’t a way of doing this, I think it’d be worthwhile to open an issue for it. EDIT: submitted [https://github.com/fonsp/Pluto.jl/issues/264](https://github.com/fonsp/Pluto.jl/issues/264).

---

<div class="post-metadata">

**Author:** ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)\
**Post date:** [August 8, 2020, 7:23am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483/4 "2020-08-08T07:23:11Z")

</div>

Hey! You can use this combination of magic spell words:

```julia
Text(sprint(versioninfo))

```

I believe that `sprint` does exactly the hack that you also invented (check the docs), and `Text` is a wrapper around `str`, such that when you `show` it, it writes the original characters, not their escape codes.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0d7bcabf578e65e9f6b9117515eb9e2d7b74a9d.png)

---

<div class="post-metadata">

**Author:** ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)\
**Post date:** [August 8, 2020, 7:27am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483/5 "2020-08-08T07:27:54Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/a/6/a626ae4b2f8012129225a4cd0184dd3267153bd9.png)

```julia
### A Pluto.jl notebook ###
# v0.11.4

using Markdown
using InteractiveUtils

# ╔═╡ 45a0f8b8-d948-11ea-0691-0b4b411a2674
md"`sprint` works by giving an `IOBuffer` as the first argument of the function that you gave. This only works if the function takes an `IO` as its first argument. 

The `Pkg` functions take `IO` as an optional keyword argument, so we have to do another trick:"

# ╔═╡ 8240a3aa-d947-11ea-083b-858ef1451c4e
Text(sprint(versioninfo))

# ╔═╡ 3409c97e-d948-11ea-3536-5999e4418ec9
Text(sprint(dump, [1,2,[3]]))

# ╔═╡ 81be742e-d948-11ea-2c29-b93dcb78b33f
import Pkg

# ╔═╡ 703a3256-d948-11ea-08de-0bbd3edecea6
Text(sprint(io -> Pkg.status(io=io)))

# ╔═╡ Cell order:
# ╠═8240a3aa-d947-11ea-083b-858ef1451c4e
# ╠═3409c97e-d948-11ea-3536-5999e4418ec9
# ╟─45a0f8b8-d948-11ea-0691-0b4b411a2674
# ╠═81be742e-d948-11ea-2c29-b93dcb78b33f
# ╠═703a3256-d948-11ea-08de-0bbd3edecea6

```

---

<div class="post-metadata">

**Author:** ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)\
**Post date:** [August 8, 2020, 7:49am UTC](https://discourse.julialang.org/t/how-can-i-display-single-spaced-multi-line-text-in-pluto/44483/6 "2020-08-08T07:49:42Z")

</div>

Dear @non-Jedi, @lyonsquark, many thanks for your help, that also gave me useful hints to possible other uses in my future programmings (Markdown and IOBuffer ones).

Dear @fonsp, I am honored by your detailed answer ! And, it is a very clean solution that works perfectly. Also, I didnt know of “sprint(function)”, so I am really enlighted now.

Could I suggest that in some future (when you have time/ if it suits you) you put this tip in your FAQ, for future reference to other newbies ?

Thank you again for your help and the wonderful “Pluto” work !

JDAD
