google / swift-jupyter

Apache License 2.0
619 stars 90 forks source link

Allow displaying of messages with custom mimetype data #86

Closed vojtamolda closed 4 years ago

vojtamolda commented 4 years ago

Hello everyone,

I have a proposal that allows people to have a simpler way of displaying messages with other mimetype than PNG.

The change allows the following example to work. Otherwise, it would be necessary to duplicate the entire JupyterDisplay.MessageContent struct and change the copy to work with HTML data:

%install '.package(url: "https://github.com/IBM-Swift/BlueCryptor.git", from: "1.0.0")' Cryptor
%include "EnableJupyterDisplay.swift"
struct HTMLData: Encodable {
    let html: String
    let text = "<IPython.core.display.HTML object>"
    private enum CodingKeys: String, CodingKey {
        case html = "text/html"
        case text = "text/plain"
    }
}

func display(html: String) {
    let htmlData = HTMLData(html: html)
    let data = JupyterDisplay.MessageContent(data: htmlData).json
    JupyterDisplay.messages.append(JupyterDisplay.Message(content: data))
}

The following cells can then output rich HTML representations:

let greenBox = "<div style='height: 100px; width: 100px; background-color: green'></div>"
display(html: greenBox)

image

googlebot commented 4 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

vojtamolda commented 4 years ago

@googlebot Signed!

googlebot commented 4 years ago

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.