Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
The hastUtils module provides utilities for converting between HAST (Hypertext Abstract Syntax Tree) nodes, strings, and React JSX elements. These utilities are essential for processing syntax-highlighted code and converting markdown/HTML structures to React components.
import {
hastToJsx,
hastOrJsonToJsx,
stringOrHastToString,
stringOrHastToJsx,
} from '@mui/internal-docs-infra/pipeline/hastUtils';
// Convert HAST to React JSX
const jsxElement = hastToJsx(hastNode);
// Convert HAST or serialized JSON to JSX
const jsxFromJson = hastOrJsonToJsx({ hastJson: '{"type":"element",...}' });
// Extract plain text from string or HAST
const plainText = stringOrHastToString(hastNodeOrString);
// Convert to JSX with optional highlighting
const jsx = stringOrHastToJsx(hastNodeOrString, true);
hastOrJsonToJsx| Parameter | Type | Description |
|---|---|---|
| hastOrJson | | |
| components | Partial<Components> | undefined |
React.ReactNodehastToJsx| Parameter | Type | Description |
|---|---|---|
| hast | HastNodes | |
| components | Partial<Components> | undefined |
React.ReactNodestringOrHastToJsx| Parameter | Type | Description |
|---|---|---|
| source | | |
| highlighted | boolean | undefined | |
| components | Partial<Components> | undefined |
React.ReactNodestringOrHastToString| Parameter | Type | Description |
|---|---|---|
| source | |
stringCodeHighlighter