Printing HTML within IPython Notebook / IPython-specific prettyprint?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Printing HTML within IPython Notebook / IPython-specific prettyprint?

Jeffrey Tratner
Hi all,

I know that I can use IPython.core.display.HTML to format something such that it outputs as HTML into the notebook. However, it appears to only work if it's the output of a cell, e.g.

```
from IPython.core.display import HTML
html_text = HTML("<p style='font-weight: bold;'> Some text! </p>")
html_text
```

But I'd like to be able to output pretty printed HTML in the midst of a function. Is it possible to get IPython to consider something as HTML (instead of as plain text)?  I tried using `lib.pretty`, but that didn't hook into it, and a plain print statemtn didn't work either.).

It would be great to be able to do something like

```
from __future__ import print_function
try:
    from IPython.somemodule import print_func
except ImportError:
    print_func = print
```

Does this exist now and/or is it planned for the future? If not, any suggestions on how I might go about making this work?

Thanks,

Jeff


_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Printing HTML within IPython Notebook / IPython-specific prettyprint?

Paul Ivanov-2
Hi Jeff,

I think display is what you want to use for now:


from IPython.display import display, HTML
for x in range(10):
    display(HTML("<b>" + str(x) + "</b>"))
   
Jeffrey Tratner, on 2013-05-10 14:01,  wrote:
> Does this exist now and/or is it planned for the future? If not, any
> suggestions on how I might go about making this work?

monkey patching print is an interesting idea.


--
                   _
                  / \
                A*   \^   -
             ,./   _.`\\ / \
            / ,--.S    \/   \
           /  `"~,_     \    \
     __o           ?
   _ \<,_         /:\
--(_)/-(_)----.../ | \
--------------.......J
Paul Ivanov
http://pirsquared.org
_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|

Re: Printing HTML within IPython Notebook / IPython-specific prettyprint?

Jeffrey Tratner
That was just what I was looking for -- thanks!


On Fri, May 10, 2013 at 2:24 PM, Paul Ivanov <[hidden email]> wrote:
Hi Jeff,

I think display is what you want to use for now:


from IPython.display import display, HTML
for x in range(10):
    display(HTML("<b>" + str(x) + "</b>"))

Jeffrey Tratner, on 2013-05-10 14:01,  wrote:
> Does this exist now and/or is it planned for the future? If not, any
> suggestions on how I might go about making this work?

monkey patching print is an interesting idea.


--
                   _
                  / \
                A*   \^   -
             ,./   _.`\\ / \
            / ,--.S    \/   \
           /  `"~,_     \    \
     __o           ?
   _ \<,_         /:\
--(_)/-(_)----.../ | \
--------------.......J
Paul Ivanov
http://pirsquared.org
_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev


_______________________________________________
IPython-dev mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-dev