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

MIME rendering #110

Closed
wants to merge 8 commits into from
Closed

Conversation

SpencerPark
Copy link
Member

@SpencerPark SpencerPark commented May 28, 2018

Initial support for rendering richer displays of data in the notebook. The approach was designed to follow IPython's API as far as it applies in Go. Any code that needs access to the kernel should be injected right before evaluation but generic user space stuff should go in the runtime package.

An example I've been playing around with is below. There is still a bug I can't quite track down yet with the zmq message being somehow corrupted during Publish and so in random cases the results may or may not show up due to the message being rejected (which means if it doesn't work try it a second time until this is fixed). (Fixed in 710233f)

import "fmt"
import r "github.com/gopherdata/gophernotes/runtime"

type Test struct {
    Color string
}

func (t Test) RenderAsSVG() string {
    return "<svg><rect x=\"0\" y=\"0\" width=\"100\" height=\"100\" fill=\"" + t.Color + "\"/></svg>"
}

func (t Test) RenderAsMarkdown() string {
    return "**Color:** " + t.Color
}

t := Test{"blue"}

fmt.Println(t)
Display(r.SVG(t))
Display(r.Markdown(t))

Still TODO:

  • Add some unit tests
  • Add example notebooks
  • Implement some renderers for standard library interfaces

@SpencerPark
Copy link
Member Author

Ran into trouble with cosmos72/gomacro#16. A lot of the rendering logic requires type assertions and unfortunately many of those are interfaces.

@cosmos72
Copy link
Member

cosmos72 commented Jun 2, 2018

If you don't mind, I tried to simplify your code, see issue #17 and pull request #105

@SpencerPark
Copy link
Member Author

If you don't mind, I tried to simplify your code

Not at all! You know gomacro's capabilities much better than I do :) I'll move the discussion over there.

@cosmos72
Copy link
Member

as per discussion in #105, I merged that pull request

@cosmos72 cosmos72 closed this Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants