IPython change input cell syntax highlighting logic for entire session

后端 未结 2 1466
無奈伤痛
無奈伤痛 2021-01-22 20:08

You can use extensions or display helpers in IPython to make whatever syntax highlighting you\'d like on output cells.

For some special cell magics, like

相关标签:
2条回答
  • 2021-01-22 20:51

    For recent IPython version, the selected answer no longer works. The 'config_default' property was renamed options_default (Ipython 6.0.0). The following works:

    import IPython
    js = "IPython.CodeCell.options_default.highlight_modes['magic_fortran'] = {'reg':[/^%%fortran/]};"
    IPython.core.display.display_javascript(js, raw=True)
    
    0 讨论(0)
  • 2021-01-22 21:08

    To replace IPython.config.cell_magic_highlight, you can use something like

    import IPython
    js = "IPython.CodeCell.config_defaults.highlight_modes['magic_fortran'] = {'reg':[/^%%fortran/]};"
    IPython.core.display.display_javascript(js, raw=True)
    

    so cells which begin with %%fortran will be syntax-highlighted like FORTRAN. (However, they will still be evaluated as python if you do only this.)

    0 讨论(0)
提交回复
热议问题