Skip to content

@alap/mdx

MDX integration for Alap — transforms [text](alap:query) links in MDX content into React <AlapLink> components.

Unlike remark-alap (which emits <alap-link> web component HTML), this plugin emits JSX that resolves through React's AlapProvider context. Use this when your MDX content renders inside a React component tree.

For a working site, see the MDX example (examples/sites/mdx/).

Install

bash
npm install alap @alap/mdx

Exports

ImportWhat you get
@alap/mdxEverything: remark plugin, provider, component map, AlapLink re-export
@alap/mdx/remarkremarkAlapMDX remark plugin only
@alap/mdx/providerAlapMDXProvider and alapComponents only

MDX Syntax

Write standard Markdown links with the alap: protocol:

md
Check out these [coffee spots](alap:.coffee).
The [best bridges](alap:@nycBridges) are worth visiting.
A specific item: [Golden Gate](alap:golden).

The remark plugin transforms these into <AlapLink query=".coffee">coffee spots</AlapLink> JSX elements during compilation.

For expressions with spaces or operators (.nyc + .food, .a | .b), use macros — Markdown parsers break on spaces in the URL portion.

Setup

Next.js (App Router)

tsx
// mdx-components.tsx
import { alapComponents } from '@alap/mdx';

export function useMDXComponents(components) {
  return { ...components, ...alapComponents };
}
tsx
// app/layout.tsx
import { AlapMDXProvider } from '@alap/mdx';
import config from './alap-config';

export default function Layout({ children }) {
  return <AlapMDXProvider config={config}>{children}</AlapMDXProvider>;
}

Add the remark plugin to your MDX config:

js
// next.config.mjs
import createMDX from '@next/mdx';
import { remarkAlapMDX } from '@alap/mdx';

const withMDX = createMDX({ options: { remarkPlugins: [remarkAlapMDX] } });
export default withMDX(nextConfig);

With @mdx-js/react (Docusaurus, custom setups)

tsx
import { AlapMDXProvider, alapComponents } from '@alap/mdx';
import { MDXProvider } from '@mdx-js/react';

<MDXProvider components={alapComponents}>
  <AlapMDXProvider config={config}>{children}</AlapMDXProvider>
</MDXProvider>

Direct import in MDX

If you prefer explicit imports over provider-based component mapping:

mdx
import { AlapLink } from '@alap/mdx';

Here are some <AlapLink query=".coffee">cafes</AlapLink>.

AlapProvider must still be an ancestor in the React tree.

Remark Plugin Options

OptionTypeDefaultDescription
componentNamestring'AlapLink'JSX component name to emit
queryPropstring'query'Prop name for the query expression
classNamestringCSS class added to every emitted component

Provider Props

PropTypeDescription
configAlapConfigAlap configuration (required)
childrenReactNodeContent to wrap
menuTimeoutnumberOverride settings.menuTimeout
defaultMenuStyleCSSPropertiesDefault inline styles for menus
defaultMenuClassNamestringDefault CSS class for menus

How it differs from remark-alap

remark-alap@alap/mdx
Output<alap-link> web component HTML<AlapLink> React JSX
ResolutionWeb component registers config globallyReact context via AlapProvider
Use whenAstro, Eleventy, any HTML pipelineNext.js, Remix, Docusaurus, any React MDX setup
Peer depsalapalap, react, optionally @mdx-js/react

Both transform the same [text](alap:query) syntax. Choose based on your rendering environment.

See also