Stream: helpdesk (published)

Topic: ✔ How to print `markdown` text?


view this post on Zulip Mason Protter (Feb 27 2024 at 13:44):

If I do

julia> using Markdown

julia> str = md"""
       hi

       ```
       1 + 1
       ```
       """;

then display will print the markdown string in a nice way:
image.png
but print and show and friends all fail to do it:
image.png

Is there a way to do this without display? I need to specify a specific output stream, which you can't do with display.

view this post on Zulip Mason Protter (Feb 27 2024 at 13:45):

cc @Timothy since I suspect you're the expert on this

view this post on Zulip Fredrik Ekre (Feb 27 2024 at 13:50):

Markdown.term I think?

view this post on Zulip Timothy (Feb 27 2024 at 14:01):

Yep! Markdown.term(::IO, ::Markdown.MD) is what you want.

view this post on Zulip Mason Protter (Feb 27 2024 at 14:02):

ah cool. It'd be good if this was documented then

view this post on Zulip Timothy (Feb 27 2024 at 14:02):

Yea. Reminds me, I really should get a move on with checkdoc...

view this post on Zulip Mason Protter (Feb 27 2024 at 14:03):

in particular, does Markdown.term fail gracefully if io doesn't support fancy outputs?

view this post on Zulip Sebastian Pfitzner (Feb 27 2024 at 14:04):

actually, why is that the bevhaviour of show for markdown objects? seems like the show method should check the output streams capabilities (just color is probably enough), no?

view this post on Zulip Timothy (Feb 27 2024 at 14:04):

in particular, does Markdown.term fail gracefully if io doesn't support fancy outputs?

Yes

view this post on Zulip Mason Protter (Feb 27 2024 at 14:04):

very annoying, since show is supposed to be the function that does that

view this post on Zulip Timothy (Feb 27 2024 at 14:05):

IMO it should behave like you expect

view this post on Zulip Mason Protter (Feb 27 2024 at 14:15):

In any case, thanks both of you!

view this post on Zulip Notification Bot (Feb 27 2024 at 14:15):

Mason Protter has marked this topic as resolved.

view this post on Zulip Mason Protter (Feb 27 2024 at 15:13):

This is what it was getting used for btw, in case anyone is curious: https://github.com/JuliaObjects/Accessors.jl/pull/140

It's nice to have markdown formatting for register_error_hint.

view this post on Zulip Timothy (Feb 27 2024 at 15:13):

I was curious :)

view this post on Zulip Timothy (Feb 27 2024 at 15:14):

I think that use of Experimental API isn't quite right though IIRC

view this post on Zulip Timothy (Feb 27 2024 at 15:15):

I think the version check should be replaced with a isdefined(Base.Experimental, :register_error_hint) check

view this post on Zulip Mason Protter (Feb 27 2024 at 15:16):

The version check was there because I was trying to avoid a failure on 1.6. The original PR did the isdefined but then it turned out the failure was something else, so I've now switched it back.

view this post on Zulip Mason Protter (Feb 27 2024 at 15:19):

By the way Timothy, since you're looking at it, do you have thoughts on the hint itself? I know you advocated in your manifesto-in-progress for using error codes so people can look up more elaborate descriptions of errors, do you think this is case that'd be better off with an error code or documentation link?

view this post on Zulip Timothy (Feb 27 2024 at 15:20):

I feel like much of the benefit with error codes is when they're a standard/ubiquitous system. I'm looking forward to that day, but until we get there I think your current approach is probably the best option. My 2c.

view this post on Zulip Timothy (Feb 27 2024 at 15:20):

As an aside, I love to see the effort you've gone to in creating a properly helpful error message there :heart:

view this post on Zulip Mason Protter (Feb 27 2024 at 15:34):

Well I did it because I was thinking of your document


Last updated: Nov 22 2024 at 04:41 UTC