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

Display html, using %html magic (or some other way) #21

Closed
haakenlid opened this issue Mar 22, 2016 · 4 comments
Closed

Display html, using %html magic (or some other way) #21

haakenlid opened this issue Mar 22, 2016 · 4 comments

Comments

@haakenlid
Copy link

I want to use the %html magic from ipython, but it seems to not exist in this kernel. And there's not list magics either (see #8). I want to use a node script that generates html, and then display it in the output cell. Is there any other way to achieve this, except magice.

@haakenlid haakenlid changed the title Which magics are implemented? Display html, using %html magic (or some other way) Mar 22, 2016
@jasonphillips
Copy link

I found a relatively simple way to implement HTML output, see my gist here:

https://gist.github.com/jasonphillips/3ecfc221f8f931027c82511870727e34

It's not secure (no checking for dangerous content in the HTML, etc) but that isn't necessary for my local development purposes.

@haakenlid
Copy link
Author

haakenlid commented Jul 12, 2016

There's another way to display html as well. The function display() which isn't documented in the readme, but is mentioned in issue #4 takes an optional mimetype argument. So displaying html is actually built in already.

display("<h1>Hello World</h1>", "text/html") 

Combined with react-dom-render you can display jsx like this:

%%babel
const React = require('react')
const ReactDOM = require('react-dom/server')
const renderJsx = jsx => display(ReactDOM.renderToStaticMarkup(jsx), 'text/html')
renderJsx(<h1>Hello World!</h1>)

image

@haakenlid
Copy link
Author

My problem is solved. But I think it would be nice to mention the display() function in the main readme.

@liuderchi
Copy link

Big thanks for your tips @haakenlid @jasonphillips 💯

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

No branches or pull requests

3 participants