prism.tsx 2.8 KB

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