Syntax Highlighting in iPython Notebook Markdown Cell

邮差的信 提交于 2019-12-03 10:39:28

The GitHub Flavored Markdown-style of denoting code using the triple-backtick is now supported in IPython master branch on GitHub, and so will be included in the 1.0 release.

As Jakob noted, even prior to this, you could use regular markdown for code, in which you just need to indent your code by four spaces, and this continues to be a valid way of displaying code in your IPython notebook.

Jakob

using IPython 0.13.1 syntax highlighting is as easy as (in a markdown cell):

some text

    def foo():
        print 'bar'
        return 0

some text

Just, use a blank line before and indent the code (see example notebooks shipped with Ipython). This works for Python and some other languages.

In IPython 7.2.0 notebooks you can use:

Text `code` text

in a markdown cell to print highlighted code inline.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!