|
1
|
import type { OpenAPI } from "types" |
|
2
|
|
|
3
|
/** |
|
4
|
* Shared context threaded through the OAS -> Markdown converters, mirroring the |
|
5
|
* `area`/base-URL data the React renderers read from providers/env. |
|
6
|
*/ |
|
7
|
export type MarkdownContext = { |
|
8
|
area: OpenAPI.Area |
|
9
|
baseUrl: string |
|
10
|
basePath: string |
|
11
|
} |
|
12
|
|
|
13
|
/** Collapse whitespace/newlines to a single line (compact type-list style). */ |
|
14
|
export const oneLine = (text: string): string => |
|
15
|
text.replace(/\s*\n+\s*/g, " ").trim() |
|
16
|
|
|
17
|
/** Capitalize the first character (mirrors docs-ui `capitalize`). */ |
|
18
|
export const capitalize = (text: string): string => { |
|
19
|
return text.length ? text.charAt(0).toUpperCase() + text.slice(1) : text |
|
20
|
} |
|
21
|
|
|
22
|
/** |
|
23
|
* Absolutize an in-content link. Internal paths (starting with `/`) are |
|
24
|
* prefixed with the base URL + base path (matching how the site's `Link` |
|
25
|
* prepends `/api`); everything else is returned unchanged. |
|
26
|
*/ |
|
27
|
export const absolutizeLink = (url: string, ctx: MarkdownContext): string => { |
|
28
|
if (url.startsWith("/")) { |
|
29
|
return `${ctx.baseUrl}${ctx.basePath}${url}` |
|
30
|
} |
|
31
|
return url |
|
32
|
} |