Skip to content

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

Add dart syntax highlighting

Joshen Lim5964012c1e3d
diff --git a/studio/lib/constants/prism.ts b/studio/lib/constants/prism.ts
new file mode 100644
index 00000000000..47bf84c5a0d
--- /dev/null
+++ b/studio/lib/constants/prism.ts
@@ -0,0 +1,79 @@
+// Prism syntax highlighting referenced from Refractor
+// https://github.com/wooorm/refractor/blob/main/lang/dart.js
+
+export function dart(Prism: any) {
+ // Handles named imports, such as http.Client
+ const keywords = [
+ /\b(?:async|sync|yield)\*/,
+ /\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extends|extension|external|factory|final|finally|for|get|hide|if|implements|import|in|interface|library|mixin|new|null|on|operator|part|rethrow|return|set|show|static|super|switch|sync|this|throw|try|typedef|var|void|while|with|yield)\b/,
+ ]
+
+ // based on the dart naming conventions
+ const packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source
+
+ const className = {
+ pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
+ lookbehind: true,
+ inside: {
+ namespace: {
+ pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
+ inside: {
+ punctuation: /\./,
+ },
+ },
+ },
+ }
+
+ Prism.languages.dart = Prism.languages.extend('clike', {
+ 'class-name': [
+ className,
+ {
+ // variables and parameters
+ // this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods)
+ pattern: RegExp(packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source),
+ lookbehind: true,
+ inside: className.inside,
+ },
+ ],
+ keyword: keywords,
+ operator: /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/,
+ })
+ Prism.languages.insertBefore('dart', 'string', {
+ 'string-literal': {
+ pattern: /r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/,
+ greedy: true,
+ inside: {
+ interpolation: {
+ pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/,
+ lookbehind: true,
+ inside: {
+ punctuation: /^\$\{?|\}$/,
+ expression: {
+ pattern: /[\s\S]+/,
+ inside: Prism.languages.dart,
+ },
+ },
+ },
+ string: /[\s\S]+/,
+ },
+ },
+ string: undefined,
+ })
+ Prism.languages.insertBefore('dart', 'class-name', {
+ metadata: {
+ pattern: /@\w+/,
+ alias: 'function',
+ },
+ })
+ Prism.languages.insertBefore('dart', 'class-name', {
+ generics: {
+ pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/,
+ inside: {
+ 'class-name': className,
+ keyword: keywords,
+ punctuation: /[<>(),.:]/,
+ operator: /[?&|]/,
+ },
+ },
+ })
+}
diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsx
index d9a8d280b26..64b3e5375c8 100644
--- a/studio/pages/_app.tsx
+++ b/studio/pages/_app.tsx
@@ -16,6 +16,9 @@ import customParseFormat from 'dayjs/plugin/customParseFormat'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
+// @ts-ignore
+import Prism from 'prism-react-renderer/prism'
+
import Head from 'next/head'
import { AppPropsWithLayout } from 'types'
@@ -24,6 +27,7 @@ import { RootStore } from 'stores'
import { StoreProvider } from 'hooks'
import { GOTRUE_ERRORS } from 'lib/constants'
import { auth } from 'lib/gotrue'
+import { dart } from 'lib/constants/prism'
import { PortalToast, RouteValidationWrapper, AppBannerWrapper } from 'components/interfaces/App'
import PageTelemetry from 'components/ui/PageTelemetry'
@@ -33,6 +37,8 @@ dayjs.extend(customParseFormat)
dayjs.extend(utc)
dayjs.extend(timezone)
+dart(Prism)
+
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
const [rootStore] = useState(() => new RootStore())