Core Concepts

Markdown Conversion

Last updated by Harlan Wilton in doc: link.

Nuxt AI Ready uses mdream to convert HTML pages to markdown during prerendering and runtime.

Conversion Flow

Build-Time (Prerendering)

During nuxi generate or nuxi build --prerender:

  1. HTML processed via mdream extraction plugin (title, description, headings)
  2. Converted to markdown and chunked
  3. Written to bulk TOON at /llms-full.toon (chunk-level) and /llms.toon (page-level)
  4. Full markdown served at .md routes
// Chunking config (reference)
const chunks = htmlToMarkdownSplitChunksStream(html, {
  headersToSplitOn: [TagIdMap.h1, TagIdMap.h2, TagIdMap.h3],
  chunkSize: 256,
  lengthFunction: estimateTokenCount,
})

Runtime

Requests with .md extension or Accept: text/markdown header trigger on-the-fly conversion with cache headers.

curl https://example.com/about.md
curl -H "Accept: text/markdown" https://example.com/about

Configuration

export default defineNuxtConfig({
  aiReady: {
    mdreamOptions: {
      preset: 'minimal', // Use minimal preset
    },
    markdownCacheHeaders: {
      maxAge: 3600, // Cache for 1 hour
      swr: true, // Enable stale-while-revalidate
    },
  },
})

Hooks

ai-ready:mdreamConfig

// Dynamic config based on route
nitroApp.hooks.hook('ai-ready:mdreamConfig', (options) => {
  if (options.origin?.includes('/blog/'))
    options.ignoreElements = [...(options.ignoreElements || []), '.author-bio']
})

// Full docs: /docs/ai-ready/nitro-api/nitro-hooks#ai-ready-mdreamconfig

ai-ready:markdown

// Post-process markdown output
nitroApp.hooks.hook('ai-ready:markdown', (context) => {
  context.markdown = `---\ntitle: ${context.title}\n---\n\n${context.markdown}`
})

// Full docs: /docs/ai-ready/nitro-api/nitro-hooks#ai-ready-markdown

Learn More

Did this page help you?