prism.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {css, Theme} from '@emotion/react';
  2. import {space} from 'sentry/styles/space';
  3. /**
  4. * Prism (code highlighting) styles. Added to <GlobalStyles />, so no need to import
  5. * this into any component.
  6. */
  7. export const prismStyles = (theme: Theme) => css`
  8. :root {
  9. ${theme.prismVariables};
  10. }
  11. /* Use dark Prism theme for code snippets imported from Sentry Docs */
  12. .gatsby-highlight,
  13. .prism-dark {
  14. ${theme.prismDarkVariables};
  15. }
  16. pre[class*='language-'] {
  17. overflow-x: auto;
  18. padding: ${space(1)} ${space(2)};
  19. border-radius: ${theme.borderRadius};
  20. box-shadow: none;
  21. code {
  22. background: unset;
  23. vertical-align: middle;
  24. }
  25. }
  26. pre[class*='language-'],
  27. code[class*='language-'] {
  28. color: var(--prism-base);
  29. background: var(--prism-block-background);
  30. font-size: ${theme.codeFontSize};
  31. text-shadow: none;
  32. font-family: ${theme.text.familyMono};
  33. direction: ltr;
  34. text-align: left;
  35. white-space: pre;
  36. word-spacing: normal;
  37. word-break: normal;
  38. -moz-tab-size: 4;
  39. -o-tab-size: 4;
  40. tab-size: 4;
  41. -webkit-hyphens: none;
  42. -moz-hyphens: none;
  43. -ms-hyphens: none;
  44. hyphens: none;
  45. .namespace {
  46. opacity: 0.7;
  47. }
  48. .token.comment,
  49. .token.prolog,
  50. .token.doctype,
  51. .token.cdata {
  52. color: var(--prism-comment);
  53. }
  54. .token.punctuation {
  55. color: var(--prism-punctuation);
  56. }
  57. .token.property,
  58. .token.tag,
  59. .token.boolean,
  60. .token.number,
  61. .token.constant,
  62. .token.symbol,
  63. .token.deleted {
  64. color: var(--prism-property);
  65. }
  66. .token.selector,
  67. .token.attr-name,
  68. .token.string,
  69. .token.char,
  70. .token.builtin,
  71. .token.inserted {
  72. color: var(--prism-selector);
  73. }
  74. .token.operator,
  75. .token.entity,
  76. .token.url,
  77. .language-css .token.string,
  78. .style .token.string {
  79. color: var(--prism-operator);
  80. background: none;
  81. }
  82. .token.atrule,
  83. .token.attr-value,
  84. .token.keyword {
  85. color: var(--prism-keyword);
  86. }
  87. .token.function {
  88. color: var(--prism-function);
  89. }
  90. .token.regex,
  91. .token.important,
  92. .token.variable {
  93. color: var(--prism-variable);
  94. }
  95. .token.important,
  96. .token.bold {
  97. font-weight: bold;
  98. }
  99. .token.italic {
  100. font-style: italic;
  101. }
  102. .token.entity {
  103. cursor: help;
  104. }
  105. .line-highlight {
  106. position: absolute;
  107. left: -${space(2)};
  108. right: 0;
  109. background: var(--prism-highlight-background);
  110. box-shadow: inset 5px 0 0 var(--prism-highlight-accent);
  111. z-index: 0;
  112. pointer-events: none;
  113. line-height: inherit;
  114. white-space: pre;
  115. }
  116. }
  117. pre[class*='language-']::selection,
  118. code[class*='language-']::selection {
  119. text-shadow: none;
  120. background: var(--prism-selected);
  121. }
  122. pre[data-line] {
  123. position: relative;
  124. }
  125. pre[class*='language-'] > code[class*='language-'] {
  126. position: relative;
  127. z-index: 1;
  128. }
  129. `;