1. Home
  2. ChevronRightPlugin API Reference
  3. ChevronRightMiddleware

Middleware

PluginMiddlewareAPI — register and query transform middleware at runtime for Boltdocs plugins.

ctx.middleware — PluginMiddlewareAPILink

Register transform middleware entries. The name field is optional — when omitted, the plugin's name is used as context.

ctx.middleware.add({
  name: 'my-plugin:html',
  transformHtml: async (_ctx, { html, path }) => ({
    html: html.replace('</body>', '<footer>© 2026</footer></body>'),
  }),
})

ctx.middleware.has('my-plugin:html')  // → boolean
ctx.middleware.list()                 // → readonly PluginTransformMiddleware[]
ctx.middleware.remove('my-plugin:html')

Transform hooksLink

Each middleware entry can implement one or more transform hooks:

HookSignatureWhen it runs
transformSource(ctx, { code, filePath }) => { code }Before MDX compilation
transformMdx(ctx, { code, filePath }) => { code }After MDX compilation
transformHtml(ctx, { html, path }) => { html }After HTML rendering

Middlewares run in registration order. Each hook is a chain — the output of one middleware feeds the input of the next.


See alsoLink

  • PluginContext — base context object
  • Server — HTTP middleware & server lifecycle
  • HMR — dev-server file watching & custom events
  • Lifecycle Hooks — build/dev hooks, transform chains, and chain signals
Last updated on July 27, 2026

Was this page helpful?