prism.tsx 2.9 KB

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