# Fumadocs Core (the core library of Fumadocs): Rehype Code
URL: /docs/headless/mdx/rehype-code
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/headless/mdx/rehype-code.mdx

Code syntax highlighter

A wrapper of [`@shikijs/rehype`](https://shiki.style/packages/rehype), the syntax highlighter used by Fumadocs.

It converts raw `<pre />` codeblocks into highlighted codeblocks:

````md tab="Input"
```ts
console.log('Hello World');
```
````

```html tab="Output"
<pre>
  <code>
    <span class="line">
      <span style="--shiki-light: #4C4F69; --shiki-dark: #CDD6F4;">console</span>...
    </span>
  </code>
</pre>
```

## Usage [#usage]

Rehype Code is a rehype plugin. Fumadocs MDX enables it by default. Pass options with `rehypeCodeOptions`:

```ts tab="unified" title="source.config.ts"
import { defineConfig } from 'fumadocs-mdx/config';

export default defineConfig({
  mdxOptions: {
    rehypeCodeOptions: {
      themes: {
        light: 'github-light',
        dark: 'github-dark',
      },
    },
  },
});
```

```ts tab="Sätteri" title="source.config.ts"
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';

export const docs = defineDocs({
  docs: { compiler: 'satteri' },
});

export default defineConfig({
  satteriOptions: {
    rehypeCodeOptions: {
      themes: {
        light: 'github-light',
        dark: 'github-dark',
      },
    },
  },
});
```

### Highlighter [#highlighter]

The plugin uses Shiki. `rehypeCodeFromHighlighter` takes another [highlighter](/docs/headless/utils/shiki) like Highlights instead, with the options other than Shiki's. Pass a function to create the highlighter with the transformers of the plugin.

Disable the default plugin and add it:

```ts tab="unified" title="source.config.ts"
import { defineConfig } from 'fumadocs-mdx/config';
import { rehypeCodeFromHighlighter } from 'fumadocs-core/mdx-plugins/rehype-code.core';
import { highlighter } from './lib/highlighter';

export default defineConfig({
  mdxOptions: {
    rehypeCodeOptions: false,
    rehypePlugins: [
      () =>
        rehypeCodeFromHighlighter(({ transformers }) =>
          highlighter.override({ shikiTransformers: transformers }),
        ),
    ],
  },
});
```

```ts tab="Sätteri" title="source.config.ts"
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';
import { rehypeCodeFromHighlighter } from '@fumadocs/satteri/rehype-code';
import { highlighter } from './lib/highlighter';

export const docs = defineDocs({
  docs: { compiler: 'satteri' },
});

export default defineConfig({
  satteriOptions: {
    rehypeCodeOptions: false,
    hastPlugins: [
      rehypeCodeFromHighlighter(({ transformers }) =>
        highlighter.override({ shikiTransformers: transformers }),
      ),
    ],
  },
});
```

### Meta [#meta]

It parses the `title` meta string, and adds it to the `pre` element as an attribute.

````mdx tab="Input"
```js title="Title"
console.log('Hello');
```
````

```jsx tab="Output"
<pre title="Title">...</pre>
```

You may filter the meta string before processing it with the `filterMetaString` option.

### Inline Code [#inline-code]

You can enable it with `inline` option:

```ts
import { type RehypeCodeOptions } from 'fumadocs-core/mdx-plugins';

const rehypeCodeOptions: RehypeCodeOptions = {
  // [!code ++]
  inline: 'tailing-curly-colon',
};
```

```md title="Syntax"
This is a highlighted inline code: `console.log("hello world"){:js}`.
```

This is a highlighted inline code: `console.log("hello world"){:js}`.

### Icon [#icon]

The plugin will automatically adds an `icon` attribute according to the language meta string.
It is a HTML string, you can render it with React `dangerouslySetInnerHTML`.

````md tab="Input"
```ts
console.log('This should shows the logo of TypeScript');
```
````

```jsx tab="Output"
<pre icon="<svg />">...</pre>
```

Disable or customize icons with the `icon` option.

### Unknown Languages [#unknown-languages]

A code block with a language that Shiki doesn't support fails the build. To highlight it as another language instead, set `fallbackLanguage`:

```ts tab="unified" title="source.config.ts"
import { defineConfig } from 'fumadocs-mdx/config';

export default defineConfig({
  mdxOptions: {
    rehypeCodeOptions: {
      fallbackLanguage: 'plaintext',
    },
  },
});
```

```ts tab="Sätteri" title="source.config.ts"
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';

export const docs = defineDocs({
  docs: { compiler: 'satteri' },
});

export default defineConfig({
  satteriOptions: {
    rehypeCodeOptions: {
      fallbackLanguage: 'plaintext',
    },
  },
});
```

### More Options [#more-options]

The options are inherited from [Shiki](https://shiki.style), see their docs for other options.