UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

25 lines (24 loc) 615 B
/** * Extracts all text content from a HAST node recursively. */ export function getHastTextContent(node) { if (node.type === 'text') { return node.value || ''; } if ('children' in node && Array.isArray(node.children)) { return node.children.map(child => getHastTextContent(child)).join(''); } return ''; } /** * Gets the direct text content of a HAST element (non-recursive, first level only). */ export function getShallowTextContent(element) { let text = ''; for (const child of element.children) { if (child.type === 'text') { text += child.value; } } return text; }