style.py 8.3 KB

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