Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload print for Markdown Strings #10009

Open
cortner opened this issue Feb 1, 2015 · 10 comments
Open

Overload print for Markdown Strings #10009

cortner opened this issue Feb 1, 2015 · 10 comments
Assignees
Labels
display and printing Aesthetics and correctness of printed representations of objects. markdown strings "Strings!"

Comments

@cortner
Copy link

cortner commented Feb 1, 2015

@one-more-minute

It would be nice to create Base.Markdown.MD objects and then output them using print or println. They could then be used as messages, or even error messages.

See also discussion on julia-users.

@MikeInnes MikeInnes self-assigned this Feb 1, 2015
@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

Why not just use display(x) on x::MD? Assuming there is a display backend that knows how to use writemime(io, "text/markdown", x) output (or MD defines a text/html output), then it will display correctly ... rich output is the whole point of the display stuff.

print(io, x) is essentially a synonym for writemime(io, "text/plain", x) so it doesn't seem appropriate here.

@stevengj stevengj added the io Involving the I/O subsystem: libuv, read, write, etc. label Feb 2, 2015
@MikeInnes
Copy link
Member

When Markdown is displayed in a terminal (via display) it handles other bits of formatting like margins and trailing newlines. The idea would be for print(::MD) to have slightly different semantics to that so that you can intersperse printing plain and formatted text to the terminal.

@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

What would be the semantics of print(::MD)?

@cortner
Copy link
Author

cortner commented Feb 2, 2015

For most of my own uses, display would actually work ok - to be honest I just wasn't aware of it when I opened this issue. What about error messages though? I thought it would also be able to write

    error(md"Error with `code` or *other formatting*?")

but at the moment the output will be a discription of the MD object. Which command is used here?

@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

error throws an ErrorException, which is currently parameterized by a string. It doesn't actually display anything. To allow markdown in error messages, you would need:

  • Modify the ErrorException type (and similar exceptions) to accept an arbitrary object (or some set of types) as an exception message.
  • Modify the showerror (IIRC) function in the REPL to do richly formatted backtrace messages.
  • IPython uses a special pyerr/error message type to display backtraces, and in IPython 3 I think this will accept richly formatted tracebacks; we just have to use it.

@cortner
Copy link
Author

cortner commented Feb 2, 2015

I can play around with this and report back, but is there any point in pursuing this, or would I be the only one interested in features like this?

@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

I suspect that it is probably premature to add markdown messages to exceptions; that would be a fairly intrusive change since exceptions are used everywhere.

@MikeInnes
Copy link
Member

You don't have to change the ErrorException type – you could just overload error to respond to MD types by creating a different RichException or similar type. It would be a completely non-intrusive change.

@stevengj
Copy link
Member

stevengj commented Feb 2, 2015

@one-more-minute, that's true; a much cleaner solution.

@JeffBezanson JeffBezanson removed the io Involving the I/O subsystem: libuv, read, write, etc. label Jul 10, 2015
@kshyatt kshyatt added the strings "Strings!" label Sep 15, 2016
@JeffBezanson JeffBezanson added the display and printing Aesthetics and correctness of printed representations of objects. label Jan 3, 2017
@stevengj
Copy link
Member

Looks like the Markdown display should be updated. Currently, it overloads Base.display(d::Base.REPL.REPLDisplay, md::MD) to decide whether to print ANSI terminal color codes etcetera, when nowadays it should use IOContext for this in show.

Then you will be able to just call show with an appropriate IOContext if you want to print the same thing to any stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. markdown strings "Strings!"
Projects
None yet
Development

No branches or pull requests

6 participants