Skip to content

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

feat(docs-gpt): markdown formatted responses

Greg Richardsonbfc2795b5bf6
diff --git a/apps/docs/components/Clippy/ClippyModal.tsx b/apps/docs/components/Clippy/ClippyModal.tsx
index 3edb3dce4b1..c7a3e7bcca2 100644
--- a/apps/docs/components/Clippy/ClippyModal.tsx
+++ b/apps/docs/components/Clippy/ClippyModal.tsx
@@ -1,6 +1,8 @@
import { useSupabaseClient } from '@supabase/auth-helpers-react'
import { FC, useCallback, useState } from 'react'
-import { Input } from '~/../../packages/ui'
+import ReactMarkdown from 'react-markdown'
+import { Input, Loading } from '~/../../packages/ui'
+import components from '~/components'
type Props = {
onClose?: () => void
@@ -35,14 +37,14 @@ const ClippyModal: FC<Props> = ({ onClose }) => {
onClick={onClose}
>
<div
- className={`mx-auto flex flex-col gap-6 rounded-lg p-6 w-full max-w-2xl shadow-2xl overflow-hidden border text-left border-scale-500 dark:bg-scale-300 cursor-auto`}
+ className={`prose dark:prose-dar mx-auto flex flex-col gap-4 rounded-lg p-6 w-full max-w-3xl shadow-2xl overflow-hidden border text-left border-scale-500 dark:bg-scale-300 cursor-auto`}
onClick={(e) => e.stopPropagation()}
>
<Input
className="w-full"
size="xlarge"
autoFocus
- placeholder="What can I help you with?"
+ placeholder="Ask me anything about Supabase"
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={(e) => {
@@ -55,8 +57,31 @@ const ClippyModal: FC<Props> = ({ onClose }) => {
}
}}
/>
- {isLoading && 'Loading'}
- {answer && <div>{answer}</div>}
+ {isLoading && (
+ <div className="p-6">
+ <Loading active>{}</Loading>
+ </div>
+ )}
+ {answer && (
+ <div className="px-8 py-4 dark dark:bg-scale-200 rounded-lg overflow-y-scroll">
+ <ReactMarkdown
+ linkTarget="_blank"
+ transformLinkUri={(href) => {
+ const supabaseUrl = new URL('https://supabase.com')
+ const linkUrl = new URL(href, 'https://supabase.com')
+
+ if (linkUrl.origin === supabaseUrl.origin) {
+ return linkUrl.toString()
+ }
+
+ return href
+ }}
+ components={components}
+ >
+ {answer}
+ </ReactMarkdown>
+ </div>
+ )}
</div>
</div>
)
diff --git a/apps/docs/components/CodeBlock/CodeBlock.tsx b/apps/docs/components/CodeBlock/CodeBlock.tsx
index f4e962bb2aa..7b98e265ff2 100644
--- a/apps/docs/components/CodeBlock/CodeBlock.tsx
+++ b/apps/docs/components/CodeBlock/CodeBlock.tsx
@@ -1,4 +1,4 @@
-import { FC } from 'react'
+import { Children, FC } from 'react'
import CopyToClipboard from 'react-copy-to-clipboard'
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter'
import monokaiCustomTheme from './CodeBlock.utils'
@@ -48,10 +48,18 @@ const CodeBlock: FC<Props> = ({
}, 1000)
}
+ // Extract string when `children` has a single string node
+ const childrenArray = Children.toArray(children)
+ const [singleChild] = childrenArray.length === 1 ? childrenArray : []
+ const singleString = typeof singleChild === 'string' ? singleChild : undefined
+
+ let codeValue = value ?? singleString ?? children
+ codeValue = codeValue.trimEnd?.() ?? codeValue
+
// check the length of the string inside the <code> tag
// if it's fewer than 70 characters, add a white-space: pre so it doesn't wrap
const shortCodeBlockClasses =
- typeof children === 'string' && children.length < 70 ? 'short-inline-codeblock' : ''
+ typeof codeValue === 'string' && codeValue.length < 70 ? 'short-inline-codeblock' : ''
let lang = language ? language : className ? className.replace('language-', '') : 'js'
// force jsx to be js highlighted
@@ -116,7 +124,7 @@ const CodeBlock: FC<Props> = ({
paddingBottom: '4px',
}}
>
- {(value || children)?.trimEnd()}
+ {codeValue}
</SyntaxHighlighter>
{!hideCopy && (value || children) && className ? (
<div