UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

67 lines 1.62 kB
import _typeof from "@babel/runtime/helpers/esm/typeof"; import { Fragment, jsx, jsxs } from 'react/jsx-runtime'; import { toText } from 'hast-util-to-text'; import { toJsxRuntime } from 'hast-util-to-jsx-runtime'; export function hastToJsx(hast) { return toJsxRuntime(hast, { Fragment: Fragment, jsx: jsx, jsxs: jsxs }); } export function hastOrJsonToJsx(hastOrJson) { var hast; if ('hastJson' in hastOrJson) { try { hast = JSON.parse(hastOrJson.hastJson); } catch (error) { throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error))); } } else { hast = hastOrJson; } return toJsxRuntime(hast, { Fragment: Fragment, jsx: jsx, jsxs: jsxs }); } export function stringOrHastToString(source) { if (typeof source === 'string') { return source; } var hast; if ('hastJson' in source) { try { hast = JSON.parse(source.hastJson); } catch (error) { throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error))); } } else { hast = source; } return toText(hast, { whitespace: 'pre' }); } export function stringOrHastToJsx(source, highlighted) { if (typeof source === 'string') { return source; } var hast; if ('hastJson' in source) { try { hast = JSON.parse(source.hastJson); } catch (error) { throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error))); } } else { hast = source; } if (highlighted && _typeof(hast) === 'object') { return hastToJsx(hast); } return toText(hast, { whitespace: 'pre' }); }