Skip to content

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

feat(kb): Apply supabase theme to code blocks (#49957)

Jeremias Menichelli0ab0bb8efd3d
diff --git a/apps/kb/astro.config.mjs b/apps/kb/astro.config.mjs
index f44675364a7..019ad553395 100644
--- a/apps/kb/astro.config.mjs
+++ b/apps/kb/astro.config.mjs
@@ -6,6 +6,8 @@ import react from '@astrojs/react'
import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'astro/config'
+import supabaseTheme from '../learn/lib/themes/supabase-2.json' with { type: 'json' }
+
// Absolute dir of lodash-es, for the SSR-only lodash alias below (same fix
// apps/studio/vite.config.ts uses). `packages/ui`'s clipboard util does
// `import { noop } from 'lodash'` — under Vite's dev-mode SSR module runner,
@@ -45,4 +47,23 @@ export default defineConfig({
},
plugins: [tailwindcss(), ssrLodashEs],
},
+ markdown: {
+ shikiConfig: {
+ theme: supabaseTheme,
+ // Match the docs app's CodeBlock component (border + rounded-lg on the
+ // outer element), since Astro's own markdown pipeline renders code
+ // blocks straight to a `<pre>` with no wrapper we can add classes to.
+ transformers: [
+ {
+ name: 'kb-code-block-classes',
+ pre(node) {
+ this.addClassToHast(node, 'border border-default rounded-lg')
+ },
+ code(node) {
+ this.addClassToHast(node, 'inline-block p-6')
+ },
+ },
+ ],
+ },
+ },
})
diff --git a/apps/kb/src/styles/globals.css b/apps/kb/src/styles/globals.css
index b15951345ec..efb8df5e7bb 100644
--- a/apps/kb/src/styles/globals.css
+++ b/apps/kb/src/styles/globals.css
@@ -73,8 +73,35 @@ h6:not(.font-mono),
border-color: var(--border-default, currentColor);
}
-/* TEMPORARY UNTIL WE IMPLEMENT OUR OWN CODE COMPONENT */
-.prose pre code {
- padding: 1rem;
- display: inline-block;
+/* Code block theme colors for use with Supabase Theme */
+[data-theme='dark'] {
+ --code-token-keyword: #bda4ff;
+ --code-foreground: #ffffff;
+ --code-token-constant: #3ecf8e;
+ --code-token-string: #ffcda1;
+ --code-token-comment: #949494;
+ --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'] {
+ --code-token-keyword: #5f2fc4;
+ --code-foreground: oklch(from var(--foreground-light) l c h / 1);
+ --code-token-constant: #15593b;
+ --code-token-string: #9a5200;
+ --code-token-comment: #6a6a6a;
+ --code-token-parameter: oklch(from var(--foreground-light) l c h / 1);
+ --code-token-function: #15593b;
+ --code-token-string-expression: #9a5200;
+ --code-token-punctuation: oklch(from var(--foreground-light) l c h / 1);
+ --code-token-link: oklch(from var(--foreground-light) l c h / 1);
+ --code-token-number: oklch(from var(--foreground-light) l c h / 1);
+ --code-token-property: #15593b;
+ --code-highlight-color: #1c1c1c;
}