[IPython-User] html/rst rendering in Ipython notebook as return from a python function

Brian Granger ellisonbg@gmail....
Mon Apr 2 18:15:34 CDT 2012


Have the function return the raw HTML wrapped in an HTML object:

from IPython.core.display import HTML

def foo():
  raw_html = "<h1>Yah, rendered HTML</h1>"
  return HTML(raw_html)

Calling foo() and not assigning to a variable will give you what you want:

In [1]: foo()
Yah, rendered HTML  (will be rendered as an h1).

Cheers,

Brian



On Mon, Apr 2, 2012 at 3:54 PM, Massimo Di Stefano
<massimodisasha@gmail.com> wrote:
> Hi All,
>
> i was tring to learn how to use the notebook to render the output of a function as rst or html and display it in the notebook.
> i see the recent version of pandas as this feature enabled to print out in the notebook a data frame and render it as an html table.
>
> do you know how can i do the same with  a custom function ?
>
> what i means is something like :
>
> def myfunction():
>    """  *this is italic test*
>          ** this is bold **  """
>
> and print it out as :
>
> myfunc.__doc__
>
> but seems it is not yet possible, as i can see from this thread :
>
> http://python.6.n6.nabble.com/notebook-idea-reST-rendering-of-docstrings-td4342595.html
>
> so, if i do something like :
>
>
> class my class():
>    def method1():
>        some code
>
>
>    def method2():
>        some code
>
>    def helpmethod1():
>        help = """ some html code """
>        return help
>
>    def helpmethod2():
>        help = """ some html code """
>        return help
>
>
> id like to render it in the notebook as html when i type instruction like :
>
> In [1]: myclass(). helpmethod1
>
>
>
> Is this possible ?
>
>
> Thanks!
>
> --Massimo.
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user



-- 
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com


More information about the IPython-User mailing list