# Fumadocs Core (the core library of Fumadocs): Markdown Rendering
URL: /docs/headless/utils/markdown
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/headless/utils/markdown.mdx

Render React elements into Markdown.

## Overview [#overview]

`fumadocs-core/server` renders React Server Components, into a Markdown document:

```tsx tab="Input"
import { renderToMarkdown } from 'fumadocs-core/server';

const text = await renderToMarkdown(
  <div>
    <h2>Hello World</h2>
    <p>
      Some <b>rich</b> content.
    </p>
  </div>,
);
```

```md tab="Output"
## Hello World

Some **rich** content.
```

It powers the component exported by [Remark LLMs](/docs/headless/mdx/remark-llms#jsx-elements), and works on any server-rendered content you want to serve as Markdown.

> `renderToMarkdown()` is server-only.

## `asMarkdown` [#asmarkdown]

Components define their own Markdown form. Calling `asMarkdown()` during render is the opt-in: it returns the [target](#targets) when the component is being rendered into Markdown, and the HTML elements it returns are converted.

```tsx
import { asMarkdown, md } from 'fumadocs-core/server';

function Callout({ title, children }) {
  if (asMarkdown()) return md.linePrefix('> ')`**${title}**\n${children}`;

  return <div className="...">...</div>;
}
```

A component that never calls it is kept as JSX syntax with its props, like:

```mdx
<Tabs items={['a', 'b']}>...</Tabs>
```

This includes client components, which don't execute on the server.

### Targets [#targets]

A tree renders for a target, the `target` option of `renderToMarkdown()`:

- `markdown` (default): the document for agents.
- `search`: the text of [search records](/docs/headless/mdx/structure#components). It has the text of links, no images or code blocks, and a component without a Markdown form is an HTML tag with its text props.

These rules apply to the elements a component returns, like `<a href>`. A link written as text in an `md` template keeps its target in search, so return the element, or check the target.

`asMarkdown()` returns the target, so a component can give agents more than search indexes:

```tsx
import { asMarkdown, md } from 'fumadocs-core/server';

function Version({ name, released }) {
  const target = asMarkdown();
  if (target === 'search') return name;
  if (target) return md`${name} (released ${released})`;

  return <span title={released}>{name}</span>;
}
```

## `md` [#md]

Tagged template for Markdown output, interpolated values can be strings, React nodes, promises, or arrays of them. Use it to stringify `children` before manipulating them.

Two variants return the content as a block:

- `md.linePrefix(prefix)`: prefix every line, e.g. `'> '` for quote blocks.
- `md.indent(size)`: indent every line.

## `renderRoute` [#renderroute]

Render a page element into Markdown, or `undefined` when its component doesn't call `asMarkdown()`.

```tsx
import { renderRoute } from 'fumadocs-core/server';

const text = await renderRoute(<Page params={params} />);
```

Useful for serving a Markdown variant of a route: pages that opt in produce Markdown, other pages return `undefined` so you can fall back to a 404 or another source.