Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(docs): change code block theme (#34940)

Charis84914090f9c0
diff --git a/apps/docs/features/ui/CodeBlock/CodeBlock.tsx b/apps/docs/features/ui/CodeBlock/CodeBlock.tsx
index cbbf7d4b272..57c33dc0c53 100644
--- a/apps/docs/features/ui/CodeBlock/CodeBlock.tsx
+++ b/apps/docs/features/ui/CodeBlock/CodeBlock.tsx
@@ -1,9 +1,11 @@
import { type PropsWithChildren } from 'react'
-import { type BundledLanguage, codeToTokens, type ThemedToken } from 'shiki'
+import { bundledLanguages, createHighlighter, type BundledLanguage, type ThemedToken } from 'shiki'
import { createTwoslasher, type ExtraFiles, type NodeHover } from 'twoslash'
import { cn } from 'ui'
import { AnnotatedSpan, CodeCopyButton } from './CodeBlock.client'
+import { getFontStyle } from './CodeBlock.utils'
+import theme from './supabase-2.json' with { type: 'json' }
import denoTypes from './types/lib.deno.d.ts.include'
const extraFiles: ExtraFiles = { 'deno.d.ts': denoTypes }
@@ -11,6 +13,12 @@ const extraFiles: ExtraFiles = { 'deno.d.ts': denoTypes }
const twoslasher = createTwoslasher({ extraFiles })
const TWOSLASHABLE_LANGS: ReadonlyArray<string> = ['js', 'ts', 'javascript', 'typescript']
+const BUNDLED_LANGUAGES = Object.keys(bundledLanguages)
+const highlighter = await createHighlighter({
+ themes: [theme],
+ langs: BUNDLED_LANGUAGES,
+})
+
export async function CodeBlock({
className,
lang: langSetting,
@@ -42,12 +50,9 @@ export async function CodeBlock({
}
}
- const { tokens } = await codeToTokens(code, {
+ const { tokens } = highlighter.codeToTokens(code, {
lang,
- themes: {
- light: 'vitesse-light',
- dark: 'vitesse-dark',
- },
+ theme: 'Supabase Theme',
})
return (
@@ -114,7 +119,7 @@ function CodeLine({
annotations={twoslash.get(token.offset)!}
/>
) : (
- <span key={token.offset} style={token.htmlStyle}>
+ <span key={token.offset} style={{ color: token.color, ...getFontStyle(token.fontStyle) }}>
{token.content}
</span>
)
@@ -174,288 +179,3 @@ function tryToBundledLanguage(lang: string): BundledLanguage | null {
}
return null
}
-
-const BUNDLED_LANGUAGES = [
- 'abap',
- 'actionscript-3',
- 'ada',
- 'adoc',
- 'angular-html',
- 'angular-ts',
- 'apache',
- 'apex',
- 'apl',
- 'applescript',
- 'ara',
- 'asciidoc',
- 'asm',
- 'astro',
- 'awk',
- 'ballerina',
- 'bash',
- 'bat',
- 'batch',
- 'be',
- 'beancount',
- 'berry',
- 'bibtex',
- 'bicep',
- 'blade',
- 'c',
- 'c#',
- 'c++',
- 'cadence',
- 'cdc',
- 'clarity',
- 'clj',
- 'clojure',
- 'closure-templates',
- 'cmake',
- 'cmd',
- 'cobol',
- 'codeowners',
- 'codeql',
- 'coffee',
- 'coffeescript',
- 'common-lisp',
- 'console',
- 'cpp',
- 'cql',
- 'crystal',
- 'cs',
- 'csharp',
- 'css',
- 'csv',
- 'cue',
- 'cypher',
- 'd',
- 'dart',
- 'dax',
- 'desktop',
- 'diff',
- 'docker',
- 'dockerfile',
- 'dream-maker',
- 'elisp',
- 'elixir',
- 'elm',
- 'emacs-lisp',
- 'erb',
- 'erl',
- 'erlang',
- 'f',
- 'f#',
- 'f03',
- 'f08',
- 'f18',
- 'f77',
- 'f90',
- 'f95',
- 'fennel',
- 'fish',
- 'fluent',
- 'for',
- 'fortran-fixed-form',
- 'fortran-free-form',
- 'fs',
- 'fsharp',
- 'fsl',
- 'ftl',
- 'gdresource',
- 'gdscript',
- 'gdshader',
- 'genie',
- 'gherkin',
- 'git-commit',
- 'git-rebase',
- 'gjs',
- 'gleam',
- 'glimmer-js',
- 'glimmer-ts',
- 'glsl',
- 'gnuplot',
- 'go',
- 'gql',
- 'graphql',
- 'groovy',
- 'gts',
- 'hack',
- 'haml',
- 'handlebars',
- 'haskell',
- 'haxe',
- 'hbs',
- 'hcl',
- 'hjson',
- 'hlsl',
- 'hs',
- 'html',
- 'html-derivative',
- 'http',
- 'hxml',
- 'hy',
- 'imba',
- 'ini',
- 'jade',
- 'java',
- 'javascript',
- 'jinja',
- 'jison',
- 'jl',
- 'js',
- 'json',
- 'json5',
- 'jsonc',
- 'jsonl',
- 'jsonnet',
- 'jssm',
- 'jsx',
- 'julia',
- 'kotlin',
- 'kql',
- 'kt',
- 'kts',
- 'kusto',
- 'latex',
- 'less',
- 'liquid',
- 'lisp',
- 'log',
- 'logo',
- 'lua',
- 'make',
- 'makefile',
- 'markdown',
- 'marko',
- 'matlab',
- 'md',
- 'mdc',
- 'mdx',
- 'mediawiki',
- 'mermaid',
- 'mojo',
- 'move',
- 'nar',
- 'narrat',
- 'nextflow',
- 'nf',
- 'nginx',
- 'nim',
- 'nix',
- 'nu',
- 'nushell',
- 'objc',
- 'objective-c',
- 'objective-cpp',
- 'ocaml',
- 'pascal',
- 'perl',
- 'perl6',
- 'php',
- 'plsql',
- 'po',
- 'postcss',
- 'pot',
- 'potx',
- 'powerquery',
- 'powershell',
- 'prisma',
- 'prolog',
- 'properties',
- 'proto',
- 'ps',
- 'ps1',
- 'pug',
- 'puppet',
- 'purescript',
- 'py',
- 'python',
- 'ql',
- 'qml',
- 'qmldir',
- 'qss',
- 'r',
- 'racket',
- 'raku',
- 'razor',
- 'rb',
- 'reg',
- 'regex',
- 'regexp',
- 'rel',
- 'riscv',
- 'rs',
- 'rst',
- 'ruby',
- 'rust',
- 'sas',
- 'sass',
- 'scala',
- 'scheme',
- 'scss',
- 'sh',
- 'shader',
- 'shaderlab',
- 'shell',
- 'shellscript',
- 'shellsession',
- 'smalltalk',
- 'solidity',
- 'soy',
- 'sparql',
- 'spl',
- 'splunk',
- 'sql',
- 'ssh-config',
- 'stata',
- 'styl',
- 'stylus',
- 'svelte',
- 'swift',
- 'system-verilog',
- 'systemd',
- 'tasl',
- 'tcl',
- 'terraform',
- 'tex',
- 'tf',
- 'tfvars',
- 'toml',
- 'ts',
- 'tsp',
- 'tsv',
- 'tsx',
- 'turtle',
- 'twig',
- 'typ',
- 'typescript',
- 'typespec',
- 'typst',
- 'v',
- 'vala',
- 'vb',
- 'verilog',
- 'vhdl',
- 'vim',
- 'viml',
- 'vimscript',
- 'vue',
- 'vue-html',
- 'vy',
- 'vyper',
- 'wasm',
- 'wenyan',
- 'wgsl',
- 'wiki',
- 'wikitext',
- 'wl',
- 'wolfram',
- 'xml',
- 'xsl',
- 'yaml',
- 'yml',
- 'zenscript',
- 'zig',
- 'zsh',
- '文言',
-]
diff --git a/apps/docs/features/ui/CodeBlock/CodeBlock.utils.ts b/apps/docs/features/ui/CodeBlock/CodeBlock.utils.ts
new file mode 100644
index 00000000000..e28e07f6cbb
--- /dev/null
+++ b/apps/docs/features/ui/CodeBlock/CodeBlock.utils.ts
@@ -0,0 +1,30 @@
+import { type CSSProperties } from 'react'
+
+/*
+ * As defined in @shikijs/core/dist/chunk-tokens.d.mts
+ */
+enum FontStyle {
+ NotSet = -1,
+ None = 0,
+ Italic = 1,
+ Bold = 2,
+ Underline = 4,
+}
+
+export function getFontStyle(styleFlags: number): CSSProperties {
+ let style: CSSProperties = null
+
+ if (styleFlags & FontStyle.Italic) {
+ ;(style ??= {}).fontStyle = 'italic'
+ }
+
+ if (styleFlags & FontStyle.Bold) {
+ ;(style ??= {}).fontWeight = 'bold'
+ }
+
+ if (styleFlags & FontStyle.Underline) {
+ ;(style ??= {}).textDecoration = 'underline'
+ }
+
+ return style
+}
diff --git a/apps/docs/features/ui/CodeBlock/supabase-2.json b/apps/docs/features/ui/CodeBlock/supabase-2.json
new file mode 100644
index 00000000000..d4120e118a2
--- /dev/null
+++ b/apps/docs/features/ui/CodeBlock/supabase-2.json
@@ -0,0 +1,207 @@
+{
+ "name": "Supabase Theme",
+ "displayName": "Supabase Theme",
+ "semanticHighlighting": true,
+ "colors": {
+ "editor.background": "var(--background-surface-75) / 0.75",
+ "editor.foreground": "var(--code-foreground)",
+ "editor.lineHighlightBackground": "var(--code-highlight-color)",
+ "editorCursor.foreground": "var(--code-foreground)",
+ "editorWhitespace.foreground": "var(--code-foreground)",
+ "editorIndentGuide.background": "var(--code-foreground)",
+ "editor.selectionBackground": "var(--code-highlight-color)",
+ "editor.selectionHighlightBackground": "var(--code-highlight-color)"
+ },
+ "tokenColors": [
+ {
+ "scope": ["comment", "punctuation.definition.comment", "string.comment"],
+ "settings": {
+ "foreground": "var(--code-token-comment)",
+ "fontStyle": "italic"
+ }
+ },
+ {
+ "scope": ["constant", "entity.name.constant", "variable.other.constant"],
+ "settings": {
+ "foreground": "var(--code-token-constant)"
+ }
+ },
+ {
+ "scope": ["entity", "entity.name", "entity.name.type", "support.type"],
+ "settings": {
+ "foreground": "var(--code-token-function)"
+ }
+ },
+ {
+ "scope": ["variable", "support.variable", "variable.parameter"],
+ "settings": {
+ "foreground": "var(--code-token-parameter)"
+ }
+ },
+ {
+ "scope": ["keyword", "storage.type", "storage.modifier", "keyword.control"],
+ "settings": {
+ "foreground": "var(--code-token-keyword)"
+ }
+ },
+ {
+ "scope": ["string", "constant.other.symbol", "constant.other.key", "string.quoted"],
+ "settings": {
+ "foreground": "var(--code-token-string)"
+ }
+ },
+ {
+ "scope": ["support.function", "entity.name.function"],
+ "settings": {
+ "foreground": "var(--code-token-function)"
+ }
+ },
+ {
+ "scope": ["punctuation", "punctuation.separator", "meta.brace", "punctuation.definition"],
+ "settings": {
+ "foreground": "var(--code-token-punctuation)"
+ }
+ },
+ {
+ "scope": ["meta.tag", "declaration.tag", "markup.deleted"],
+ "settings": {
+ "foreground": "var(--code-token-function)"
+ }
+ },
+ {
+ "scope": ["markup.inserted"],
+ "settings": {
+ "foreground": "var(--code-token-string)"
+ }
+ },
+ {
+ "scope": ["markup.changed"],
+ "settings": {
+ "foreground": "var(--code-token-string-expression)"
+ }
+ },
+ {
+ "scope": ["invalid", "invalid.deprecated"],
+ "settings": {
+ "foreground": "var(--code-foreground)",
+ "background": "var(--code-token-comment)"
+ }
+ },
+ {
+ "scope": ["support.type.property-name"],
+ "settings": {
+ "foreground": "var(--code-token-property)"
+ }
+ },
+ {
+ "scope": ["entity.other.attribute-name"],
+ "settings": {
+ "foreground": "var(--code-token-property)"
+ }
+ },
+ {
+ "scope": ["meta.object-literal.key"],
+ "settings": {
+ "foreground": "var(--code-token-property)"
+ }
+ },
+ {
+ "scope": ["entity.other.attribute-name", "entity.other.inherited-class"],
+ "settings": {
+ "foreground": "var(--code-token-property)"
+ }
+ },
+ {
+ "scope": ["storage", "storage.type", "storage.modifier"],
+ "settings": {
+ "foreground": "var(--code-token-keyword)"
+ }
+ },
+ {
+ "scope": ["support.class"],
+ "settings": {
+ "foreground": "var(--code-token-function)"
+ }
+ },
+ {
+ "scope": ["constant.language"],
+ "settings": {
+ "foreground": "var(--code-token-constant)"
+ }
+ },
+ {
+ "scope": ["meta.embedded"],
+ "settings": {
+ "foreground": "var(--code-token-string-expression)"
+ }
+ },
+ {
+ "scope": ["meta.function-call"],
+ "settings": {
+ "foreground": "var(--code-token-function)"
+ }
+ },
+ {
+ "scope": ["meta.method-call"],
+ "settings": {
+ "foreground": "var(--code-token-function)"
+ }
+ },
+ {
+ "scope": ["meta.return-type"],
+ "settings": {
+ "foreground": "var(--code-token-keyword)"
+ }
+ },
+ {
+ "scope": [
+ "meta.import",
+ "meta.import.js",
+ "meta.import.ts",
+ "meta.import.tsx",
+ "meta.import.jsx",
+ "string.quoted.single.js",
+ "string.quoted.double.js",
+ "string.quoted.single.ts",
+ "string.quoted.double.ts",
+ "string.quoted.single.tsx",
+ "string.quoted.double.tsx",
+ "string.quoted.single.jsx",
+ "string.quoted.double.jsx"
+ ],
+ "settings": {
+ "foreground": "var(--code-token-string-expression)"
+ }
+ },
+ {
+ "scope": ["meta.var.expr"],
+ "settings": {
+ "foreground": "var(--code-token-variable)"
+ }
+ },
+ {
+ "scope": ["meta.block"],
+ "settings": {
+ "foreground": "var(--code-foreground)"
+ }
+ },
+ {
+ "scope": ["meta.delimiter.period"],
+ "settings": {
+ "foreground": "var(--code-foreground)"
+ }
+ },
+ {
+ "scope": ["meta.brace.round"],
+ "settings": {
+ "foreground": "var(--code-foreground)"
+ }
+ },
+ {
+ "scope": ["meta.paren.expr"],
+ "settings": {
+ "foreground": "var(--code-foreground)"
+ }
+ }
+ ]
+}
diff --git a/apps/docs/styles/main.scss b/apps/docs/styles/main.scss
index 1d599b80ffc..95e74ae32ff 100644
--- a/apps/docs/styles/main.scss
+++ b/apps/docs/styles/main.scss
@@ -350,20 +350,43 @@ th code {
@apply not-sr-only;
}
-// Shiki dark mode styling
-
-[data-theme="dark"] :is(.shiki,
-.shiki span) {
- color: var(--shiki-dark) !important;
- background-color: var(--shiki-dark-bg) !important;
- /* Optional, if you also want font styles */
- font-style: var(--shiki-dark-font-style) !important;
- font-weight: var(--shiki-dark-font-weight) !important;
- text-decoration: var(--shiki-dark-text-decoration) !important;
-}
-
// Code blocks need margin applied when in content container
-
.prose :where(.shiki:not(.shiki-wrapper *), .shiki-wrapper) {
margin-block: 2rem;
}
+
+// Code block theme colors for use with Supabase Theme
+[data-theme='dark'],
+[data-theme='deep-dark'],
+.dark,
+.deep-dark {
+ --code-token-keyword: #bda4ff;
+ --code-foreground: #ffffff;
+ --code-token-constant: #3ecf8e;
+ --code-token-string: #ffcda1;
+ --code-token-comment: #7e7e7e;
+ --code-token-parameter: #ffffff;
+ --code-token-function: #3ecf8e;
+ --code-token-string-expression: #ffcda1;
+ --code-token-punctuation: #ffffff;
+ --code-token-link: #ffffff;
+ --code-token-number: #ffffff;
+ --code-token-property: #3ecf8e;
+ --code-highlight-color: #232323;
+}
+[data-theme='light'],
+.light {
+ --code-token-keyword: #6b35dc;
+ --code-foreground: hsl(var(--foreground-light) / 1);
+ --code-token-constant: #15593b;
+ --code-token-string: #f1a10d;
+ --code-token-comment: #7e7e7e;
+ --code-token-parameter: hsl(var(--foreground-light) / 1);
+ --code-token-function: #15593b;
+ --code-token-string-expression: #f1a10d;
+ --code-token-punctuation: hsl(var(--foreground-light) / 1);
+ --code-token-link: hsl(var(--foreground-light) / 1);
+ --code-token-number: hsl(var(--foreground-light) / 1);
+ --code-token-property: #15593b;
+ --code-highlight-color: #1c1c1c;
+}