zfb
GitHub repository

Type to search...

to open search from anywhere

Strip .md extension

Opt-in top-level config that removes .md or .mdx suffixes from internal link hrefs at build time.

stripMdExt is an opt-in top-level zfb.config.ts field, not a markdown.features entry. It defaults to false; when omitted or set to false, author-written .md and .mdx hrefs are preserved.

When enabled, StripMdExtensionPlugin removes the .md or .mdx suffix from internal link href values and appends a trailing slash, so links authored as [page](./other.md) produce clean output URLs like ./other/.

What it does

In the hast phase, the plugin walks every <a> element. For each internal link whose path ends with .md or .mdx:

  1. Strips the extension.

  2. Appends a trailing / to the stripped path.

  3. Preserves the query string and fragment after the slash.

The plugin touches internal relative and root-relative paths. Absolute URLs (https://), anchor-only links (#section), non-link elements, and hrefs with non-markdown file extensions are left unchanged. In trailing-slash mode, extensionless relative hrefs such as ./guide and ../guide also become ./guide/ and ../guide/.

Config

Enable it at the top level:

zfb.config.ts
import { defineConfig } from "zfb/config";

export default defineConfig({
  stripMdExt: true,
});

The plugin runs after ResolveLinksPlugin when both are configured, so it sees already-resolved paths before cleaning up any remaining markdown extensions.

Example

See [setup](./installation.mdx#requirements) for details.

With stripMdExt: true, produces:

<p>See <a href="./installation/#requirements">setup</a> for details.</p>

With stripMdExt: false or an omitted config field, the authored ./installation.mdx#requirements href is preserved.

See also

  • Resolve links — runs before this plugin to normalise the target path.

Revision History

CreatedUpdated