How to print markdown in the terminal

I want to print styled markdown with colors and etc (the same way the REPL prints docs), instead of the raw text. So far i wasn’t able to figure out, i was thinking something like:

show(stdout, MIME"text/markdown", some_markdown)

But the above does not work.

Thanks in advance.

2 Likes

@dylanxyz - the most advanced rendering I have seen in the Julia REPL comes from Home · Term.jl - I don’t know of anything that prints styled markdown-like text in the REPL, but I think this tool is probably the best shot to do something like what you imagine.

P.S. @FedeClaudi is the author and is super active about the project!
CC’ing him to see this.

1 Like

Term.jl is a awesome package, however i could not find markdown related stuff when searching through the docs.

This will show up as styled Markdown text in the terminal (or in Jupyter, Pluto, etc.)

julia> using Markdown

julia> md"Some **bold** text"
  Some bold text

julia> Markdown.parse("Some **bold** text.")
  Some bold text.

That being said, it would be nice to support display("text/markdown", "Some **bold** text") in the REPL (this is already supported in e.g. Jupyter/IJulia).

3 Likes

Hey, the developer of Term here (thanks for the shotout @TheCedarPrince)

@dylanxyz that’s right, Term doesn’t currently support Markdown, but it should be a nice and easy feature to add. Python’s rich libray has it, all you need is to parse the markdown text into tokens (header, bullet point list…) and then use those to crate a styled text using Term’s markup syntax. Julia has markdown parsing so it should be pretty easy.

I’d be happy to work on it together if you want to help implement this, otherwise I will add it to the things to add to Term (finishing a coupe other features first)

2 Likes

This is what i want, but how to make this work outside the REPL?

> julia -e 'using Markdown; md"`Hello` *world*" |> println'
`Hello` *world*

As you can see, only the raw text is printed.

This would be a awesome feature to support!

julia -e 'using Markdown; md"`Hello` *world*" |> display'

(print by definition only writes the plain text show output.)

1 Like

Thank you! I was unaware of the display function.

Term.jl will have a markdown parser in the next version: Term.jl/markdown.jl at v4 · FedeClaudi/Term.jl · GitHub

stay tuned!

2 Likes

@FedeClaudi For now the display function works for me, but i’ll definitely use the Term.jl version once is ready :smile:.

No problem, this is what it’s going to look like though :smiley: https://twitter.com/Federico_claudi/status/1535034402018934784?s=20&t=ZUI796ZIWamwS-ZDeL8A5w


Uploading: image.png(1)…

I can give you a shout once it comes out if you’d like.

4 Likes

Awesome! I would appreciate :pray:.

Term.jl v1.0 is out with new Markdown parsing functionality: Markdown · Term.jl

1 Like

That’s so cool, thanks for your work :pray:!