prism.tsx 2.9 KB

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