Make output cells like Markdown

前端 未结 3 1878
故里飘歌
故里飘歌 2020-12-31 04:09

I like IPython\'s Markdown cells for incorporating HTML and other rich content inside notebooks. I would like to know if a command output can be formatted similarly, in outp

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 04:53

    Just adding some extra feature to your code example

    htmlContent = ''
    
    def header(text):
        raw_html = '

    ' + str(text) + '

    ' return raw_html def box(text): raw_html = '
    '+str(text)+'
    ' return raw_html def addContent(raw_html): global htmlContent htmlContent += raw_html # Example addContent( header("This is a header") ) addContent( box("This is some text in a box") ) from IPython.core.display import HTML HTML(htmlContent)

    gives you this:

    OUTPUT

提交回复
热议问题