@stainless-api/docs 0.1.0-beta.99 → 1.0.0-beta.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +390 -0
- package/ambient.d.ts +6 -0
- package/eslint-suppressions.json +22 -6
- package/{eslint.config.js → eslint.config.ts} +1 -7
- package/package.json +57 -40
- package/plugin/buildAlgoliaIndex.ts +6 -12
- package/plugin/components/SDKSelect.astro +0 -6
- package/plugin/components/SnippetCode.tsx +6 -37
- package/plugin/components/search/SearchAlgolia.astro +1 -1
- package/plugin/components/search/SearchIsland.tsx +19 -13
- package/plugin/generateAPIReferenceLink.ts +0 -40
- package/plugin/globalJs/ai-dropdown-options.ts +22 -9
- package/plugin/globalJs/code-snippets.ts +5 -5
- package/plugin/globalJs/copy.ts +20 -91
- package/plugin/globalJs/navigation.ts +13 -13
- package/plugin/globalJs/summary-selection-tweak.ts +29 -0
- package/plugin/index.ts +107 -163
- package/plugin/loadPluginConfig.ts +49 -151
- package/plugin/markdown/highlighter.ts +100 -0
- package/plugin/markdown/index.ts +39 -0
- package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +2 -0
- package/plugin/react/Routing.tsx +10 -244
- package/plugin/referencePlaceholderUtils.ts +1 -1
- package/plugin/replaceSidebarPlaceholderMiddleware.ts +1 -1
- package/plugin/routes/Docs.astro +3 -1
- package/plugin/routes/Overview.astro +14 -7
- package/plugin/routes/llms.ts +186 -0
- package/plugin/routes/markdown.ts +62 -13
- package/plugin/sidebar-utils/sidebar-builder.ts +38 -12
- package/plugin/specs/defaultSpecLoader.ts +192 -0
- package/plugin/specs/fetchSpecSSR.ts +1 -1
- package/plugin/specs/utils.ts +86 -0
- package/shared/conditionalIntegration.ts +28 -0
- package/shared/getProsePages.ts +6 -7
- package/shared/virtualModule.ts +1 -26
- package/stl-docs/aiChatExamples.ts +31 -0
- package/stl-docs/chat/docs-chat-handler.ts +17 -0
- package/stl-docs/chat/hook.ts +225 -0
- package/stl-docs/chat/schemas.ts +27 -0
- package/stl-docs/chat/ui/AiChat.module.css +591 -0
- package/stl-docs/chat/ui/AiChat.tsx +175 -0
- package/stl-docs/chat/ui/Trigger.tsx +154 -0
- package/stl-docs/chat/ui/components/ChatControls.tsx +51 -0
- package/stl-docs/chat/ui/components/ChatEmpty.tsx +42 -0
- package/stl-docs/chat/ui/components/ChatLog.tsx +93 -0
- package/stl-docs/chat/ui/components/ChatMessage.tsx +47 -0
- package/stl-docs/chat/ui/components/CodeBlock.tsx +33 -0
- package/stl-docs/chat/ui/components/MessageFeedback.tsx +106 -0
- package/stl-docs/chat/ui/components/Table.tsx +15 -0
- package/stl-docs/chat/ui/components/ToolCall.tsx +34 -0
- package/stl-docs/chat/ui/components/hljs-github.css +81 -0
- package/stl-docs/chat/ui/scroll-manager.ts +86 -0
- package/stl-docs/chat/ui/types.ts +45 -0
- package/stl-docs/components/AiChatIsland.tsx +10 -12
- package/stl-docs/components/ContentPanel.astro +9 -0
- package/stl-docs/components/Footer.astro +89 -0
- package/stl-docs/components/Header.astro +0 -5
- package/stl-docs/components/PageFrame.astro +23 -8
- package/stl-docs/components/PageSidebar.astro +11 -0
- package/stl-docs/components/StainlessLogo.svg +4 -0
- package/stl-docs/components/TwoColumnContent.astro +2 -0
- package/stl-docs/components/headers/DefaultHeader.astro +6 -8
- package/stl-docs/components/headers/StackedHeader.astro +5 -53
- package/stl-docs/components/mintlify-compat/Accordion.astro +2 -2
- package/stl-docs/components/mintlify-compat/AccordionGroup.astro +0 -4
- package/stl-docs/components/mintlify-compat/Columns.astro +2 -2
- package/stl-docs/components/mintlify-compat/Frame.astro +2 -2
- package/stl-docs/components/mintlify-compat/Tab.astro +2 -2
- package/stl-docs/components/mintlify-compat/callouts/Callout.astro +2 -2
- package/stl-docs/components/mintlify-compat/callouts/Check.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Danger.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Info.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Note.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Tip.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Warning.astro +0 -4
- package/stl-docs/components/nav-tabs/NavDropdown.astro +12 -7
- package/stl-docs/components/nav-tabs/NavTabs.astro +5 -3
- package/stl-docs/components/nav-tabs/buildNavLinks.ts +2 -0
- package/stl-docs/components/pagination/Pagination.astro +4 -2
- package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +2 -2
- package/stl-docs/components/pagination/PaginationLinkQuiet.astro +2 -2
- package/stl-docs/components/pagination/util.ts +3 -3
- package/stl-docs/components/sidebars/BaseSidebar.astro +72 -1
- package/stl-docs/disableCalloutSyntax.ts +1 -1
- package/stl-docs/fonts.ts +5 -5
- package/stl-docs/index.ts +76 -53
- package/stl-docs/loadStlDocsConfig.ts +38 -8
- package/stl-docs/og-image/components/OpenGraphFunctionSignature.tsx +64 -0
- package/stl-docs/og-image/components/OpenGraphImage.tsx +126 -0
- package/stl-docs/og-image/config.ts +56 -0
- package/stl-docs/og-image/image-gen/generate-api-reference-og-image.tsx +188 -0
- package/stl-docs/og-image/image-gen/generate-og-image.tsx +119 -0
- package/stl-docs/og-image/image-gen/get-logo-url.ts +47 -0
- package/stl-docs/og-image/index.ts +135 -0
- package/stl-docs/og-image/routes/add-og-image.ts +45 -0
- package/stl-docs/og-image/routes/get-api-reference-og-image.ts +36 -0
- package/stl-docs/og-image/routes/get-og-image.ts +28 -0
- package/stl-docs/og-image/theme.ts +43 -0
- package/stl-docs/og-image/utils.ts +14 -0
- package/stl-docs/proseDocSync.test.ts +74 -0
- package/stl-docs/proseDocSync.ts +344 -0
- package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +4 -12
- package/stl-docs/schema-extension.ts +12 -0
- package/stl-docs/tabsMiddleware.ts +1 -1
- package/styles/overrides.css +2 -14
- package/styles/page.css +210 -71
- package/styles/sidebar.css +30 -17
- package/styles/sl-variables.css +3 -8
- package/styles/stldocs-variables.css +2 -2
- package/styles/toc.css +8 -0
- package/tsconfig.json +1 -1
- package/virtual-module.d.ts +35 -11
- package/playground-virtual-modules.d.ts +0 -96
- package/plugin/globalJs/create-playground.shim.ts +0 -3
- package/plugin/globalJs/playground-data.shim.ts +0 -1
- package/plugin/globalJs/playground-data.ts +0 -14
- package/plugin/specs/FileCache.ts +0 -99
- package/plugin/specs/generateSpec.ts +0 -112
- package/plugin/specs/index.ts +0 -132
- package/plugin/specs/inputResolver.ts +0 -146
- package/plugin/specs/worker.ts +0 -199
- package/plugin/vendor/preview.worker.docs.js +0 -26108
- package/plugin/vendor/templates/cli.md +0 -1
- package/plugin/vendor/templates/go.md +0 -316
- package/plugin/vendor/templates/java.md +0 -89
- package/plugin/vendor/templates/kotlin.md +0 -89
- package/plugin/vendor/templates/node.md +0 -235
- package/plugin/vendor/templates/python.md +0 -251
- package/plugin/vendor/templates/ruby.md +0 -147
- package/plugin/vendor/templates/terraform.md +0 -60
- package/plugin/vendor/templates/typescript.md +0 -319
- package/scripts/vendor_deps.ts +0 -50
- package/stl-docs/components/ClientRouterHead.astro +0 -41
- package/stl-docs/components/content-panel/ContentPanel.astro +0 -42
- package/stl-docs/components/headers/SplashMobileMenuToggle.astro +0 -65
- package/stl-docs/proseSearchIndexing.ts +0 -606
|
@@ -5,20 +5,22 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
5
5
|
import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
|
|
6
6
|
import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
7
7
|
import type { PropertySettingsType } from '@stainless-api/docs-ui/contexts';
|
|
8
|
-
import { bold } from '../shared/terminalUtils';
|
|
9
|
-
import { resolveSpec, SpecInputResolver } from './specs/inputResolver';
|
|
10
|
-
import { specCache, SpecCacheResult } from './specs/generateSpec';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
import { defaultSpecLoader } from './specs/defaultSpecLoader';
|
|
10
|
+
import { SpecLoaderFn } from './specs/utils';
|
|
11
|
+
|
|
12
|
+
type ApiKeySource = 'explicit-config' | 'environment-variable' | 'cli';
|
|
13
|
+
|
|
14
|
+
type LoadedApiKey = {
|
|
15
|
+
value: string;
|
|
16
|
+
source: ApiKeySource;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
type AstroCommand = 'dev' | 'build' | 'preview' | 'sync';
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
type ContentLayout = 'double-pane' | 'single-pane';
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
type VersionUserConfig = {
|
|
22
24
|
version: string;
|
|
23
25
|
stainlessProject: string;
|
|
24
26
|
branch: string;
|
|
@@ -50,17 +52,9 @@ export type StainlessStarlightUserConfig = {
|
|
|
50
52
|
stainlessProject: string;
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
|
-
*
|
|
55
|
+
* Optional function to provide your own loader for API reference data.
|
|
54
56
|
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* More advanced replacement for versions, basePath, and excludeLanguages.
|
|
59
|
-
*/
|
|
60
|
-
overrideSpecs?: {
|
|
61
|
-
specs: SpecInputResolver[];
|
|
62
|
-
};
|
|
63
|
-
};
|
|
57
|
+
loadSpecs?: SpecLoaderFn;
|
|
64
58
|
|
|
65
59
|
/**
|
|
66
60
|
* Optional list of versions to render in the API reference.
|
|
@@ -149,13 +143,7 @@ export type StainlessStarlightUserConfig = {
|
|
|
149
143
|
* @default true
|
|
150
144
|
*/
|
|
151
145
|
|
|
152
|
-
contextMenu?: boolean;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* When set to `import playgrounds from '@stainless-api/playgrounds'`, code snippets will have a "Play" button,
|
|
156
|
-
* allowing users to edit and run code snippets in their browser.
|
|
157
|
-
*/
|
|
158
|
-
experimentalPlaygrounds?: { playgroundsBase: string };
|
|
146
|
+
contextMenu?: boolean | { thirdParty?: boolean };
|
|
159
147
|
|
|
160
148
|
/** When set to true, enables the experimental request builder interface for testing API endpoints. */
|
|
161
149
|
experimentalRequestBuilder?: boolean;
|
|
@@ -165,6 +153,31 @@ export type StainlessStarlightUserConfig = {
|
|
|
165
153
|
* @default true
|
|
166
154
|
*/
|
|
167
155
|
experimentalPrerender?: boolean;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Configuration for the generated `/llms.txt` file.
|
|
159
|
+
*/
|
|
160
|
+
llmsTxt?: {
|
|
161
|
+
/**
|
|
162
|
+
* Whether to disable the generated `/llms.txt` file.
|
|
163
|
+
*
|
|
164
|
+
* @default false
|
|
165
|
+
*/
|
|
166
|
+
disabled?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* A short description of the site, used as the blockquote summary at the top of the file.
|
|
169
|
+
* Falls back to the top-level Starlight `description` field if not set.
|
|
170
|
+
*/
|
|
171
|
+
description?: string;
|
|
172
|
+
/**
|
|
173
|
+
* The maximum number of total routes (prose + API reference) at which the file switches
|
|
174
|
+
* from compact mode (resources only) to detailed mode (resources and
|
|
175
|
+
* methods).
|
|
176
|
+
*
|
|
177
|
+
* @default 2000
|
|
178
|
+
*/
|
|
179
|
+
detailThreshold?: number;
|
|
180
|
+
};
|
|
168
181
|
};
|
|
169
182
|
|
|
170
183
|
// TODO: eventually? re-add support for external spec servers
|
|
@@ -174,37 +187,6 @@ export type StainlessStarlightUserConfig = {
|
|
|
174
187
|
|
|
175
188
|
export type SomeStainlessStarlightUserConfig = StainlessStarlightUserConfig;
|
|
176
189
|
|
|
177
|
-
function resolvePath(inputPath: string) {
|
|
178
|
-
return path.resolve(process.cwd(), inputPath);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function getLocalFilePaths(command: AstroCommand) {
|
|
182
|
-
if (command !== 'dev') {
|
|
183
|
-
return null;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
|
187
|
-
const oasPath = process.env.OPENAPI_PATH;
|
|
188
|
-
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
|
189
|
-
const configPath = process.env.STAINLESS_CONFIG_PATH;
|
|
190
|
-
|
|
191
|
-
if (!oasPath || !configPath) {
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
oasPath: resolvePath(oasPath),
|
|
197
|
-
configPath: resolvePath(configPath),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export type ApiKeySource = 'explicit-config' | 'environment-variable' | 'cli';
|
|
202
|
-
|
|
203
|
-
export type LoadedApiKey = {
|
|
204
|
-
value: string;
|
|
205
|
-
source: ApiKeySource;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
190
|
function parseAuthJson(authJsonStr: string) {
|
|
209
191
|
let json: unknown;
|
|
210
192
|
try {
|
|
@@ -252,6 +234,7 @@ function loadApiKey(configValue: string | undefined): LoadedApiKey | null {
|
|
|
252
234
|
return { value: accessToken, source: 'cli' };
|
|
253
235
|
}
|
|
254
236
|
|
|
237
|
+
/** @public but discouraged - used by cloudflare via relative import */
|
|
255
238
|
export function forceLoadStainlessCredentials(): LoadedApiKey {
|
|
256
239
|
const v = loadApiKey(undefined);
|
|
257
240
|
if (!v) {
|
|
@@ -265,93 +248,6 @@ type AstroOptions = {
|
|
|
265
248
|
base: string;
|
|
266
249
|
};
|
|
267
250
|
|
|
268
|
-
export type ResolvedAPIConfigEntry = {
|
|
269
|
-
loadSpecs: () => Promise<SpecCacheResult[]>;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
function makeSimpleAPIConfig(
|
|
273
|
-
partial: SomeStainlessStarlightUserConfig,
|
|
274
|
-
astroOptions: AstroOptions,
|
|
275
|
-
): ResolvedAPIConfigEntry {
|
|
276
|
-
if (!('stainlessProject' in partial)) {
|
|
277
|
-
throw new Error('You must provide a stainlessProject when using Stainless Starlight');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const excludedLanguages = partial.excludeLanguages ?? [];
|
|
281
|
-
|
|
282
|
-
const apiKey = loadApiKey(partial.apiKey);
|
|
283
|
-
|
|
284
|
-
function getResolver() {
|
|
285
|
-
const localFilePaths = getLocalFilePaths(astroOptions.command);
|
|
286
|
-
if (localFilePaths) {
|
|
287
|
-
return resolveSpec.fromFiles({
|
|
288
|
-
oasPath: localFilePaths.oasPath,
|
|
289
|
-
configPath: localFilePaths.configPath,
|
|
290
|
-
languageOverrides: {
|
|
291
|
-
mode: 'exclude',
|
|
292
|
-
list: excludedLanguages,
|
|
293
|
-
},
|
|
294
|
-
stainlessProject: partial.stainlessProject,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (!apiKey) {
|
|
299
|
-
throw new Error(
|
|
300
|
-
[
|
|
301
|
-
bold(
|
|
302
|
-
'No Stainless credentials found. Please choose one of the following options to authenticate with Stainless:',
|
|
303
|
-
),
|
|
304
|
-
'- Run `stl auth login` to authenticate via the Stainless CLI',
|
|
305
|
-
'- Provide a Stainless API key via the `STAINLESS_API_KEY` environment variable (eg. in a .env file)',
|
|
306
|
-
'- Set the `apiKey` option in the Stainless Docs config',
|
|
307
|
-
].join('\n'),
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
return resolveSpec.fromStainlessApi({
|
|
311
|
-
stainlessProject: partial.stainlessProject,
|
|
312
|
-
branch: partial.versions?.[0]?.branch ?? 'main',
|
|
313
|
-
apiKey: apiKey,
|
|
314
|
-
languageOverrides: {
|
|
315
|
-
mode: 'exclude',
|
|
316
|
-
list: excludedLanguages,
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const resolver = getResolver();
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
loadSpecs: async function loadSpecs() {
|
|
325
|
-
const inputs = await resolver.resolve({ apiKey });
|
|
326
|
-
|
|
327
|
-
const result = await specCache.get(inputs);
|
|
328
|
-
|
|
329
|
-
return [result];
|
|
330
|
-
},
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function loadAPIConfig(
|
|
335
|
-
partial: SomeStainlessStarlightUserConfig,
|
|
336
|
-
astroOptions: AstroOptions,
|
|
337
|
-
): ResolvedAPIConfigEntry {
|
|
338
|
-
if (partial.advanced?.overrideSpecs) {
|
|
339
|
-
const overrides = partial.advanced.overrideSpecs;
|
|
340
|
-
const apiKey = loadApiKey(partial.apiKey);
|
|
341
|
-
return {
|
|
342
|
-
loadSpecs: async function loadSpecs() {
|
|
343
|
-
const specsPromises = overrides.specs.map(async (spec) => {
|
|
344
|
-
const inputs = await spec.resolve({ apiKey });
|
|
345
|
-
return await specCache.get(inputs);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
return await Promise.all(specsPromises);
|
|
349
|
-
},
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
return makeSimpleAPIConfig(partial, astroOptions);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
251
|
function normalizeConfig(partial: SomeStainlessStarlightUserConfig, astroOptions: AstroOptions) {
|
|
356
252
|
const configWithDefaults = {
|
|
357
253
|
basePath: partial.basePath ?? '/api',
|
|
@@ -381,18 +277,20 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, astroOptions
|
|
|
381
277
|
includeModelProperties: partial.propertySettings?.includeModelProperties ?? true,
|
|
382
278
|
},
|
|
383
279
|
contextMenu: partial.contextMenu ?? true,
|
|
384
|
-
experimentalPlaygrounds: partial.experimentalPlaygrounds ?? undefined,
|
|
385
280
|
experimentalRequestBuilder: partial.experimentalRequestBuilder ?? false,
|
|
386
281
|
experimentalPrerender: partial.experimentalPrerender ?? true,
|
|
387
282
|
stainlessProject: partial.stainlessProject,
|
|
283
|
+
llmsTxt: {
|
|
284
|
+
enabled: !partial.llmsTxt?.disabled,
|
|
285
|
+
description: partial.llmsTxt?.description ?? null,
|
|
286
|
+
detailThreshold: partial.llmsTxt?.detailThreshold ?? 2000,
|
|
287
|
+
},
|
|
288
|
+
apiKey: loadApiKey(partial.apiKey),
|
|
289
|
+
loadSpecs: partial.loadSpecs ?? defaultSpecLoader,
|
|
290
|
+
branch: partial.versions?.[0]?.branch ?? 'main',
|
|
388
291
|
};
|
|
389
292
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
return {
|
|
393
|
-
...configWithDefaults,
|
|
394
|
-
api,
|
|
395
|
-
};
|
|
293
|
+
return configWithDefaults;
|
|
396
294
|
}
|
|
397
295
|
|
|
398
296
|
export type NormalizedStainlessStarlightConfig = ReturnType<typeof normalizeConfig>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHighlighter,
|
|
3
|
+
type HighlighterGeneric,
|
|
4
|
+
type ThemeInput,
|
|
5
|
+
type BundledTheme,
|
|
6
|
+
type BundledLanguage,
|
|
7
|
+
} from 'shiki';
|
|
8
|
+
import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
|
|
9
|
+
import { SupportedLanguageSyntaxes } from '@stainless-api/docs-ui/routing';
|
|
10
|
+
import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
|
|
11
|
+
|
|
12
|
+
const STAINLESS_DOCS_JSON_THEME = {
|
|
13
|
+
name: 'stainless-docs-json',
|
|
14
|
+
colors: {
|
|
15
|
+
'editor.background': 'var(--stl-color-background)',
|
|
16
|
+
'editor.foreground': 'var(--stl-color-foreground)',
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
tokenColors: [
|
|
20
|
+
{
|
|
21
|
+
scope: ['comment', 'punctuation.definition.comment'],
|
|
22
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
23
|
+
},
|
|
24
|
+
// numbers, booleans, null
|
|
25
|
+
{
|
|
26
|
+
scope: ['constant.numeric', 'constant.language'],
|
|
27
|
+
settings: { foreground: 'var(--stl-color-orange-foreground)' },
|
|
28
|
+
},
|
|
29
|
+
// strings
|
|
30
|
+
{
|
|
31
|
+
scope: ['string', 'string.quoted', 'string.template'],
|
|
32
|
+
settings: { foreground: 'var(--stl-color-green-foreground)' },
|
|
33
|
+
},
|
|
34
|
+
// Keys, brackets
|
|
35
|
+
{
|
|
36
|
+
scope: ['support.type', 'meta'],
|
|
37
|
+
settings: { foreground: 'var(--stl-color-foreground)' },
|
|
38
|
+
},
|
|
39
|
+
// brackets
|
|
40
|
+
{
|
|
41
|
+
scope: ['meta'],
|
|
42
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
43
|
+
},
|
|
44
|
+
// built-in types
|
|
45
|
+
{
|
|
46
|
+
scope: ['support.type.builtin'],
|
|
47
|
+
settings: { foreground: 'var(--stl-color-purple-foreground)' },
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
} satisfies ThemeInput;
|
|
51
|
+
|
|
52
|
+
// singleton
|
|
53
|
+
let astroShikiHighlighter:
|
|
54
|
+
| HighlighterGeneric<BundledLanguage, BundledTheme>
|
|
55
|
+
| Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
|
|
56
|
+
| null = null;
|
|
57
|
+
async function getAstroHighlighter() {
|
|
58
|
+
if (astroShikiHighlighter) {
|
|
59
|
+
return astroShikiHighlighter;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
astroShikiHighlighter = createHighlighter({
|
|
63
|
+
themes: [
|
|
64
|
+
HIGHLIGHT_THEMES?.dark ?? 'github-dark',
|
|
65
|
+
HIGHLIGHT_THEMES?.light ?? 'github-light',
|
|
66
|
+
STAINLESS_DOCS_JSON_THEME,
|
|
67
|
+
],
|
|
68
|
+
langs: SupportedLanguageSyntaxes,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return astroShikiHighlighter;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function runHighlight({
|
|
75
|
+
highlighter,
|
|
76
|
+
content,
|
|
77
|
+
language,
|
|
78
|
+
themes,
|
|
79
|
+
}: {
|
|
80
|
+
highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
81
|
+
content: string;
|
|
82
|
+
language?: string;
|
|
83
|
+
themes?: CreateShikiHighlighterOptions['themes'] | Record<string, 'stainless-docs-json'>;
|
|
84
|
+
}) {
|
|
85
|
+
return highlighter.codeToHtml(content, {
|
|
86
|
+
lang: language ?? 'javascript',
|
|
87
|
+
themes:
|
|
88
|
+
// Default to user-provided themes except in case of json
|
|
89
|
+
themes ??
|
|
90
|
+
(language === 'JSON'
|
|
91
|
+
? { light: 'stainless-docs-json', dark: 'stainless-docs-json' }
|
|
92
|
+
: HIGHLIGHT_THEMES) ??
|
|
93
|
+
{},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function highlight(content: string, language?: string) {
|
|
98
|
+
const highlighter = await getAstroHighlighter();
|
|
99
|
+
return runHighlight({ highlighter, content, language });
|
|
100
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createMarkdownProcessor, type MarkdownProcessor } from '@astrojs/markdown-remark';
|
|
2
|
+
import remarkGfmAlerts from 'remark-github-alerts';
|
|
3
|
+
import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
|
|
4
|
+
|
|
5
|
+
// singleton
|
|
6
|
+
let astroMarkdownProcessor: MarkdownProcessor;
|
|
7
|
+
async function getAstroMarkdown() {
|
|
8
|
+
if (!astroMarkdownProcessor) {
|
|
9
|
+
astroMarkdownProcessor = await createMarkdownProcessor({
|
|
10
|
+
gfm: true,
|
|
11
|
+
remarkPlugins: [remarkGfmAlerts],
|
|
12
|
+
shikiConfig: { themes: HIGHLIGHT_THEMES },
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return astroMarkdownProcessor;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function astroMarkdownRender(content: string) {
|
|
20
|
+
const md = await getAstroMarkdown();
|
|
21
|
+
const output = await md.render(content);
|
|
22
|
+
|
|
23
|
+
// Map GFM callouts to the closest Starlight equivalent
|
|
24
|
+
// TODO: this sucks; we should be rendering via ui-primitives callouts instead of ugly theme-incompatible starlight ones
|
|
25
|
+
output.code = output.code
|
|
26
|
+
.replaceAll('markdown-alert-caution', 'markdown-alert-danger')
|
|
27
|
+
.replaceAll('markdown-alert-warning', 'markdown-alert-caution')
|
|
28
|
+
.replaceAll('markdown-alert-important', 'markdown-alert-caution')
|
|
29
|
+
.replaceAll('markdown-alert-title', 'starlight-aside__title')
|
|
30
|
+
.replaceAll('markdown-alert-', 'starlight-aside--')
|
|
31
|
+
.replaceAll('markdown-alert', 'starlight-aside');
|
|
32
|
+
|
|
33
|
+
return output;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function astroMarkdownRenderText(content: string) {
|
|
37
|
+
const result = await astroMarkdownRender(content);
|
|
38
|
+
return result.code;
|
|
39
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/components/sdk';
|
|
2
|
+
import type { AppComponents } from '@stainless-api/docs-ui/contexts/component';
|
|
2
3
|
|
|
3
4
|
export type StlStarlightMiddleware = {
|
|
4
5
|
transformRequestSnippet?: TransformRequestSnippetFn;
|
|
6
|
+
componentOverrides?: Partial<AppComponents>;
|
|
5
7
|
};
|