# In-REPL pager for Markdown

**URL:** <https://discourse.julialang.org/t/in-repl-pager-for-markdown/51768>\
**Category:** General Usage\
**Tags:** markdown\
**Created:** [December 13, 2020, 5:44pm UTC](https://discourse.julialang.org/t/in-repl-pager-for-markdown/51768 "2020-12-13T17:44:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [December 13, 2020, 5:44pm UTC](https://discourse.julialang.org/t/in-repl-pager-for-markdown/51768/1 "2020-12-13T17:44:45Z")

</div>

I’m trying to print Markdown output to the terminal, which I can accomplish with…

```julia
using Markdown

md_str = md"# My Header"
display(md_str)

```

Ideally, I’d like to print this to a **pager** , not the REPL itself. However, `InteractiveUtils.less` only supports `::AbstractString`s.

Is there any way to do this with code similar to the following code?

```julia
using Markdown
using InteractiveUtils

md_str = md"# My Header"
less(md_str)

```

---

<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:** [December 13, 2020, 7:59pm UTC](https://discourse.julialang.org/t/in-repl-pager-for-markdown/51768/2 "2020-12-13T19:59:10Z")

</div>

`less` can interpret ANSI control sequences that get written by the `Markdown.term` method that’s used to print markdown in the REPL. So with the following you can kind of get what you’re after I think.

```julia
julia> using Markdown

julia> function InteractiveUtils.less(md::Markdown.MD)
           withenv("PAGER" => "less -R -f") do
               file = tempname()
               open(io -> Markdown.term(io, md), file, "w")
               less(file)
               rm(file)
           end
       end

julia> less(@doc +)

```

You need to change some of the PAGER flags to correctly interpret the ANSI sequences (`-R`) and to force (`-f`) it to open what may appear to be a binary file to the pager.

I believe there’s an open issue about making use of the pager to display docs in the REPL, so if anyone what’s to use this as a starting point they’re more than welcome to.

---

<div class="post-metadata">

**Author:** ![cadojo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cadojo/32/25328_2.png) [@cadojo](https://discourse.julialang.org/u/cadojo)\
**Post date:** [December 14, 2020, 4:09pm UTC](https://discourse.julialang.org/t/in-repl-pager-for-markdown/51768/3 "2020-12-14T16:09:12Z")

</div>

Awesome, thank you for the detailed answer!
