Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
A function for parsing types.md files back into structured type metadata. This is the reverse operation of syncTypes - it reads markdown and reconstructs the TypesMeta[] array.
loadServerTypesText parses a types.md file that was previously generated by syncTypes. It reconstructs:
This is useful for:
import { loadServerTypesText } from '@mui/internal-docs-infra/pipeline/loadServerTypesText';
// Load types from a file URL
const result = await loadServerTypesText('file:///absolute/path/to/types.md');
// Access the parsed types
console.log(result.allTypes); // TypesMeta[]
console.log(result.variantData); // Record<string, VariantData>
console.log(result.externalTypes); // Record<string, string>
import { parseTypesMarkdown } from '@mui/internal-docs-infra/pipeline/loadServerTypesText';
const markdown = `# Button API
## API Reference
### Button
A clickable button component
**Button Props:**
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| disabled | \`boolean\` | \`false\` | Whether the button is disabled |
| onClick* | \`() => void\` | - | Click handler |
`;
const result = parseTypesMarkdown(markdown);
console.log(result.allTypes[0]); // { type: 'component', name: 'Button', data: {...} }
Loads and parses a types.md file from a file URL.
async function loadServerTypesText(fileUrl: string): Promise<LoadServerTypesTextResult>;
Parameters:
| Parameter | Type | Description |
|---|---|---|
| fileUrl | string | A file:// URL to the types.md file |
Parses markdown content directly into type metadata. Exported for testing.
function parseTypesMarkdown(content: string): LoadServerTypesTextResult;
Parameters:
| Parameter | Type | Description |
|---|---|---|
| content | string | The raw markdown content to parse |
The parser expects markdown in the format generated by syncTypes:
Each type is defined by an H3 heading (###) followed by optional description and tables:
### ComponentName
Optional description paragraph.
**ComponentName Props:**
| Prop | Type | Default | Description |
| ---------- | --------- | ----------- | ------------------------------ |
| propName | `string` | `"default"` | Prop description |
| required\* | `boolean` | - | Required prop (marked with \*) |
The parser determines type kind based on content:
useThe parser recognizes these table formats:
| Prop | Type | Default | Description || Parameter | Type | Default | Description || Attribute | Type | Description || Variable | Type | Description || Property | Type | Description |External types are parsed from the "External Types" H2 section:
## External Types
### TypeName
\`\`\`typescript
type TypeName = string | number;
\`\`\`
Variant and type name mappings are embedded as HTML comments at the end of the file:
[//]: # 'variantTypes: {"Default":["Button","ButtonProps"]}'
[//]: # 'typeNameMap: {"ButtonProps":"Button.Props"}'
loadServerTypesTextLoad and parse a types.md file into TypesMeta[].
| Parameter | Type | Description |
|---|---|---|
| fileUrl | string | file:// URL to the types.md file |
Promise<TypesSourceData>Parsed types and external types
organizeTypesByExportOrganizes types data by export name and computes slugs.
The logic categorizes types as follows:
type in their exportadditionalTypes for their exportadditionalTypesEach type is also assigned a slug for anchor linking (e.g., “trigger” or “trigger.props”).
| Parameter | Type | Description |
|---|---|---|
| variantData | Record<string, { types: BaseTypeMeta[]; typeNameMap?: Record<string, string> }> | The variant data containing types per variant |
| typeNameMap | Record<string, string> | undefined | Optional map from flat names to dotted names |
| Key | Type | Description |
|---|---|---|
| exports | Record<string, { type: BaseTypeMeta; additionalTypes: BaseTypeMeta[] }> | Export data where each export has a main type and related additional types |
| additionalTypes | BaseTypeMeta[] | Top-level non-namespaced types like InputType |
| variantTypeNames | Record<string, string[]> | Maps variant names to the type names that originated from that variant.
Used for namespace imports (e.g., |
| variantTypeNameMaps | Record<string, Record<string, string>> | Maps variant names to their per-variant typeNameMaps. Used for Canonical Types annotations showing which variants contain each type. |
Base type metadata interface used for organizing exports. This is a minimal interface that works with both TypesMeta and EnhancedTypesMeta.
type BaseTypeMeta = {
name: string;
type: 'component' | 'hook' | 'function' | 'class' | 'raw';
slug?: string;
data: unknown;
};Defines the order in which exports should be sorted in generated documentation.
Top-level order:
Component namespace members are automatically grouped with their parent component. For example, “Accordion” will be followed by “Accordion.Root”, “Accordion.Item”, etc. The namespace members themselves are sorted by the suffix order defined below.
type componentExports = string[];type cssVariables = any[];type dataAttributes = string[];type namespaceParts = string[];Result of organizing types by export.
type OrganizeTypesResult = {
exports: Record<string, { type: BaseTypeMeta; additionalTypes: BaseTypeMeta[] }>;
additionalTypes: BaseTypeMeta[];
variantTypeNames: Record<string, string[]>;
variantTypeNameMaps: Record<string, Record<string, string>>;
};type props = string[];Common data returned by both syncTypes and loadServerTypesText. This is the shared contract consumed by loadServerTypes.
type TypesSourceData = {
externalTypes: Record<string, string>;
typeNameMap: Record<string, string>;
allDependencies: string[];
updated: boolean;
exports: Record<string, { type: TypesMeta; additionalTypes: TypesMeta[] }>;
additionalTypes: TypesMeta[];
variantTypeNames: Record<string, string[]>;
variantTypeNameMaps: Record<string, Record<string, string>>;
};type typeSuffixes = string[];Variant data structure for a single variant. Contains the types and optional typeNameMap specific to that variant.
type VariantData = { types: TypesMeta[]; typeNameMap?: Record<string, string> };syncTypes - Generates the types.md files that this function parsesloadServerTypes - Full pipeline that calls syncTypes and applies highlighting