Skip to content

Instantly share code, notes, and snippets.

@data-enhanced
Created April 27, 2022 20:50
Show Gist options
  • Save data-enhanced/d65bc3eab1d08cb70fefd2860d147b25 to your computer and use it in GitHub Desktop.
Save data-enhanced/d65bc3eab1d08cb70fefd2860d147b25 to your computer and use it in GitHub Desktop.

Revisions

  1. data-enhanced created this gist Apr 27, 2022.
    20 changes: 20 additions & 0 deletions format_jupyter_output.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # Format using Markdown ================================================

    # Format Jupyter Code Output using Markdown
    # https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html?highlight=display_markdown#IPython.display.display_markdown
    from IPython.display import display_markdown

    markdowntext = 'Markdown Heading Level 3'
    display_markdown(f'### Code Output Formatted as {markdowntext}', raw=True)
    display_markdown(f'_Code output italicized using_ `display_markdown`', raw=True)


    # Format using HTML ================================================

    # Format Jupyter Code Output using HTML
    # https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html?highlight=display_#IPython.display.display_html

    from IPython.display import display_html

    htmltext = 'HTML h3'
    display_html(f'<h3>{htmltext} Heading + <em>Emphasized</em></h3>', raw=True)