@stainless-api/docs 0.1.0-beta.44 → 0.1.0-beta.46
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 +31 -0
- package/package.json +13 -13
- package/plugin/components/MethodDescription.tsx +54 -0
- package/plugin/components/SDKSelect.astro +0 -82
- package/plugin/components/search/SearchIsland.tsx +4 -1
- package/plugin/globalJs/method-descriptions.ts +33 -0
- package/plugin/index.ts +2 -9
- package/plugin/loadPluginConfig.ts +9 -0
- package/plugin/react/Routing.tsx +117 -24
- package/plugin/routes/Docs.astro +1 -0
- package/stl-docs/components/Header.astro +3 -6
- package/stl-docs/components/PageTitle.astro +1 -1
- package/stl-docs/components/ThemeSelect.astro +41 -32
- package/stl-docs/components/content-panel/ContentPanel.astro +0 -3
- package/stl-docs/components/headers/SplashMobileMenuToggle.astro +5 -8
- package/stl-docs/components/icons/chat-gpt.tsx +1 -1
- package/stl-docs/components/icons/cursor.tsx +1 -1
- package/stl-docs/components/icons/markdown.tsx +1 -1
- package/stl-docs/components/mintlify-compat/Frame.astro +4 -4
- package/stl-docs/components/mintlify-compat/Step.astro +3 -3
- package/stl-docs/components/mintlify-compat/card.css +4 -4
- package/stl-docs/components/nav-tabs/NavDropdown.astro +2 -12
- package/stl-docs/components/nav-tabs/NavTabs.astro +1 -17
- package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +1 -2
- package/stl-docs/components/pagination/Pagination.astro +12 -11
- package/stl-docs/index.ts +20 -0
- package/stl-docs/loadStlDocsConfig.ts +2 -0
- package/styles/code.css +14 -39
- package/styles/links.css +2 -0
- package/styles/method-descriptions.css +36 -0
- package/styles/overrides.css +26 -30
- package/styles/sdk_select.css +1 -1
- package/styles/search.css +10 -11
- package/styles/sidebar.css +41 -28
- package/styles/{variables.css → sl-variables.css} +3 -2
- package/styles/stldocs-variables.css +6 -0
- package/styles/toc.css +11 -8
- package/theme.css +6 -4
- package/virtual-module.d.ts +1 -0
- package/components/variables.css +0 -109
- package/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @stainless-api/docs
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.46
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b61b7c1: New theming system
|
|
8
|
+
|
|
9
|
+
A whole new set of design system variables used throughout docs, docs-ui, and ui-primitives
|
|
10
|
+
|
|
11
|
+
Improves customizability & uniformness compared to the old set of variables.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [b61b7c1]
|
|
16
|
+
- Updated dependencies [262f201]
|
|
17
|
+
- @stainless-api/docs-ui@0.1.0-beta.38
|
|
18
|
+
- @stainless-api/ui-primitives@0.1.0-beta.27
|
|
19
|
+
|
|
20
|
+
## 0.1.0-beta.45
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 00b33d9: syntax highlighting for markdown renderer
|
|
25
|
+
- fa43cff: json brackets should use muted foreground color
|
|
26
|
+
- c06e5c3: update marked dependency
|
|
27
|
+
- 32d1735: experimental support for collapsible method descriptions
|
|
28
|
+
- Updated dependencies [00b33d9]
|
|
29
|
+
- Updated dependencies [32d1735]
|
|
30
|
+
- Updated dependencies [23254d1]
|
|
31
|
+
- @stainless-api/ui-primitives@0.1.0-beta.26
|
|
32
|
+
- @stainless-api/docs-ui@0.1.0-beta.37
|
|
33
|
+
|
|
3
34
|
## 0.1.0-beta.44
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stainless-api/docs",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.46",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -26,21 +26,21 @@
|
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@astrojs/starlight": ">=0.36.1",
|
|
28
28
|
"astro": ">=5.15.3",
|
|
29
|
-
"vite": ">=6.2.1",
|
|
30
29
|
"react": ">=19.0.0",
|
|
31
|
-
"react-dom": ">=19.0.0"
|
|
30
|
+
"react-dom": ">=19.0.0",
|
|
31
|
+
"vite": ">=6.2.1"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@astrojs/markdown-remark": "^6.3.9",
|
|
35
35
|
"@astrojs/react": "^4.4.2",
|
|
36
|
-
"@stainless-api/sdk": "0.1.0-alpha.
|
|
36
|
+
"@stainless-api/sdk": "0.1.0-alpha.16",
|
|
37
|
+
"astro-expressive-code": "^0.41.3",
|
|
37
38
|
"cheerio": "^1.1.2",
|
|
38
39
|
"clsx": "^2.1.1",
|
|
39
40
|
"dotenv": "17.2.3",
|
|
40
41
|
"get-port": "^7.1.0",
|
|
41
|
-
"highlight.js": "^11.11.1",
|
|
42
42
|
"lucide-react": "^0.554.0",
|
|
43
|
-
"marked": "^
|
|
43
|
+
"marked": "^17.0.1",
|
|
44
44
|
"node-html-parser": "^7.0.1",
|
|
45
45
|
"rehype-parse": "^9.0.1",
|
|
46
46
|
"rehype-remark": "^10.0.1",
|
|
@@ -51,23 +51,23 @@
|
|
|
51
51
|
"unified": "^11.0.5",
|
|
52
52
|
"web-worker": "^1.5.0",
|
|
53
53
|
"yaml": "^2.8.1",
|
|
54
|
-
"@stainless-api/
|
|
55
|
-
"@stainless-api/ui
|
|
54
|
+
"@stainless-api/ui-primitives": "0.1.0-beta.27",
|
|
55
|
+
"@stainless-api/docs-ui": "0.1.0-beta.38"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@astrojs/check": "^0.9.5",
|
|
59
59
|
"@markdoc/markdoc": "^0.5.4",
|
|
60
60
|
"@types/node": "24.10.1",
|
|
61
|
-
"@types/react": "^19.2.
|
|
61
|
+
"@types/react": "^19.2.7",
|
|
62
62
|
"@types/react-dom": "^19.2.3",
|
|
63
63
|
"react": "^19.2.0",
|
|
64
64
|
"react-dom": "^19.2.0",
|
|
65
|
-
"tsx": "^4.20.
|
|
65
|
+
"tsx": "^4.20.6",
|
|
66
66
|
"typescript": "5.9.3",
|
|
67
67
|
"vite": "^6.4.1",
|
|
68
|
-
"zod": "^4.1.
|
|
69
|
-
"@stainless/
|
|
70
|
-
"@stainless/
|
|
68
|
+
"zod": "^4.1.13",
|
|
69
|
+
"@stainless/sdk-json": "^0.1.0-beta.0",
|
|
70
|
+
"@stainless/eslint-config": "0.1.0-beta.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"vendor-deps": "pnpm tsx scripts/vendor_deps.ts",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MethodDescriptionProps } from '@stainless-api/docs-ui/components';
|
|
2
|
+
import { useComponents } from '@stainless-api/docs-ui/contexts/use-components';
|
|
3
|
+
import style from '@stainless-api/docs-ui/style';
|
|
4
|
+
import { Button } from '@stainless-api/ui-primitives';
|
|
5
|
+
|
|
6
|
+
function shouldCollapseDescription(description: string) {
|
|
7
|
+
const MIN_CHARS = 400;
|
|
8
|
+
const MIN_LINES = 6;
|
|
9
|
+
|
|
10
|
+
const lineCount = description.split('\n').length;
|
|
11
|
+
|
|
12
|
+
if (description.length >= MIN_CHARS) return true;
|
|
13
|
+
if (lineCount >= MIN_LINES) return true;
|
|
14
|
+
|
|
15
|
+
// Markdown structure often means longer content
|
|
16
|
+
if (/#\s/.test(description)) return true; // has headings
|
|
17
|
+
if (/```/.test(description)) return true; // has code blocks
|
|
18
|
+
if (/^\s*[-*]\s+/m.test(description)) return true; // has lists
|
|
19
|
+
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function MethodDescription({ description }: MethodDescriptionProps) {
|
|
24
|
+
const { Markdown } = useComponents();
|
|
25
|
+
|
|
26
|
+
if (description) {
|
|
27
|
+
// Attempt to determine if we should make the description collapsible initially
|
|
28
|
+
// or not. If we get this right, there will be no FOUC.
|
|
29
|
+
const collapsible = shouldCollapseDescription(description);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="stl-method-description">
|
|
33
|
+
<div
|
|
34
|
+
className={style.MethodDescription}
|
|
35
|
+
data-stldocs-property-group="method-description"
|
|
36
|
+
data-collapsed={collapsible ? 'true' : 'false'}
|
|
37
|
+
>
|
|
38
|
+
<Markdown content={description} />
|
|
39
|
+
</div>
|
|
40
|
+
<div className="stl-method-description-overflow-wrapper">
|
|
41
|
+
<Button
|
|
42
|
+
type="button"
|
|
43
|
+
data-method-description-toggle
|
|
44
|
+
size="sm"
|
|
45
|
+
variant="ghost"
|
|
46
|
+
hidden={!collapsible}
|
|
47
|
+
>
|
|
48
|
+
Show more
|
|
49
|
+
</Button>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -53,88 +53,6 @@ const readmeSlug = language === 'http' ? BASE_PATH : `${BASE_PATH}/${language}`;
|
|
|
53
53
|
)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
<style>
|
|
57
|
-
@layer starlight.core {
|
|
58
|
-
label {
|
|
59
|
-
--sl-label-icon-size: 16px;
|
|
60
|
-
--sl-caret-size: 1.25rem;
|
|
61
|
-
--sl-inline-padding: 0.5rem;
|
|
62
|
-
position: relative;
|
|
63
|
-
display: flex;
|
|
64
|
-
align-items: center;
|
|
65
|
-
gap: 0.25rem;
|
|
66
|
-
color: var(--sl-color-gray-1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
label:hover {
|
|
70
|
-
color: var(--sl-color-gray-2);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.icon {
|
|
74
|
-
position: absolute;
|
|
75
|
-
top: 50%;
|
|
76
|
-
transform: translateY(-50%);
|
|
77
|
-
pointer-events: none;
|
|
78
|
-
width: 16px;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
select {
|
|
82
|
-
padding-block: 0.3rem;
|
|
83
|
-
padding-inline: calc(var(--sl-label-icon-size) + var(--sl-inline-padding) + 0.5rem)
|
|
84
|
-
calc(var(--sl-caret-size) + var(--sl-inline-padding) + 0.25rem);
|
|
85
|
-
margin-inline: calc(var(--sl-inline-padding) * -1);
|
|
86
|
-
width: calc(var(--sl-select-width) + var(--sl-inline-padding) * 2);
|
|
87
|
-
text-overflow: ellipsis;
|
|
88
|
-
color: inherit;
|
|
89
|
-
cursor: pointer;
|
|
90
|
-
appearance: none;
|
|
91
|
-
font-weight: 600;
|
|
92
|
-
text-transform: capitalize;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
select:active {
|
|
96
|
-
font-weight: inherit;
|
|
97
|
-
/* font-family: sans-serif;
|
|
98
|
-
font-weight: 400; */
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
option {
|
|
102
|
-
background-color: var(--sl-color-bg-nav);
|
|
103
|
-
color: var(--sl-color-gray-1);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@media (min-width: 50rem) {
|
|
107
|
-
select {
|
|
108
|
-
font-size: var(--sl-text-sm);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@layer starlight.components {
|
|
114
|
-
.label-icon {
|
|
115
|
-
font-size: var(--sl-label-icon-size);
|
|
116
|
-
inset-inline-start: 0;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
.caret {
|
|
120
|
-
font-size: var(--sl-caret-size);
|
|
121
|
-
inset-inline-end: 0;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
.custom-select-wrapper {
|
|
126
|
-
--sl-inline-padding: 0.5rem;
|
|
127
|
-
position: relative;
|
|
128
|
-
display: inline-block;
|
|
129
|
-
/* These match the padding on the sidebar menu */
|
|
130
|
-
padding-left: var(--sl-inline-padding);
|
|
131
|
-
padding-right: var(--sl-inline-padding);
|
|
132
|
-
|
|
133
|
-
.icon.http path {
|
|
134
|
-
fill: var(--sl-color-text);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
</style>
|
|
138
56
|
<script>
|
|
139
57
|
import { navigate } from 'astro:transitions/client';
|
|
140
58
|
import { updateSelectedLanguage } from '../languages';
|
|
@@ -38,7 +38,10 @@ async function createMarkdownRenderer(): Promise<MarkdownContext> {
|
|
|
38
38
|
transform(node, config) {
|
|
39
39
|
const attributes = node.transformAttributes(config);
|
|
40
40
|
const lang = node.attributes.language === 'node' ? 'typescript' : node.attributes.language;
|
|
41
|
-
const code = highlighter.codeToTokens(node.attributes.content, {
|
|
41
|
+
const code = highlighter.codeToTokens(node.attributes.content, {
|
|
42
|
+
lang,
|
|
43
|
+
theme: 'github-dark',
|
|
44
|
+
});
|
|
42
45
|
|
|
43
46
|
return new Markdoc.Tag(
|
|
44
47
|
'pre',
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
2
|
+
const COLLAPSED_HEIGHT = 170;
|
|
3
|
+
|
|
4
|
+
const container = document.querySelector<HTMLElement>('[data-stldocs-property-group="method-description"]');
|
|
5
|
+
|
|
6
|
+
if (!container) return;
|
|
7
|
+
|
|
8
|
+
const toggle = document?.querySelector<HTMLButtonElement>('[data-method-description-toggle]');
|
|
9
|
+
if (!toggle) return;
|
|
10
|
+
|
|
11
|
+
// If content isn't tall enough, don't show the button
|
|
12
|
+
if (container.scrollHeight <= COLLAPSED_HEIGHT + 1) {
|
|
13
|
+
toggle.hidden = true;
|
|
14
|
+
container.dataset.collapsed = 'false';
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Only show button if content is taller than collapsed max height
|
|
19
|
+
if (container.scrollHeight > COLLAPSED_HEIGHT + 1) {
|
|
20
|
+
toggle.hidden = false;
|
|
21
|
+
} else {
|
|
22
|
+
// Not tall enough to need collapsing — show full content and hide button
|
|
23
|
+
container.dataset.collapsed = 'false';
|
|
24
|
+
toggle.hidden = true;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toggle.addEventListener('click', function () {
|
|
29
|
+
const isCollapsed = container.dataset.collapsed !== 'false';
|
|
30
|
+
container.dataset.collapsed = isCollapsed ? 'false' : 'true';
|
|
31
|
+
toggle.textContent = isCollapsed ? 'Show less' : 'Show more';
|
|
32
|
+
});
|
|
33
|
+
});
|
package/plugin/index.ts
CHANGED
|
@@ -220,6 +220,8 @@ async function stlStarlightAstroIntegration(
|
|
|
220
220
|
HIGHLIGHT_THEMES: pluginConfig.highlighting.themes,
|
|
221
221
|
CONTENT_PANEL_LAYOUT: pluginConfig.contentPanel.layout,
|
|
222
222
|
EXPERIMENTAL_COLLAPSIBLE_SNIPPETS: pluginConfig.experimentalCollapsibleSnippets,
|
|
223
|
+
EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS:
|
|
224
|
+
pluginConfig.experimentalCollapsibleMethodDescriptions,
|
|
223
225
|
PROPERTY_SETTINGS: pluginConfig.propertySettings,
|
|
224
226
|
ENABLE_CONTEXT_MENU: pluginConfig.contextMenu,
|
|
225
227
|
} satisfies Omit<typeof StlStarlightVirtualModule, 'MIDDLEWARE'>),
|
|
@@ -308,15 +310,6 @@ export function stainlessStarlight(someUserConfig: SomeStainlessStarlightUserCon
|
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
|
|
311
|
-
const currentExpressiveCode =
|
|
312
|
-
typeof starlightConfig.expressiveCode === 'object' ? starlightConfig.expressiveCode : {};
|
|
313
|
-
updateConfig({
|
|
314
|
-
expressiveCode: {
|
|
315
|
-
...currentExpressiveCode,
|
|
316
|
-
themes: [...(currentExpressiveCode.themes || []), 'github-light', 'github-dark'],
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
|
|
320
313
|
updateConfig({
|
|
321
314
|
sidebar: starlightConfig.sidebar,
|
|
322
315
|
});
|
|
@@ -116,6 +116,14 @@ export type StainlessStarlightUserConfig = {
|
|
|
116
116
|
*/
|
|
117
117
|
experimentalCollapsibleSnippets?: boolean;
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Enable experimental collapsible method descriptions. Method descriptions will be
|
|
121
|
+
* collapsed if their content exceeds a certain length.
|
|
122
|
+
*
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
experimentalCollapsibleMethodDescriptions?: boolean;
|
|
126
|
+
|
|
119
127
|
/**
|
|
120
128
|
* Whether to show the context menu with options like "Copy as Markdown" and "Open in ChatGPT".
|
|
121
129
|
*
|
|
@@ -247,6 +255,7 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: Ast
|
|
|
247
255
|
layout: partial.contentPanel?.layout ?? 'double-pane',
|
|
248
256
|
},
|
|
249
257
|
experimentalCollapsibleSnippets: partial.experimentalCollapsibleSnippets ?? false,
|
|
258
|
+
experimentalCollapsibleMethodDescriptions: partial.experimentalCollapsibleMethodDescriptions ?? false,
|
|
250
259
|
propertySettings: {
|
|
251
260
|
types: partial.propertySettings?.types ?? 'rich',
|
|
252
261
|
collapseDescription: partial.propertySettings?.collapseDescription ?? true,
|
package/plugin/react/Routing.tsx
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { marked } from 'marked';
|
|
3
|
-
|
|
4
|
-
import {
|
|
2
|
+
import { marked, Tokens } from 'marked';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
createMarkdownProcessor,
|
|
6
|
+
CreateShikiHighlighterOptions,
|
|
7
|
+
type MarkdownProcessor,
|
|
8
|
+
} from '@astrojs/markdown-remark';
|
|
5
9
|
import remarkGfmAlerts from 'remark-github-alerts';
|
|
6
10
|
|
|
7
11
|
import type { MarkdownHeading } from 'astro';
|
|
8
12
|
import type { StarlightRouteData } from '@astrojs/starlight/route-data';
|
|
9
13
|
import type * as SDKJSON from '@stainless/sdk-json';
|
|
10
|
-
import { LanguageNames, type DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
14
|
+
import { LanguageNames, SupportedLanguageSyntaxes, type DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
11
15
|
|
|
12
16
|
import {
|
|
13
17
|
generateRouteList,
|
|
14
18
|
generateRoute,
|
|
15
19
|
parseStainlessPath,
|
|
16
20
|
walkTree,
|
|
17
|
-
SupportedLanguageSyntaxes,
|
|
18
21
|
getLanguageSnippet,
|
|
19
22
|
} from '@stainless-api/docs-ui/routing';
|
|
20
23
|
|
|
@@ -48,14 +51,16 @@ import {
|
|
|
48
51
|
BREADCRUMB_CONFIG,
|
|
49
52
|
PROPERTY_SETTINGS,
|
|
50
53
|
ENABLE_CONTEXT_MENU,
|
|
54
|
+
EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS,
|
|
51
55
|
} from 'virtual:stl-starlight-virtual-module';
|
|
52
56
|
import style from '@stainless-api/docs-ui/style';
|
|
53
|
-
import {
|
|
57
|
+
import { BundledTheme, createHighlighter, HighlighterGeneric, type BundledLanguage } from 'shiki';
|
|
54
58
|
import { SnippetCode, SnippetContainer, SnippetRequestContainer } from '../components/SnippetCode';
|
|
55
59
|
import type { StlStarlightMiddleware } from '../middlewareBuilder/stainlessMiddleware';
|
|
56
60
|
import { ComponentProvider } from '@stainless-api/docs-ui/contexts/component';
|
|
57
61
|
import { AIDropdown } from '../../stl-docs/components/AIDropdown';
|
|
58
62
|
import { ChevronsUpDownIcon } from 'lucide-react';
|
|
63
|
+
import { MethodDescription } from '../components/MethodDescription';
|
|
59
64
|
|
|
60
65
|
export function generateDocsRoutes(spec: SDKJSON.Spec) {
|
|
61
66
|
const paths = generateRouteList({
|
|
@@ -151,19 +156,58 @@ export function buildPageNavigation(resource: SDKJSON.Resource, depth: number =
|
|
|
151
156
|
return [...output, ...subs];
|
|
152
157
|
}
|
|
153
158
|
|
|
154
|
-
function renderMarkdown(content: string) {
|
|
155
|
-
|
|
159
|
+
async function renderMarkdown(content: string) {
|
|
160
|
+
const highlighter = await astroHighlight();
|
|
161
|
+
|
|
162
|
+
const renderer = {
|
|
163
|
+
code({ text, lang }: Tokens.Code) {
|
|
164
|
+
return shikiHighlight({
|
|
165
|
+
highlighter,
|
|
166
|
+
content: text,
|
|
167
|
+
language: lang,
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
marked.use({ renderer });
|
|
173
|
+
return marked.parse(content, {
|
|
174
|
+
gfm: true,
|
|
175
|
+
}) as string;
|
|
156
176
|
}
|
|
157
177
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
178
|
+
function shikiHighlight({
|
|
179
|
+
highlighter,
|
|
180
|
+
content,
|
|
181
|
+
language,
|
|
182
|
+
themes,
|
|
183
|
+
}: {
|
|
184
|
+
highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
185
|
+
content: string;
|
|
186
|
+
language?: string;
|
|
187
|
+
themes?: CreateShikiHighlighterOptions['themes'] | Record<string, 'stainless-docs-json'>;
|
|
188
|
+
}) {
|
|
189
|
+
let _themes = themes;
|
|
190
|
+
if (!themes && language === 'json') {
|
|
191
|
+
_themes = {
|
|
192
|
+
light: 'stainless-docs-json',
|
|
193
|
+
dark: 'stainless-docs-json',
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!_themes) {
|
|
198
|
+
_themes = HIGHLIGHT_THEMES;
|
|
199
|
+
}
|
|
161
200
|
return highlighter.codeToHtml(content, {
|
|
162
201
|
lang: language ?? 'javascript',
|
|
163
|
-
themes:
|
|
202
|
+
themes: _themes || {},
|
|
164
203
|
});
|
|
165
204
|
}
|
|
166
205
|
|
|
206
|
+
async function highlight(content: string, language?: string) {
|
|
207
|
+
const highlighter = await astroHighlight();
|
|
208
|
+
return shikiHighlight({ highlighter, content, language });
|
|
209
|
+
}
|
|
210
|
+
|
|
167
211
|
export function SDKSelectReactComponent({
|
|
168
212
|
selected,
|
|
169
213
|
languages,
|
|
@@ -327,6 +371,7 @@ export function RenderSpec({
|
|
|
327
371
|
SnippetCode,
|
|
328
372
|
SnippetContainer,
|
|
329
373
|
SnippetRequestContainer,
|
|
374
|
+
...(EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS ? { MethodDescription } : {}),
|
|
330
375
|
}}
|
|
331
376
|
>
|
|
332
377
|
<NavigationProvider basePath={BASE_PATH} selectedPath={path}>
|
|
@@ -392,6 +437,66 @@ export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguag
|
|
|
392
437
|
return spec.readme[language];
|
|
393
438
|
}
|
|
394
439
|
|
|
440
|
+
let astroShikiHighlighter:
|
|
441
|
+
| HighlighterGeneric<BundledLanguage, BundledTheme>
|
|
442
|
+
| Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
|
|
443
|
+
| null = null;
|
|
444
|
+
|
|
445
|
+
async function astroHighlight() {
|
|
446
|
+
if (astroShikiHighlighter) {
|
|
447
|
+
return astroShikiHighlighter;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
astroShikiHighlighter = createHighlighter({
|
|
451
|
+
themes: [
|
|
452
|
+
'github-light',
|
|
453
|
+
'github-dark',
|
|
454
|
+
{
|
|
455
|
+
name: 'stainless-docs-json',
|
|
456
|
+
colors: {
|
|
457
|
+
'editor.background': 'var(--stl-color-background)',
|
|
458
|
+
'editor.foreground': 'var(--stl-color-foreground)',
|
|
459
|
+
},
|
|
460
|
+
|
|
461
|
+
tokenColors: [
|
|
462
|
+
{
|
|
463
|
+
scope: ['comment', 'punctuation.definition.comment'],
|
|
464
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
465
|
+
},
|
|
466
|
+
// numbers, booleans, null
|
|
467
|
+
{
|
|
468
|
+
scope: ['constant.numeric', 'constant.language'],
|
|
469
|
+
settings: { foreground: 'var(--stl-color-foreground-orange)' },
|
|
470
|
+
},
|
|
471
|
+
// strings
|
|
472
|
+
{
|
|
473
|
+
scope: ['string', 'string.quoted', 'string.template'],
|
|
474
|
+
settings: { foreground: 'var(--stl-color-foreground-green)' },
|
|
475
|
+
},
|
|
476
|
+
// Keys, brackets
|
|
477
|
+
{
|
|
478
|
+
scope: ['support.type', 'meta'],
|
|
479
|
+
settings: { foreground: 'var(--stl-color-foreground)' },
|
|
480
|
+
},
|
|
481
|
+
// brackets
|
|
482
|
+
{
|
|
483
|
+
scope: ['meta'],
|
|
484
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
485
|
+
},
|
|
486
|
+
// built-in types
|
|
487
|
+
{
|
|
488
|
+
scope: ['support.type.builtin'],
|
|
489
|
+
settings: { foreground: 'var(--stl-color-foreground-purple)' },
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
},
|
|
493
|
+
],
|
|
494
|
+
langs: SupportedLanguageSyntaxes,
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
return astroShikiHighlighter;
|
|
498
|
+
}
|
|
499
|
+
|
|
395
500
|
// Astro's markdown processor is a singleton
|
|
396
501
|
// Need to cache it instead of instanting per request
|
|
397
502
|
let astroMarkdownProcessor: MarkdownProcessor;
|
|
@@ -409,18 +514,6 @@ async function astroMarkdown() {
|
|
|
409
514
|
return astroMarkdownProcessor;
|
|
410
515
|
}
|
|
411
516
|
|
|
412
|
-
let astroShikiHighlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
413
|
-
async function astroHighlight() {
|
|
414
|
-
if (!astroShikiHighlighter) {
|
|
415
|
-
astroShikiHighlighter = await createHighlighter({
|
|
416
|
-
themes: ['github-light', 'github-dark'],
|
|
417
|
-
langs: SupportedLanguageSyntaxes,
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
return astroShikiHighlighter;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
517
|
export async function astroMarkdownRender(content: string) {
|
|
425
518
|
const md = await astroMarkdown();
|
|
426
519
|
const output = await md.render(content);
|
package/plugin/routes/Docs.astro
CHANGED
|
@@ -23,12 +23,9 @@ const shouldRenderSearch = !!(
|
|
|
23
23
|
|
|
24
24
|
<style is:global>
|
|
25
25
|
@layer starlight.core {
|
|
26
|
-
header
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
&.header {
|
|
30
|
-
border-bottom-color: var(--sl-color-hairline);
|
|
31
|
-
}
|
|
26
|
+
header,
|
|
27
|
+
header.header {
|
|
28
|
+
border-color: var(--stl-color-border-faint);
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
.header {
|