File size: 8,492 Bytes
d1ceb73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from pygments.style import Style
from pygments.token import (
Comment, Error, Generic, Keyword, Literal, Name, Number, Operator, Other,
Punctuation, String, Text, Whitespace)
class JupyterStyle(Style):
"""
A pygments style using JupyterLab CSS variables.
The goal is to mimick JupyterLab's codemirror theme.
Known impossibilities:
- With pygments, the dot in `foo.bar` is considered an Operator (class: 'o'),
while in codemirror, it is bare text.
- With pygments, in both `from foo import bar`, and `foo.bar`, "bar" is
considered a Name (class: 'n'), while in coremirror, the latter is a property.
Available CSS variables are
--jp-mirror-editor-keyword-color
--jp-mirror-editor-atom-color
--jp-mirror-editor-number-color
--jp-mirror-editor-def-color
--jp-mirror-editor-variable-color
--jp-mirror-editor-variable-2-color
--jp-mirror-editor-variable-3-color
--jp-mirror-editor-punctuation-color
--jp-mirror-editor-property-color
--jp-mirror-editor-operator-color
--jp-mirror-editor-comment-color
--jp-mirror-editor-string-color
--jp-mirror-editor-string-2-color
--jp-mirror-editor-meta-color
--jp-mirror-editor-qualifier-color
--jp-mirror-editor-builtin-color
--jp-mirror-editor-bracket-color
--jp-mirror-editor-tag-color
--jp-mirror-editor-attribute-color
--jp-mirror-editor-header-color
--jp-mirror-editor-quote-color
--jp-mirror-editor-link-color
--jp-mirror-editor-error-color
"""
default_style = ''
background_color = 'var(--jp-cell-editor-background)'
highlight_color = 'var(--jp-cell-editor-active-background)'
styles = {
Text: 'var(--jp-mirror-editor-variable-color)', # no class
Whitespace: '', # class: 'w'
Error: 'var(--jp-mirror-editor-error-color)', # class: 'err'
Other: '', # class: 'x'
Comment: 'italic var(--jp-mirror-editor-comment-color)', # class: 'c'
#Comment.Multiline: '', # class: 'cm'
#Comment.Preproc: '', # class: 'cp'
#Comment.Single: '', # class: 'c1'
#Comment.Special: '', # class: 'cs'
Keyword: 'bold var(--jp-mirror-editor-keyword-color)', # class: 'k'
#Keyword.Constant: '', # class: 'kc'
#Keyword.Declaration: '', # class: 'kd'
#Keyword.Namespace: '', # class: 'kn'
#Keyword.Pseudo: '', # class: 'kp'
#Keyword.Reserved: '', # class: 'kr'
#Keyword.Type: '', # class: 'kt'
Operator: 'bold var(--jp-mirror-editor-operator-color)', # class: 'o'
Operator.Word: '', # class: 'ow'
Literal: '', # class: 'l'
Literal.Date: '', # class: 'ld'
String: 'var(--jp-mirror-editor-string-color)',
#String.Backtick: '', # class: 'sb'
#String.Char: '', # class: 'sc'
#String.Doc: '', # class: 'sd'
#String.Double: '', # class: 's2'
#String.Escape: '', # class: 'se'
#String.Heredoc: '', # class: 'sh'
#String.Interpol: '', # class: 'si'
#String.Other: '', # class: 'sx'
#String.Regex: '', # class: 'sr'
#String.Single: '', # class: 's1'
#String.Symbol: '', # class: 'ss'
Number: 'var(--jp-mirror-editor-number-color)', # class: 'm'
#Number.Float: '', # class: 'mf'
#Number.Hex: '', # class: 'mh'
#Number.Integer: '', # class: 'mi'
#Number.Integer.Long: '', # class: 'il'
#Number.Oct: '', # class: 'mo'
Name: '', # class: 'n'
#Name.Attribute: '', # class: 'na'
#Name.Builtin: '', # class: 'nb'
#Name.Builtin.Pseudo: '', # class: 'bp'
#Name.Class: '', # class: 'nc'
#Name.Constant: '', # class: 'no'
#Name.Decorator: '', # class: 'nd'
#Name.Entity: '', # class: 'ni'
#Name.Exception: '', # class: 'ne'
#Name.Function: '', # class: 'nf'
#Name.Property: '', # class 'py'
#Name.Label: '', # class: 'nl'
#Name.Namespace: '', # class: 'nn'
#Name.Other: '', # class: 'nx'
#Name.Tag: '', # class: 'nt'
#Name.Variable: '', # class: 'nv'
#Name.Variable.Class: '', # class: 'vc'
#Name.Variable.Global: '', # class: 'vg'
#Name.Variable.Instance: '', # class: 'vi'
Generic: '', # class: 'g'
#Generic.Deleted: '', # class: 'gd',
#Generic.Emph: 'italic', # class: 'ge'
#Generic.Error: '', # class: 'gr'
#Generic.Heading: '', # class: 'gh'
#Generic.Inserted: '', # class: 'gi'
#Generic.Output: '', # class: 'go'
#Generic.Prompt: '', # class: 'gp'
#Generic.Strong: '', # class: 'gs'
#Generic.Subheading: '', # class: 'gu'
#Generic.Traceback: '', # class: 'gt'
Punctuation: 'var(--jp-mirror-editor-punctuation-color)' # class: 'p'
}
|