diff --git a/src/exportMarkdownFromLexical.ts b/src/exportMarkdownFromLexical.ts index db796b77..10a2cc7a 100644 --- a/src/exportMarkdownFromLexical.ts +++ b/src/exportMarkdownFromLexical.ts @@ -194,7 +194,9 @@ export function exportLexicalTreeToMdast({ const defaultImportsMap = new Map<string, string>() for (const componentName of referredComponents) { - const descriptor = jsxComponentDescriptors.find((descriptor) => descriptor.name === componentName) + const descriptor = + jsxComponentDescriptors.find((descriptor) => descriptor.name === componentName) ?? + jsxComponentDescriptors.find((descriptor) => descriptor.name === '*') if (!descriptor) { throw new Error(`Component ${componentName} is used but not imported`) } diff --git a/src/plugins/jsx/LexicalJsxNode.tsx b/src/plugins/jsx/LexicalJsxNode.tsx index 73adf898..94cfcb40 100644 --- a/src/plugins/jsx/LexicalJsxNode.tsx +++ b/src/plugins/jsx/LexicalJsxNode.tsx @@ -105,7 +105,10 @@ export function JsxEditorContainer(props: { }) { const { mdastNode } = props const jsxComponentDescriptors = useCellValue(jsxComponentDescriptors$) - const descriptor = jsxComponentDescriptors.find((descriptor) => descriptor.name === mdastNode.name) + const descriptor = + jsxComponentDescriptors.find((descriptor) => descriptor.name === mdastNode.name) ?? + jsxComponentDescriptors.find((descriptor) => descriptor.name === '*') + if (!descriptor) { throw new Error(`No JSX descriptor found for ${mdastNode.name}`) } diff --git a/src/plugins/jsx/MdastMdxJsxElementVisitor.ts b/src/plugins/jsx/MdastMdxJsxElementVisitor.ts index 6f0f8fad..21a34c07 100644 --- a/src/plugins/jsx/MdastMdxJsxElementVisitor.ts +++ b/src/plugins/jsx/MdastMdxJsxElementVisitor.ts @@ -6,7 +6,9 @@ import { MdastImportVisitor } from '../../importMarkdownToLexical' export const MdastMdxJsxElementVisitor: MdastImportVisitor<MdxJsxTextElement> = { testNode: (node, { jsxComponentDescriptors }) => { if (node.type === 'mdxJsxTextElement' || node.type === 'mdxJsxFlowElement') { - const descriptor = jsxComponentDescriptors.find((descriptor) => descriptor.name === node.name) + const descriptor = + jsxComponentDescriptors.find((descriptor) => descriptor.name === node.name) ?? + jsxComponentDescriptors.find((descriptor) => descriptor.name === '*') return descriptor !== undefined } return false diff --git a/src/plugins/jsx/index.ts b/src/plugins/jsx/index.ts index 5410cc81..b5ba1156 100644 --- a/src/plugins/jsx/index.ts +++ b/src/plugins/jsx/index.ts @@ -56,8 +56,9 @@ export interface JsxPropertyDescriptor { */ export interface JsxComponentDescriptor { /** - * The tag name. For example: 'div', 'span', 'MyComponent'. + * The tag name. For example: 'div', 'span', 'MyComponent'. Use '*' for any tag. * Note: For fragments, use null. + * */ name: string | null /**