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 | |
React.ReactNodehastToJsx| Parameter | Type | Description |
|---|---|---|
| hast | | |
| components | |
React.ReactNodestringOrHastToJsx| Parameter | Type | Description |
|---|---|---|
| source | | |
| highlighted | | |
| components | |
React.ReactNodestringOrHastToString| Parameter | Type | Description |
|---|---|---|
| source | |
stringChecksum byte length embedded in compressed payloads that use a text
dictionary. The checksum lets decompressHast verify that the caller
supplied the same textContent that was used during compression.
type CHECKSUM_BYTES = 4Shared dictionary for DEFLATE compression of HAST JSON.
Contains byte sequences that frequently appear in JSON-serialized HAST trees (syntax-highlighted TypeScript type documentation). The dictionary is embedded in both the server build and the client bundle, so it must stay small — currently ~3 KB uncompressed.
type HAST_DICTIONARY = Uint8ArrayMaximum size of the DEFLATE dictionary in bytes.
DEFLATE uses only the last 32 KiB of the dictionary buffer. Any content beyond this limit is ignored by the compressor.
type MAX_DICTIONARY_SIZE = numberCodeHighlighter