Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 .mdx extension are parsed as MDX automatically; -I mdx is only needed when the content doesn’t have that extension (e.g. piped from stdin).