Files
supabase/apps/docs/features/directives/utils.ts
Chris Chinchilla 6821c07811 docs: feature toggle tests (#38282)
* Docs feature toggle tests

* Prettier

* Types fix

* Hide unsupported languages

* Fix import

* Add unsupported code warning

* Further SDK toggling

* Temp intro text

* Auth toggles

* clean up conditional visibility code

* fix: typecheck, tests, tiny bug

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2025-09-04 16:46:08 +02:00

41 lines
1.3 KiB
TypeScript

import { type Root } from 'mdast'
import { gfmToMarkdown } from 'mdast-util-gfm'
import { mdxToMarkdown } from 'mdast-util-mdx'
import { toMarkdown } from 'mdast-util-to-markdown'
import remarkMkDocsAdmonition from '~/lib/mdx/plugins/remarkAdmonition'
import remarkPyMdownTabs from '~/lib/mdx/plugins/remarkTabs'
import { getGitHubFileContentsImmutableOnly } from '~/lib/octokit'
import { codeSampleRemark } from './CodeSample'
import { codeTabsRemark } from './CodeTabs'
import { fromDocsMarkdown } from './utils.server'
import { partialsRemark } from './Partial'
import { showRemark } from './Show'
type Transformer = (ast: Root) => Root | Promise<Root>
export async function preprocessMdx<T>(mdx: string, transformers: Transformer[]) {
if (!mdx) return mdx
let mdast = fromDocsMarkdown(mdx)
for (const transform of transformers) {
mdast = await transform(mdast)
}
const output = toMarkdown(mdast, { extensions: [mdxToMarkdown(), gfmToMarkdown()] })
return output
}
export function preprocessMdxWithDefaults(mdx: string) {
return preprocessMdx(mdx, [
showRemark(),
remarkMkDocsAdmonition(),
remarkPyMdownTabs(),
partialsRemark(),
codeSampleRemark({
fetchFromGitHub: getGitHubFileContentsImmutableOnly,
}),
codeTabsRemark(),
])
}