ipython jupyter_如何更改IPython(Jupyter)中代码的高亮颜色样式?

本文介绍了如何更改Pygments代码高亮库中特定区域的高亮颜色。作者通过提供一个自定义的EmacsStyle样式类展示了如何定义不同类型的代码标记颜色,并分享了在Mac和Linux上改变IPython颜色方案的临时解决方案:%colors NoColor或%colors Linux。此方法适用于希望个性化代码显示风格的开发者。
摘要由CSDN通过智能技术生成

1586010002-jmsa.png

My question is showed in the following picutre. I want to change the highlight color style of the code region that is specified by the red rectangle in the picutre below. But I dont' know which token I should change style of.

6FaPB.png

My pygment style setting code is below

from pygments.style import Style

from pygments.token import Keyword, Name, Comment, String, Error, \

Number, Operator, Generic, Whitespace, Token

class EmacsStyle(Style):

"""

The default style (inspired by Emacs 22).

"""

background_color = "#333333"

highlight_color = "#a7a695"

default_style = ""

styles = {

Token: "#ffffff",

Whitespace: "#bbbbbb",

Comment: "italic #008800",

Comment.Preproc: "noitalic",

Comment.Special: "noitalic bold",

Keyword: "bold #B541FF",

Keyword.Pseudo: "nobold",

Keyword.Type: "bold #00BB00",

Operator: "#666666",

Operator.Word: "bold #AA22FF",

Name.Builtin: "#B541FF",

Name.Function: "#00A000",

Name.Class: "#4242FF",

Name.Namespace: "bold #4242FF",

Name.Exception: "bold #D2413A",

Name.Variable: "#B8860B",

Name.Constant: "#880000",

Name.Label: "#A0A000",

Name.Entity: "bold #999999",

Name.Attribute: "#BB4444",

Name.Tag: "bold #008000",

Name.Decorator: "#AA22FF",

String: "#BB4444",

String.Doc: "italic",

String.Interpol: "bold #BB6688",

String.Escape: "bold #BB6622",

String.Regex: "#BB6688",

String.Symbol: "#B8860B",

String.Other: "#008000",

Number: "#666666",

Generic.Heading: "bold #4242FF",

Generic.Subheading: "bold #B541FF",

Generic.Deleted: "#D2413A",

Generic.Inserted: "#00A000",

Generic.Error: "#FF0000",

Generic.Emph: "italic",

Generic.Strong: "bold",

Generic.Prompt: "bold #4242FF",

Generic.Output: "#888",

Generic.Traceback: "#04D",

Error: "border:#FF0000"

}

解决方案

I've found a IPython magic command to change the color (on Mac):

%colors NoColor

or (on Linux)

%colors Linux

This is not a perfect resolution but works.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值