Extract MDX components
Goal: Pull out every JSX-like component from an MDX document, e.g. to audit which components a doc site actually uses.
Prerequisites: Parse the file as MDX with -I mdx (plain .md parsing does not recognize JSX syntax).
Query
select(is_mdx())
$ mq -I mdx 'select(is_mdx())' page.mdx
Input
Regular paragraph.
<CustomComponent prop="value" />
Another paragraph.
<AnotherComponent>
Content
</AnotherComponent>
Output
<CustomComponent prop="value" />
<AnotherComponent>Content</AnotherComponent>
Notes
- Files with an
.mdxextension are parsed as MDX automatically;-I mdxis only needed when the content doesn’t have that extension (e.g. piped from stdin).