In-REPL pager for Markdown

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

3 Likes