mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-30 14:41:16 +00:00
37 lines
838 B
TypeScript
37 lines
838 B
TypeScript
import type { Expression, Program } from 'estree';
|
|
import type { MdxJsxAttribute } from 'mdast-util-mdx';
|
|
|
|
export function createElement(name: string, attributes: object[], children?: unknown): object {
|
|
const element: Record<string, unknown> = {
|
|
type: 'mdxJsxFlowElement',
|
|
name,
|
|
attributes,
|
|
};
|
|
|
|
if (children) element.children = children;
|
|
|
|
return element;
|
|
}
|
|
|
|
export function expressionToAttribute(key: string, value: Expression): MdxJsxAttribute {
|
|
return {
|
|
type: 'mdxJsxAttribute',
|
|
name: key,
|
|
value: {
|
|
type: 'mdxJsxAttributeValueExpression',
|
|
value: '',
|
|
data: {
|
|
estree: {
|
|
type: 'Program',
|
|
body: [
|
|
{
|
|
type: 'ExpressionStatement',
|
|
expression: value,
|
|
},
|
|
],
|
|
} as Program,
|
|
},
|
|
},
|
|
};
|
|
}
|